Skip to content

Commit d266a94

Browse files
committed
Add Bizum processor
1 parent 3a3f6ff commit d266a94

File tree

5 files changed

+88
-29
lines changed

5 files changed

+88
-29
lines changed

tests/fixtures/payment-test-data.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export const PAYMENT_TEST_DATA = {
2121
},
2222
bizum: {
2323
success: {
24-
phoneNumber: '+3450000000000'
24+
phoneNumber: '+34500000000'
2525
},
2626
fail: {
27-
phoneNumber: '+3450000000000'
27+
phoneNumber: '+34500000000'
2828
}
2929
},
30-
// Add other payment methods as needed
3130
};

tests/fixtures/test-configurations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function generateTestConfigurations(options: {
6767
*/
6868
export const TEST_CONFIGURATIONS = {
6969
QUICK: generateTestConfigurations({
70-
paymentMethods: [PAYMENT_METHODS.CREDIT_CARD_SUCCESS],
70+
paymentMethods: [PAYMENT_METHODS.BIZUM],
7171
checkoutTypes: [CHECKOUT_TYPES.CLASSIC],
7272
productTypes: [PRODUCT_TYPES.SIMPLE],
7373
userStates: [USER_STATES.GUEST],

tests/helpers/payment-processors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { BizumProcessor } from './payment-processors/bizum-processor';
55

66
export function getPaymentProcessor(paymentMethod: string, page: Page): PayPalProcessor | CreditCardProcessor | BizumProcessor {
77
switch (paymentMethod) {
8-
case 'monei-paypal':
8+
case 'monei_paypal':
99
return new PayPalProcessor(page);
1010
case 'monei':
1111
return new CreditCardProcessor(page, false);
1212
case 'monei-hosted':
1313
return new CreditCardProcessor(page, true);
14-
case 'monei-bizum':
14+
case 'monei_bizum':
1515
return new BizumProcessor(page);
1616
default:
1717
throw new Error(`Unsupported payment method: ${paymentMethod}`);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { Page } from '@playwright/test';
2+
import {BasePaymentProcessor} from "./base-payment-processor";
3+
import {PAYMENT_TEST_DATA} from "../../fixtures/payment-test-data";
4+
5+
export class BizumProcessor extends BasePaymentProcessor {
6+
7+
// Locators
8+
readonly phoneInput = 'bizum-phone-input';
9+
readonly bizumButton = 'bizum-button';
10+
readonly submitButton = 'bizum-pay-button';
11+
readonly confirmButton = '#bizum-confirm';
12+
readonly successMessage = '.bizum-success-message';
13+
readonly errorMessage = '.bizum-error-message';
14+
15+
constructor(page: Page) {
16+
super(page);
17+
}
18+
19+
/**
20+
* Feature: Bizum payment
21+
* Scenario: User can pay with Bizum
22+
* Given the user has been redirected to Bizum
23+
* When the user enters their phone number
24+
* And confirms the payment
25+
* Then the payment should be processed successfully
26+
*/
27+
async processPayment(expectSuccess, preset: string = 'success') {
28+
const bizumDetails = PAYMENT_TEST_DATA.bizum[preset];
29+
30+
const buttonLocator = this.page.frameLocator('iframe[name^="__zoid__monei_bizum_button"]');
31+
await buttonLocator.getByTestId(this.phoneInput).click();
32+
const frameLocator = this.page.frameLocator('iframe[name^="__zoid__monei_bizum__"]');
33+
await frameLocator.getByTestId(this.phoneInput).fill(bizumDetails.phoneNumber);
34+
await frameLocator.getByTestId(this.submitButton).click();
35+
36+
await this.page.waitForTimeout(15000);
37+
}
38+
39+
/**
40+
* Feature: Bizum payment error handling
41+
* Scenario: User enters invalid phone number
42+
* Given the user is on the Bizum payment page
43+
* When the user enters an invalid phone number
44+
* Then an error message should be displayed
45+
*/
46+
async handleInvalidPhoneNumber(invalidPhone: string) {
47+
await this.page.fill(this.phoneInput, invalidPhone);
48+
await this.page.click(this.submitButton);
49+
50+
await this.page.waitForSelector(this.errorMessage);
51+
return this.page.textContent(this.errorMessage);
52+
}
53+
54+
/**
55+
* Feature: Bizum payment cancellation
56+
* Scenario: User cancels Bizum payment
57+
* Given the user is on the Bizum payment confirmation page
58+
* When the user clicks the cancel button
59+
* Then they should be redirected back to the merchant site
60+
*/
61+
async cancelPayment() {
62+
const cancelButtonSelector = '#bizum-cancel';
63+
await this.page.waitForSelector(cancelButtonSelector);
64+
await this.page.click(cancelButtonSelector);
65+
await this.page.waitForNavigation({ waitUntil: 'networkidle' });
66+
}
67+
68+
/**
69+
* Feature: Bizum payment timeout
70+
* Scenario: Bizum payment times out
71+
* Given the user has initiated a Bizum payment
72+
* When the payment is not confirmed within the timeout period
73+
* Then an error message should be displayed
74+
*/
75+
async handlePaymentTimeout() {
76+
const timeoutErrorSelector = '.bizum-timeout-error';
77+
await this.page.waitForSelector(timeoutErrorSelector, { timeout: 120000 }); // 2 minutes timeout
78+
return this.page.textContent(timeoutErrorSelector);
79+
}
80+
}

tests/helpers/payment-processors/credit-card-processor.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,24 @@
11
import { Page } from '@playwright/test';
22
import { PAYMENT_TEST_DATA } from '../../fixtures/payment-test-data';
3+
import { BasePaymentProcessor } from './base-payment-processor';
34

4-
export class CreditCardProcessor {
5-
readonly page: Page;
5+
export class CreditCardProcessor extends BasePaymentProcessor {
66
readonly isHosted: boolean;
77
// Locators
88
readonly cardNumberInput: string;
99
readonly cardExpiryInput: string;
1010
readonly cardCvcInput: string;
1111
readonly cardholderNameInput: string;
1212
readonly submitButton: string;
13-
readonly wooSubmitButtonSelectors: string[];
1413

1514
constructor(page: Page, isHosted: boolean) {
16-
this.page = page;
15+
super(page);
1716
this.isHosted = isHosted;
1817
this.cardNumberInput = 'card-number-input';
1918
this.cardExpiryInput = 'expiry-date-input';
2019
this.cardCvcInput = 'cvc-input';
2120
this.cardholderNameInput = 'cardholder-name-input';
2221
this.submitButton = 'pay-button';
23-
this.wooSubmitButtonSelectors = [
24-
'#place_order',
25-
'.wc-block-components-checkout-place-order-button'
26-
];
27-
}
28-
29-
/**
30-
* Clicks on the WooCommerce submit button, checking for multiple possible selectors
31-
*/
32-
async clickWooSubmitButton() {
33-
// Try each selector in order until one is found
34-
for (const selector of this.wooSubmitButtonSelectors) {
35-
const buttonExists = await this.page.$(selector) !== null;
36-
if (buttonExists) {
37-
await this.page.click(selector);
38-
return;
39-
}
40-
}
41-
throw new Error('WooCommerce submit button not found. Tried selectors: ' + this.wooSubmitButtonSelectors.join(', '));
4222
}
4323

4424
async processPayment(isHostedPayment, preset: string = 'success') {

0 commit comments

Comments
 (0)