-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f16c820
commit 33a37a3
Showing
7 changed files
with
277 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as testIds from "../../../src/Utilities/TestUtils.bs"; | ||
import { getClientURL } from "../support/utils"; | ||
import { createPaymentBody } from "../support/utils"; | ||
import { changeObjectKeyValue } from "../support/utils"; | ||
import { stripeCards } from "cypress/support/cards"; | ||
|
||
describe("Card payment flow test", () => { | ||
|
||
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') | ||
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY') | ||
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>; | ||
let iframeSelector = | ||
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; | ||
|
||
// changeObjectKeyValue(createPaymentBody,"profile_id","YOUR_PROFILE_ID") | ||
|
||
|
||
beforeEach(() => { | ||
getIframeBody = () => cy.iframe(iframeSelector); | ||
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { | ||
cy.getGlobalState("clientSecret").then((clientSecret) => { | ||
|
||
cy.visit(getClientURL(clientSecret, publishableKey)); | ||
}); | ||
|
||
}) | ||
}); | ||
|
||
it("should complete the card payment successfully", () => { | ||
// Visit the page with the payment form | ||
//cy.visit(CLIENT_URL); | ||
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
// Wait for iframe to load and get its body | ||
getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Example card number | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year | ||
getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV | ||
|
||
// Click on the submit button | ||
getIframeBody().get("#submit").click(); | ||
|
||
// Wait for the response and assert payment success message | ||
cy.wait(3000); // Adjust wait time based on actual response time | ||
cy.contains("Thanks for your order!").should("be.visible"); | ||
}); | ||
|
||
|
||
it("should fail with an invalid card number", () => { | ||
// cy.visit(CLIENT_URL); | ||
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.invalidCard; | ||
|
||
getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Invalid card number | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year | ||
getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV | ||
|
||
getIframeBody().get("#submit").click(); | ||
|
||
cy.wait(3000); // Adjust wait time based on actual response time | ||
cy.contains("Please enter valid details").should("be.visible"); // Adjust based on actual error message | ||
}); | ||
|
||
it("should show error for expired card year", () => { | ||
//cy.visit(CLIENT_URL); | ||
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.invalidYear; | ||
|
||
getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Valid card number | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year | ||
getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV | ||
|
||
getIframeBody().get("#submit").click(); | ||
|
||
cy.wait(3000); // Adjust wait time based on actual response time | ||
getIframeBody().find('.Error.pt-1').should('be.visible') | ||
.and('contain.text', "Your card's expiration year is in the past."); | ||
}); | ||
|
||
it("should show error for incomplete card CVV", () => { | ||
//cy.visit(CLIENT_URL); | ||
const{ cardNo, card_exp_month , card_exp_year ,cvc}=stripeCards.invalidCVC | ||
|
||
getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Valid card number | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year | ||
getIframeBody().find('[data-testid=cvvInput]').type(cvc); // Incomplete CVV | ||
|
||
getIframeBody().get("#submit").click(); | ||
|
||
cy.wait(3000); // Adjust wait time based on actual response time | ||
getIframeBody().find('.Error.pt-1').should('be.visible') | ||
.and('contain.text', "Your card's security code is incomplete."); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as testIds from "../../../src/Utilities/TestUtils.bs"; | ||
import { getClientURL } from "../support/utils"; | ||
import { createPaymentBody } from "../support/utils"; | ||
import { changeObjectKeyValue } from "../support/utils"; | ||
import { stripeCards } from "cypress/support/cards"; | ||
|
||
describe("Card payment flow test", () => { | ||
|
||
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') | ||
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY') | ||
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>; | ||
let iframeSelector = | ||
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; | ||
|
||
changeObjectKeyValue(createPaymentBody,"authentication_type","three_ds") | ||
|
||
|
||
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(iframeSelector) | ||
.should("be.visible") | ||
.its("0.contentDocument") | ||
.its("body"); | ||
}); | ||
|
||
it("should complete the card payment successfully", () => { | ||
// Visit the page with the payment form | ||
const{ cardNo,cvc, card_exp_month, card_exp_year}=stripeCards.threeDSCard | ||
// Wait for iframe to load and get its body | ||
getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Example card number | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year | ||
getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV | ||
|
||
// Click on the submit button | ||
getIframeBody().get("#submit").click(); | ||
|
||
// Wait for the response and assert payment success message | ||
cy.wait(3000); // Adjust wait time based on actual response time | ||
cy.url().should('include', 'hooks.stripe.com/3d_secure_2'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as testIds from "../../../src/Utilities/TestUtils.bs"; | ||
import { getClientURL } from "../support/utils"; | ||
import { createPaymentBody } from "../support/utils"; | ||
import { changeObjectKeyValue } from "../support/utils"; | ||
import { stripeCards } from "cypress/support/cards"; | ||
|
||
describe("Card payment flow test", () => { | ||
|
||
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') | ||
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY') | ||
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>; | ||
let iframeSelector = | ||
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; | ||
|
||
changeObjectKeyValue(createPaymentBody,"capture_method","manual") | ||
|
||
|
||
beforeEach(() => { | ||
getIframeBody = () => cy.iframe(iframeSelector); | ||
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { | ||
cy.getGlobalState("clientSecret").then((clientSecret) => { | ||
|
||
cy.visit(getClientURL(clientSecret, publishableKey)); | ||
}); | ||
|
||
}) | ||
}); | ||
|
||
it("should complete the card payment successfully", () => { | ||
|
||
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
// Wait for iframe to load and get its body | ||
getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Example card number | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month | ||
getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year | ||
getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV | ||
|
||
// Click on the submit button | ||
getIframeBody().get("#submit").click(); | ||
|
||
// Wait for the response and assert payment processing message | ||
cy.wait(3000); | ||
cy.contains('Payment processing! Requires manual capture') | ||
.should('be.visible'); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
export type cardDetails = { | ||
cardNo: string, | ||
cardScheme: string, | ||
cvc: string, | ||
card_exp_month: string, | ||
card_exp_year: string, | ||
|
||
} | ||
|
||
|
||
type connectorCard = { | ||
successCard: cardDetails | ||
failureCard: cardDetails | ||
threeDSCard: cardDetails | ||
invalidCard: cardDetails | ||
invalidCVC : cardDetails | ||
invalidMonth:cardDetails | ||
invalidYear: cardDetails | ||
} | ||
|
||
|
||
export const stripeCards = { | ||
successCard: { | ||
cardNo: "4242424242424242", | ||
cardScheme: "Visa", | ||
cvc: "123", | ||
card_exp_month:"12", | ||
card_exp_year:"30", | ||
}, | ||
failureCard: { | ||
cardNo: "4000000000000002", | ||
cardScheme: "Visa", | ||
cvc: "123", | ||
card_exp_month:"12", | ||
card_exp_year:"30", | ||
}, | ||
invalidYear: { | ||
cardNo: "4242424242424242", | ||
cardScheme: "Visa", | ||
cvc: "123", | ||
card_exp_month:"12", | ||
card_exp_year:"10", | ||
}, | ||
invalidCVC: { | ||
cardNo: "4000000000000002", | ||
cardScheme: "Visa", | ||
cvc: "12", | ||
card_exp_month:"12", | ||
card_exp_year:"30", | ||
}, | ||
invalidCard: { | ||
cardNo: "400000000000000", | ||
cardScheme: "Visa", | ||
cvc: "123", | ||
card_exp_month:"12", | ||
card_exp_year:"30", | ||
}, | ||
invalidMonth: { | ||
cardNo: "4000000000000002", | ||
cardScheme: "Visa", | ||
cvc: "123", | ||
card_exp_month:"13", | ||
card_exp_year:"30", | ||
}, | ||
threeDSCard: { | ||
cardNo: "4000000000003220", | ||
cardScheme: "Visa", | ||
cvc: "123", | ||
card_exp_month:"13", | ||
card_exp_year:"30", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters