From d24954aef518caf2e6500e8b5877158b81bb6a72 Mon Sep 17 00:00:00 2001 From: Sanskar Atrey Date: Thu, 7 Nov 2024 12:46:56 +0530 Subject: [PATCH 1/3] =?UTF-8?q?test:=20added=20nested=20iframe=20test=20su?= =?UTF-8?q?pport=20in=20cypress=20and=20external=203ds=20ne=E2=80=A6=20(#7?= =?UTF-8?q?64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Shiva Nandan --- .../e2e/external-3DS-netcetera-e2e-test.cy.ts | 81 +++++++++++++++++++ cypress-tests/cypress/support/commands.ts | 8 ++ cypress-tests/cypress/support/types.ts | 1 + cypress-tests/cypress/support/utils.ts | 9 ++- 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 cypress-tests/cypress/e2e/external-3DS-netcetera-e2e-test.cy.ts diff --git a/cypress-tests/cypress/e2e/external-3DS-netcetera-e2e-test.cy.ts b/cypress-tests/cypress/e2e/external-3DS-netcetera-e2e-test.cy.ts new file mode 100644 index 000000000..333ceb201 --- /dev/null +++ b/cypress-tests/cypress/e2e/external-3DS-netcetera-e2e-test.cy.ts @@ -0,0 +1,81 @@ +import * as testIds from "../../../src/Utilities/TestUtils.bs"; +import { getClientURL, netceteraChallengeTestCard, createPaymentBody, changeObjectKeyValue, connectorProfileIdMapping, connectorEnum } from "../support/utils"; +describe("External 3DS using Netcetera Checks", () => { + let getIframeBody: () => Cypress.Chainable>; + const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') + const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY') + changeObjectKeyValue(createPaymentBody, "profile_id", connectorProfileIdMapping.get(connectorEnum.NETCETERA)) + changeObjectKeyValue(createPaymentBody, "request_external_three_ds_authentication", true) + changeObjectKeyValue(createPaymentBody, "authentication_type", "three_ds") + let iframeSelector = + "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; + + beforeEach(() => { + getIframeBody = () => cy.iframe(iframeSelector); + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { + cy.getGlobalState("clientSecret").then((clientSecret) => { + + cy.visit(getClientURL(clientSecret, publishableKey)); + }); + + }) + }); + + + it("title rendered correctly", () => { + cy.contains("Hyperswitch Unified Checkout").should("be.visible"); + }); + + it("orca-payment-element iframe loaded", () => { + cy.get( + "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element" + ) + .should("be.visible") + .its("0.contentDocument") + .its("body"); + }); + + + it('If the user completes the challenge, the payment should be successful.', () => { + getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click() + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(netceteraChallengeTestCard) + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type("0444") + cy.wait(1000) + getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("1234") + getIframeBody().get("#submit").click(); + cy.wait(4000) + + cy.nestedIFrame("#threeDsAuthFrame", ($body) => { + cy.wrap($body).find('#otp') + .type('1234') + + cy.wrap($body).find('#sendOtp') + .click() + cy.contains("Thanks for your order!").should("be.visible"); + }) + + }) + + it('If the user closes the challenge, the payment should fail.', () => { + getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click() + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(netceteraChallengeTestCard) + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type("0444") + cy.wait(1000) + getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("1234") + getIframeBody().get("#submit").click(); + cy.wait(4000) + + cy.nestedIFrame("#threeDsAuthFrame", ($body) => { + cy.wrap($body) + .find('#cancel') + .click() + cy.contains("Payment Failed!").should("be.visible"); + }) + }) + + +}) + + + + diff --git a/cypress-tests/cypress/support/commands.ts b/cypress-tests/cypress/support/commands.ts index 5a3fe36e2..e04b93f60 100644 --- a/cypress-tests/cypress/support/commands.ts +++ b/cypress-tests/cypress/support/commands.ts @@ -173,3 +173,11 @@ Cypress.Commands.add("createPaymentIntent", (secretKey: string, createPaymentBod Cypress.Commands.add("getGlobalState", (key: any) => { return globalState[key]; }); + +Cypress.Commands.add("nestedIFrame", (selector, callback) => { + cy.iframe("#orca-fullscreen").find(selector).should("exist").should("be.visible").then(($ele) => { + const $body = + $ele.contents().find('body') + callback($body); + }) +}); \ No newline at end of file diff --git a/cypress-tests/cypress/support/types.ts b/cypress-tests/cypress/support/types.ts index d1db388d1..1ad709b50 100644 --- a/cypress-tests/cypress/support/types.ts +++ b/cypress-tests/cypress/support/types.ts @@ -26,6 +26,7 @@ declare global { ): Chainable> createPaymentIntent(secretKey: string, createPaymentBody: Record): Chainable> getGlobalState(key: string): Chainable> + nestedIFrame(selector: string, callback: (body: Chainable>) => void): Chainable; } } } \ No newline at end of file diff --git a/cypress-tests/cypress/support/utils.ts b/cypress-tests/cypress/support/utils.ts index 496d55606..18a484a01 100644 --- a/cypress-tests/cypress/support/utils.ts +++ b/cypress-tests/cypress/support/utils.ts @@ -6,15 +6,17 @@ export const getClientURL = (clientSecret, publishableKey) => { return `${CLIENT_BASE_URL}?isCypressTestMode=true&clientSecret=${clientSecret}&publishableKey=${publishableKey}`; } -export const enum connectorEnum{ +export const enum connectorEnum { TRUSTPAY, ADYEN, - STRIPE + STRIPE, + NETCETERA } export const connectorProfileIdMapping = new Map([ [connectorEnum.TRUSTPAY, "pro_eP323T9e4ApKpilWBfPA"], [connectorEnum.ADYEN, "pro_Kvqzu8WqBZsT1OjHlCj4"], [connectorEnum.STRIPE, "pro_5fVcCxU8MFTYozgtf0P8"], + [connectorEnum.NETCETERA, "pro_h9VHXnJx8s6W4KSZfSUL"] ]); export const createPaymentBody = { @@ -78,7 +80,7 @@ export const createPaymentBody = { } -export const changeObjectKeyValue = (object: Record, key: string, value: string) => { +export const changeObjectKeyValue = (object: Record, key: string, value: boolean | string) => { object[key] = value } @@ -128,3 +130,4 @@ export const adyenTestCard = "4917610000000000"; export const bluesnapTestCard = "4000000000001091"; export const amexTestCard = "378282246310005" export const visaTestCard = "4242424242424242"; +export const netceteraChallengeTestCard = "348638267931507"; \ No newline at end of file From bb98ae66e17baad2638c6b261b293df982de66eb Mon Sep 17 00:00:00 2001 From: sakksham7 <130480324+sakksham7@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:05:46 +0530 Subject: [PATCH 2/3] chore: added dynamic fields for ach (#777) --- src/Payments/ACHBankTransfer.res | 16 ++++++++++++---- src/Payments/PaymentMethodsRecord.res | 1 + src/Utilities/PaymentBody.res | 17 +---------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Payments/ACHBankTransfer.res b/src/Payments/ACHBankTransfer.res index c4665addb..98a91da37 100644 --- a/src/Payments/ACHBankTransfer.res +++ b/src/Payments/ACHBankTransfer.res @@ -10,7 +10,8 @@ let make = (~paymentType: CardThemeType.mode) => { let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), BankTransfer) let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState) let setComplete = Recoil.useSetRecoilState(fieldsComplete) - let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) + + let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make()) let complete = email.value != "" && email.isValid->Option.getOr(false) let empty = email.value == "" @@ -27,9 +28,14 @@ let make = (~paymentType: CardThemeType.mode) => { let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper if confirm.doSubmit { if complete { - let (connectors, _) = paymentMethodListValue->PaymentUtils.getConnectors(BankTransfer(ACH)) + let bodyArr = + PaymentBody.dynamicPaymentBody("bank_transfer", "ach") + ->getJsonFromArrayOfJson + ->flattenObject(true) + ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) + ->getArrayOfTupleFromDict intent( - ~bodyArr=PaymentBody.achBankTransferBody(~email=email.value, ~connectors), + ~bodyArr, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ~iframeId, @@ -43,7 +49,9 @@ let make = (~paymentType: CardThemeType.mode) => { useSubmitPaymentData(submitCallback)
- +
diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res index 68dea2a52..939697eaf 100644 --- a/src/Payments/PaymentMethodsRecord.res +++ b/src/Payments/PaymentMethodsRecord.res @@ -681,6 +681,7 @@ let dynamicFieldsEnabledPaymentMethods = [ "upi_collect", "sepa", "affirm", + "ach", ] let getIsBillingField = requiredFieldType => { diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index c7c8d2356..eaa5c76bb 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -654,21 +654,6 @@ let epsBody = (~name, ~bankName) => [ ), ] -let achBankTransferBody = (~email, ~connectors) => [ - ("payment_method", "bank_transfer"->JSON.Encode.string), - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method_type", "ach"->JSON.Encode.string), - ( - "payment_method_data", - [ - ("billing", [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), - ( - "bank_transfer", - [("ach_bank_transfer", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, - ), - ]->Utils.getJsonFromArrayOfJson, - ), -] let bacsBankTransferBody = (~email, ~name, ~connectors) => { let (firstName, lastName) = name->Utils.getFirstAndLastNameFromFullName @@ -945,7 +930,7 @@ let appendRedirectPaymentMethods = [ ] let appendBankeDebitMethods = ["sepa"] -let appendBankTransferMethods = ["sepa"] +let appendBankTransferMethods = ["sepa", "ach"] let getPaymentMethodSuffix = (~paymentMethodType, ~paymentMethod, ~isQrPaymentMethod) => { if isQrPaymentMethod { From 2930ae0d9feff46481e3b4df327e1de304de541a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 7 Nov 2024 07:37:29 +0000 Subject: [PATCH 3/3] chore(release): 0.101.2 [skip ci] ## [0.101.2](https://github.com/juspay/hyperswitch-web/compare/v0.101.1...v0.101.2) (2024-11-07) --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ecbd4e3..8f5c9c6ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## [0.101.2](https://github.com/juspay/hyperswitch-web/compare/v0.101.1...v0.101.2) (2024-11-07) + ## [0.101.1](https://github.com/juspay/hyperswitch-web/compare/v0.101.0...v0.101.1) (2024-11-07) # [0.101.0](https://github.com/juspay/hyperswitch-web/compare/v0.100.1...v0.101.0) (2024-11-07) diff --git a/package-lock.json b/package-lock.json index 5853054d8..13479c43a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "orca-payment-page", - "version": "0.101.1", + "version": "0.101.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "orca-payment-page", - "version": "0.101.1", + "version": "0.101.2", "hasInstallScript": true, "dependencies": { "@glennsl/rescript-fetch": "^0.2.0", diff --git a/package.json b/package.json index 18e32f89b..7f83f3d0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orca-payment-page", - "version": "0.101.1", + "version": "0.101.2", "main": "index.js", "private": true, "dependencies": {