mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Fix according to refactored types
and resources
- Fix of type declatations - Fix of data structure
This commit is contained in:
parent
965744ef9f
commit
cf436ee149
5 changed files with 83 additions and 91 deletions
|
@ -165,11 +165,11 @@ export class WooCommerceOrderEdit extends WooCommerceOrderEditBase {
|
|||
);
|
||||
}
|
||||
|
||||
if ( orderData.payment.dataFundingSource === 'oxxo' ) {
|
||||
if ( orderData.payment.gateway.dataFundingSource === 'oxxo' ) {
|
||||
await expect( this.seeOXXOVoucherButton() ).toBeVisible();
|
||||
}
|
||||
|
||||
if ( orderData.payment.dataFundingSource === 'acdc' ) {
|
||||
if ( orderData.payment.gateway.dataFundingSource === 'acdc' ) {
|
||||
await this.assertAddressVerificationResult(
|
||||
orderData.payment.card
|
||||
);
|
||||
|
@ -177,7 +177,7 @@ export class WooCommerceOrderEdit extends WooCommerceOrderEditBase {
|
|||
|
||||
if (
|
||||
[ 'paypal', 'paylater', 'venmo' ].includes(
|
||||
orderData.payment.dataFundingSource
|
||||
orderData.payment.gateway.dataFundingSource
|
||||
)
|
||||
) {
|
||||
await this.assertPayPalEmailAddress(
|
||||
|
|
|
@ -6,7 +6,7 @@ import { CustomerPaymentMethods as CustomerPaymentMethodsBase } from '@inpsyde/p
|
|||
* Internal dependencies
|
||||
*/
|
||||
import { PayPalUI } from './paypal-ui';
|
||||
import { PcpPayment } from '../../resources';
|
||||
import { Pcp } from '../../resources';
|
||||
|
||||
export class CustomerPaymentMethods extends CustomerPaymentMethodsBase {
|
||||
ppui: PayPalUI;
|
||||
|
@ -21,14 +21,14 @@ export class CustomerPaymentMethods extends CustomerPaymentMethodsBase {
|
|||
this.page.getByText( 'No saved methods found' );
|
||||
|
||||
// Actions
|
||||
isSavedPaymentMethod = async ( payment: PcpPayment ) => {
|
||||
isSavedPaymentMethod = async ( payment: Pcp.Payment ) => {
|
||||
await this.visit();
|
||||
|
||||
if ( await this.noSavedMethodsMessage().isVisible() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( payment.dataFundingSource ) {
|
||||
switch ( payment.gateway.dataFundingSource ) {
|
||||
case 'paypal':
|
||||
return await this.savedPaymentMethodRow(
|
||||
`Paypal /`
|
||||
|
@ -46,7 +46,7 @@ export class CustomerPaymentMethods extends CustomerPaymentMethodsBase {
|
|||
*
|
||||
* @param payment
|
||||
*/
|
||||
savePaymentMethod = async ( payment: PcpPayment ) => {
|
||||
savePaymentMethod = async ( payment: Pcp.Payment ) => {
|
||||
if ( ! ( await this.isSavedPaymentMethod( payment ) ) ) {
|
||||
await this.addPaymentMethodButton().click();
|
||||
await this.page.waitForLoadState();
|
||||
|
|
|
@ -37,7 +37,7 @@ export class OrderReceived extends OrderReceivedBase {
|
|||
assertOrderDetails = async ( order: WooCommerce.ShopOrder ) => {
|
||||
await super.assertOrderDetails( order );
|
||||
|
||||
if ( order.payment.dataFundingSource === 'oxxo' ) {
|
||||
if ( order.payment.gateway.dataFundingSource === 'oxxo' ) {
|
||||
await expect( this.seeOXXOVoucherButton_1() ).toBeVisible();
|
||||
await expect( this.seeOXXOVoucherButton_2() ).toBeVisible();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { expect, getLast4CardDigits } from '@inpsyde/playwright-utils/build';
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { PayPalAccount, PcpMerchant, PcpPayment } from '../../resources';
|
||||
import { PayPalAccount, Pcp } from '../../resources';
|
||||
import { PayPalPopup } from './paypal-popup';
|
||||
import { PayPalAPI } from '../paypal-api';
|
||||
|
||||
|
@ -355,86 +355,80 @@ export class PayPalUI {
|
|||
* @param data.merchant
|
||||
*/
|
||||
makeClassicPayment = async ( data: {
|
||||
payment: PcpPayment;
|
||||
merchant?: PcpMerchant;
|
||||
payment: Pcp.Payment;
|
||||
merchant?: Pcp.Merchant;
|
||||
} ) => {
|
||||
const { payment, merchant } = data;
|
||||
const { gateway } = payment;
|
||||
// Map to the tested method
|
||||
switch ( data.payment.method ) {
|
||||
case 'PayPal':
|
||||
switch ( gateway.dataFundingSource ) {
|
||||
case 'paypal':
|
||||
// pay with vaulted account
|
||||
if ( data.payment.isVaulted ) {
|
||||
if ( payment.isVaulted ) {
|
||||
await this.completePayPalVaultedPayment(
|
||||
data.payment.payPalAccount
|
||||
payment.payPalAccount
|
||||
);
|
||||
break;
|
||||
}
|
||||
// pay with account other than vaulted
|
||||
if ( data.payment.useNotVaultedAccount ) {
|
||||
if ( payment.useNotVaultedAccount ) {
|
||||
await this.completePayPalPayment(
|
||||
await this.openPayPalPupupDifferentAccount(),
|
||||
data.payment.useNotVaultedAccount
|
||||
payment.useNotVaultedAccount
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
await this.completePayPalPayment(
|
||||
await this.openPayPalPupup(),
|
||||
data.payment.payPalAccount
|
||||
payment.payPalAccount
|
||||
);
|
||||
break;
|
||||
|
||||
case 'PayLater':
|
||||
case 'paylater':
|
||||
await this.completePayLaterPayment(
|
||||
await this.openPayPalPupup( 'paylater' ),
|
||||
data.payment.payPalAccount
|
||||
payment.payPalAccount
|
||||
);
|
||||
break;
|
||||
|
||||
case 'ACDC':
|
||||
if ( data.payment.isVaulted ) {
|
||||
await this.completeAcdcVaultedPayment(
|
||||
data.payment,
|
||||
data.merchant
|
||||
);
|
||||
case 'acdc':
|
||||
if ( gateway.acdc3ds === 'always-3d-secure' ) {
|
||||
await this.completeAcdc3dsPayment( payment, merchant );
|
||||
break;
|
||||
}
|
||||
await this.completeAcdcPayment( data.payment, data.merchant );
|
||||
if ( payment.isVaulted ) {
|
||||
await this.completeAcdcVaultedPayment( payment, merchant );
|
||||
break;
|
||||
}
|
||||
await this.completeAcdcPayment( payment, merchant );
|
||||
break;
|
||||
|
||||
case 'ACDC3DS':
|
||||
await this.completeAcdc3dsPayment(
|
||||
data.payment,
|
||||
data.merchant
|
||||
);
|
||||
break;
|
||||
|
||||
case 'OXXO':
|
||||
case 'oxxo':
|
||||
await this.completeOXXOPayment();
|
||||
break;
|
||||
|
||||
case 'Venmo':
|
||||
case 'venmo':
|
||||
await this.completePayPalPayment(
|
||||
await this.openVenmoPopup(),
|
||||
data.payment.payPalAccount
|
||||
payment.payPalAccount
|
||||
);
|
||||
break;
|
||||
|
||||
case 'DebitOrCreditCard':
|
||||
await this.completeDebitOrCreditCardPayment(
|
||||
data.payment.card
|
||||
);
|
||||
case 'card':
|
||||
// Standard Card Button
|
||||
if ( gateway.slug === 'ppcp-card-button-gateway' ) {
|
||||
await this.completeStandardCardButtonPayment(
|
||||
payment.card
|
||||
);
|
||||
break;
|
||||
}
|
||||
// Debit Or Credit Card
|
||||
await this.completeDebitOrCreditCardPayment( payment.card );
|
||||
break;
|
||||
|
||||
case 'StandardCardButton':
|
||||
await this.completeStandardCardButtonPayment(
|
||||
data.payment.card
|
||||
);
|
||||
break;
|
||||
|
||||
case 'PayUponInvoice':
|
||||
await this.completePayUponInvoicePayment(
|
||||
data.payment.birthDate
|
||||
);
|
||||
case 'pay_upon_invoice':
|
||||
await this.completePayUponInvoicePayment( payment.birthDate );
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
@ -445,23 +439,24 @@ export class PayPalUI {
|
|||
* @param data
|
||||
*/
|
||||
makePayment = async ( data ) => {
|
||||
const { payment } = data;
|
||||
// Make payment with tested method
|
||||
switch ( data.payment.method ) {
|
||||
case 'PayPal':
|
||||
// if(paymentData.payment.isVaulted) {
|
||||
// await this.completePayPalVaultedPayment(paymentData.payment.payPalAccount);
|
||||
switch ( payment.method ) {
|
||||
case 'paypal':
|
||||
// if(payment.isVaulted) {
|
||||
// await this.completePayPalVaultedPayment(payment.payPalAccount);
|
||||
// return;
|
||||
// }
|
||||
await this.completePayPalPayment(
|
||||
await this.openBlockPayPalPopup(),
|
||||
data.payment.payPalAccount
|
||||
payment.payPalAccount
|
||||
);
|
||||
break;
|
||||
|
||||
case 'PayLater':
|
||||
case 'paylater':
|
||||
await this.completePayLaterPayment(
|
||||
await this.openBlockPayLaterPopup(),
|
||||
data.payment.payPalAccount
|
||||
payment.payPalAccount
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
@ -472,13 +467,14 @@ export class PayPalUI {
|
|||
*
|
||||
* @param payment
|
||||
*/
|
||||
savePaymentMethod = async ( payment: PcpPayment ) => {
|
||||
switch ( payment.method ) {
|
||||
case 'PayPal':
|
||||
savePaymentMethod = async ( payment: Pcp.Payment ) => {
|
||||
const { gateway } = payment;
|
||||
switch ( gateway.dataFundingSource ) {
|
||||
case 'paypal':
|
||||
await this.addPayPalPaymentMethod( payment.payPalAccount );
|
||||
break;
|
||||
|
||||
case 'ACDC':
|
||||
case 'acdc':
|
||||
await this.addCardPaymentMethod( payment );
|
||||
break;
|
||||
}
|
||||
|
@ -487,14 +483,14 @@ export class PayPalUI {
|
|||
/**
|
||||
* Opens PayPal popup
|
||||
*
|
||||
* @param fundingSource
|
||||
* @param dataFundingSource
|
||||
* @return PayPalPopup
|
||||
*/
|
||||
openPayPalPupup = async ( fundingSource = 'paypal' ) => {
|
||||
openPayPalPupup = async ( dataFundingSource: string = 'paypal' ) => {
|
||||
const popupPromise = this.page.waitForEvent( 'popup' );
|
||||
|
||||
await expect( this.fundingSourceButton( fundingSource ) ).toBeVisible();
|
||||
await this.fundingSourceButton( fundingSource ).click();
|
||||
await expect( this.fundingSourceButton( dataFundingSource ) ).toBeVisible();
|
||||
await this.fundingSourceButton( dataFundingSource ).click();
|
||||
|
||||
const popup = await popupPromise;
|
||||
await popup.waitForLoadState();
|
||||
|
@ -615,7 +611,7 @@ export class PayPalUI {
|
|||
|
||||
// In the following request Playwright replaces Auth header with Basic Auth from .env,
|
||||
// But the header should be from PayPal. Here it's replaced manually:
|
||||
replacePayPalAuthToken = async ( merchant: PcpMerchant ) => {
|
||||
replacePayPalAuthToken = async ( merchant: Pcp.Merchant ) => {
|
||||
await this.page.route(
|
||||
'https://www.sandbox.paypal.com/v2/checkout/orders/**/*',
|
||||
async ( route ) => {
|
||||
|
@ -637,8 +633,8 @@ export class PayPalUI {
|
|||
* @param merchant
|
||||
*/
|
||||
completeAcdcPayment = async (
|
||||
payment: PcpPayment,
|
||||
merchant: PcpMerchant
|
||||
payment: Pcp.Payment,
|
||||
merchant: Pcp.Merchant
|
||||
) => {
|
||||
await expect( this.acdcGateway() ).toBeVisible();
|
||||
await this.acdcGateway().click();
|
||||
|
@ -666,8 +662,8 @@ export class PayPalUI {
|
|||
};
|
||||
|
||||
completeAcdcVaultedPayment = async (
|
||||
payment: PcpPayment,
|
||||
merchant: PcpMerchant
|
||||
payment: Pcp.Payment,
|
||||
merchant: Pcp.Merchant
|
||||
) => {
|
||||
await expect( this.acdcGateway() ).toBeVisible();
|
||||
await this.acdcGateway().click();
|
||||
|
@ -677,8 +673,8 @@ export class PayPalUI {
|
|||
};
|
||||
|
||||
completeAcdc3dsPayment = async (
|
||||
payment: PcpPayment,
|
||||
merchant: PcpMerchant
|
||||
payment: Pcp.Payment,
|
||||
merchant: Pcp.Merchant
|
||||
) => {
|
||||
await this.completeAcdcPayment( payment, merchant );
|
||||
await this.threeDSAcceptCookiesButton().click();
|
||||
|
@ -779,7 +775,7 @@ export class PayPalUI {
|
|||
await payPal.savePaymentMethodAndContinue();
|
||||
};
|
||||
|
||||
addCardPaymentMethod = async ( payment: PcpPayment ) => {
|
||||
addCardPaymentMethod = async ( payment: Pcp.Payment ) => {
|
||||
await expect( this.debitCreditCardsGateway() ).toBeVisible();
|
||||
await this.debitCreditCardsGateway().click();
|
||||
await this.cardNumberInput().fill( payment.card.card_number );
|
||||
|
|
|
@ -6,7 +6,7 @@ import { createAuthHeader } from '@inpsyde/playwright-utils/build';
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { PcpFundingSource, PcpMerchant, PcpPayment } from '../resources';
|
||||
import { Pcp } from '../resources';
|
||||
|
||||
/**
|
||||
* Class for PayPal API
|
||||
|
@ -23,7 +23,7 @@ export class PayPalAPI {
|
|||
private apiRequest = async (
|
||||
requestType: string,
|
||||
endPoint: string,
|
||||
merchant: PcpMerchant,
|
||||
merchant: Pcp.Merchant,
|
||||
data?: any
|
||||
) => {
|
||||
try {
|
||||
|
@ -56,7 +56,7 @@ export class PayPalAPI {
|
|||
*
|
||||
* @param merchant - { client_id: '...', client_secret: '...' }
|
||||
*/
|
||||
getToken = async ( merchant: PcpMerchant ) => {
|
||||
getToken = async ( merchant: Pcp.Merchant ) => {
|
||||
const response = await this.request.post(
|
||||
'https://api.sandbox.paypal.com/v1/oauth2/token',
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ export class PayPalAPI {
|
|||
*/
|
||||
getCapturedPayment = async (
|
||||
resourceId: string,
|
||||
merchant: PcpMerchant
|
||||
merchant: Pcp.Merchant
|
||||
) => {
|
||||
return await this.apiRequest(
|
||||
'get',
|
||||
|
@ -95,7 +95,7 @@ export class PayPalAPI {
|
|||
*/
|
||||
getAuthorizedPayment = async (
|
||||
resourceId: string,
|
||||
merchant: PcpMerchant
|
||||
merchant: Pcp.Merchant
|
||||
) => {
|
||||
return await this.apiRequest(
|
||||
'get',
|
||||
|
@ -110,7 +110,7 @@ export class PayPalAPI {
|
|||
* @param resourceId - PayPal order ID
|
||||
* @param merchant - { client_id: '...', client_secret: '...' }
|
||||
*/
|
||||
getOrder = async ( resourceId: string, merchant: PcpMerchant ) => {
|
||||
getOrder = async ( resourceId: string, merchant: Pcp.Merchant ) => {
|
||||
return await this.apiRequest(
|
||||
'get',
|
||||
`/checkout/orders/${ resourceId }`,
|
||||
|
@ -124,7 +124,7 @@ export class PayPalAPI {
|
|||
* @param resourceId - PayPal order ID
|
||||
* @param merchant - { client_id: '...', client_secret: '...' }
|
||||
*/
|
||||
getRefund = async ( resourceId: string, merchant: PcpMerchant ) => {
|
||||
getRefund = async ( resourceId: string, merchant: Pcp.Merchant ) => {
|
||||
return await this.apiRequest(
|
||||
'get',
|
||||
`/payments/refunds/${ resourceId }`,
|
||||
|
@ -146,8 +146,8 @@ export class PayPalAPI {
|
|||
* @param payPalOrder
|
||||
* @param payment
|
||||
*/
|
||||
getPaymentIdFromOrder = async ( payPalOrder, payment: PcpPayment ) => {
|
||||
const fundingSource: PcpFundingSource = payment.dataFundingSource;
|
||||
getPaymentIdFromOrder = async ( payPalOrder, payment: Pcp.Payment ) => {
|
||||
const fundingSource = payment.gateway.dataFundingSource;
|
||||
|
||||
if ( fundingSource === 'pay_upon_invoice' ) {
|
||||
return '';
|
||||
|
@ -190,8 +190,7 @@ export class PayPalAPI {
|
|||
* @param shopOrder
|
||||
*/
|
||||
getFee = async ( resourceId: string, shopOrder: WooCommerce.ShopOrder ) => {
|
||||
const fundingSource: PcpFundingSource =
|
||||
shopOrder.payment.dataFundingSource;
|
||||
const fundingSource = shopOrder.payment.gateway.dataFundingSource;
|
||||
if (
|
||||
[ 'pay_upon_invoice', 'oxxo' ].includes( fundingSource ) ||
|
||||
shopOrder.payment.isAuthorized
|
||||
|
@ -206,8 +205,7 @@ export class PayPalAPI {
|
|||
resourceId: string,
|
||||
shopOrder: WooCommerce.ShopOrder
|
||||
) => {
|
||||
const fundingSource: PcpFundingSource =
|
||||
shopOrder.payment.dataFundingSource;
|
||||
const fundingSource = shopOrder.payment.gateway.dataFundingSource;
|
||||
if (
|
||||
[ 'pay_upon_invoice', 'oxxo' ].includes( fundingSource ) ||
|
||||
shopOrder.payment.isAuthorized
|
||||
|
@ -230,8 +228,7 @@ export class PayPalAPI {
|
|||
wooCommerceOrderJson: WooCommerce.Order,
|
||||
shopOrder: WooCommerce.ShopOrder
|
||||
) => {
|
||||
const fundingSource: PcpFundingSource =
|
||||
shopOrder.payment.dataFundingSource;
|
||||
const fundingSource = shopOrder.payment.gateway.dataFundingSource;
|
||||
const payPalOrderId = await this.getOrderIdFromWooCommerce(
|
||||
wooCommerceOrderJson
|
||||
);
|
||||
|
@ -348,8 +345,7 @@ export class PayPalAPI {
|
|||
paymentId: string,
|
||||
shopOrder: WooCommerce.ShopOrder
|
||||
) => {
|
||||
const fundingSource: PcpFundingSource =
|
||||
shopOrder.payment.dataFundingSource;
|
||||
const fundingSource = shopOrder.payment.gateway.dataFundingSource;
|
||||
|
||||
if ( fundingSource === 'pay_upon_invoice' ) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue