Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
test(cypress): add amount_captured coverage for payments manual update (#14227)
HS-QUALIBOTb560d0932759
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex 810f7d8fbd..2b2afcdb6e 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -4047,6 +4047,111 @@ export const connectorDetails = {},},}),+ ManualPaymentUpdateAmountCaptured: getCustomExchange({+ Configs: {+ skipBillingAssertion: true,+ },+ Request: {+ attempt_status: "charged",+ amount_captured: 2500,+ },+ Response: {+ status: 200,+ body: {+ attempt_status: "charged",+ amount_captured: 2500,+ amount_capturable: 6000,+ },+ },+ }),+ ManualPaymentUpdateAmountCapturedExceedsAmount: getCustomExchange({+ Request: {+ attempt_status: "charged",+ amount_captured: 6001,+ },+ Response: {+ status: 422,+ body: {+ error: {+ type: "invalid_request",+ message: "amount_captured should be less than or equal to amount",+ code: "IR_06",+ },+ },+ },+ }),+ ManualPaymentUpdateAmountCapturedBoundary: getCustomExchange({+ Configs: {+ skipBillingAssertion: true,+ },+ Request: {+ attempt_status: "charged",+ amount_captured: 6000,+ },+ Response: {+ status: 200,+ body: {+ attempt_status: "charged",+ amount_captured: 6000,+ amount_capturable: 6000,+ },+ },+ }),+ // Current-API-actual behaviour: zero amount_captured is accepted (200) —+ // no zero guard exists upstream (crates/router/src/core/payments.rs:14025-14032).+ ManualPaymentUpdateAmountCapturedZero: getCustomExchange({+ Configs: {+ skipBillingAssertion: true,+ },+ Request: {+ attempt_status: "charged",+ amount_captured: 0,+ },+ Response: {+ status: 200,+ body: {+ attempt_status: "charged",+ amount_captured: 0,+ amount_capturable: 6000,+ },+ },+ }),+ ManualPaymentUpdateAmountCapturedWithoutStatus: getCustomExchange({+ Configs: {+ skipBillingAssertion: true,+ },+ Request: {+ amount_captured: 2500,+ },+ Response: {+ status: 200,+ body: {+ attempt_status: "payment_method_awaited",+ amount_captured: 2500,+ amount_capturable: 6000,+ },+ },+ }),+ ManualPaymentUpdateAmountCapturedInvalidType: getCustomExchange({+ Request: {+ attempt_status: "charged",+ amount_captured: 25.5,+ },+ Response: {+ status: 400,+ body: {+ error: {+ error_type: "invalid_request",+ // The trailing " at line 1 column N" of the live message is+ // omitted — the column depends on the serialized request body,+ // and defaultErrorHandler matches deserialize errors by substring.+ message:+ "Json deserialize error: invalid type: floating point `25.5`, expected i64",+ code: "IR_06",+ },+ },+ },+ }),OrderDetails: getCustomExchange({Request: {payment_method: "card",diff --git a/cypress-tests/cypress/e2e/spec/Payment/47-ManualPaymentUpdate.cy.js b/cypress-tests/cypress/e2e/spec/Payment/47-ManualPaymentUpdate.cy.jsindex dac2cdc64f..a690ceceaa 100644--- a/cypress-tests/cypress/e2e/spec/Payment/47-ManualPaymentUpdate.cy.js+++ b/cypress-tests/cypress/e2e/spec/Payment/47-ManualPaymentUpdate.cy.js@@ -155,6 +155,70 @@ describe("Payment Manual Update Tests", () => {});});+ context("Manual Payment Update - Amount Captured", () => {+ it("Create Payment Intent -> Manual Update with amount_captured -> Retrieve Payment", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent with Manual Capture", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PaymentIntent"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "manual",+ globalState+ );++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("Manual Update Payment with amount_captured", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Manual Update Payment with amount_captured"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCaptured"];++ cy.manualPaymentStatusUpdateTest(globalState, data);++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("Retrieve Payment to Verify amount_captured Persistence", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment to Verify amount_captured Persistence"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCaptured"];++ cy.retrievePaymentCallTest({+ globalState,+ data,+ unconfirmedPayment: true,+ });+ });+ });+ });+context("Manual Payment Update - Negative Cases", () => {it("Create Payment Intent -> Manual Update with Invalid Attempt ID", () => {let shouldContinue = true;@@ -191,6 +255,287 @@ describe("Payment Manual Update Tests", () => {});});+ context("Manual Payment Update - Amount Captured Exceeds Amount", () => {+ it("Create Payment Intent -> Manual Update with amount_captured exceeding payment amount", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent with Manual Capture", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PaymentIntent"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "manual",+ globalState+ );++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step(+ "Manual Update with amount_captured exceeding payment amount",+ () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Manual Update with amount_captured exceeding payment amount"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedExceedsAmount"];++ cy.manualPaymentStatusUpdateTest(globalState, data);+ }+ );+ });+ });++ context("Manual Payment Update - Amount Captured Boundary", () => {+ it("Create Payment Intent -> Manual Update with amount_captured equal to payment amount -> Retrieve Payment", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent with Manual Capture", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PaymentIntent"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "manual",+ globalState+ );++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step(+ "Manual Update Payment with amount_captured equal to payment amount",+ () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Manual Update Payment with amount_captured equal to payment amount"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedBoundary"];++ cy.manualPaymentStatusUpdateTest(globalState, data);++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ }+ );++ cy.step("Retrieve Payment to Verify amount_captured Persistence", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment to Verify amount_captured Persistence"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedBoundary"];++ cy.retrievePaymentCallTest({+ globalState,+ data,+ unconfirmedPayment: true,+ });+ });+ });+ });++ context("Manual Payment Update - Amount Captured Zero", () => {+ it("Create Payment Intent -> Manual Update with zero amount_captured -> Retrieve Payment", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent with Manual Capture", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PaymentIntent"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "manual",+ globalState+ );++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("Manual Update Payment with zero amount_captured", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Manual Update Payment with zero amount_captured"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedZero"];++ cy.manualPaymentStatusUpdateTest(globalState, data);++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("Retrieve Payment to Verify amount_captured Persistence", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment to Verify amount_captured Persistence"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedZero"];++ cy.retrievePaymentCallTest({+ globalState,+ data,+ unconfirmedPayment: true,+ });+ });+ });+ });++ context("Manual Payment Update - Amount Captured Without Status", () => {+ it("Create Payment Intent -> Manual Update with amount_captured without attempt_status -> Retrieve Payment", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent with Manual Capture", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PaymentIntent"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "manual",+ globalState+ );++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step(+ "Manual Update Payment with amount_captured without attempt_status",+ () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Manual Update Payment with amount_captured without attempt_status"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedWithoutStatus"];++ cy.manualPaymentStatusUpdateTest(globalState, data);++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ }+ );++ cy.step("Retrieve Payment to Verify amount_captured Persistence", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Retrieve Payment to Verify amount_captured Persistence"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedWithoutStatus"];++ cy.retrievePaymentCallTest({+ globalState,+ data,+ unconfirmedPayment: true,+ });+ });+ });+ });++ context("Manual Payment Update - Amount Captured Invalid Type", () => {+ it("Create Payment Intent -> Manual Update with invalid amount_captured type", () => {+ let shouldContinue = true;++ cy.step("Create Payment Intent with Manual Capture", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PaymentIntent"];++ cy.createPaymentIntentTest(+ fixtures.createPaymentBody,+ data,+ "no_three_ds",+ "manual",+ globalState+ );++ if (!utils.should_continue_further(data)) {+ shouldContinue = false;+ }+ });++ cy.step("Manual Update with invalid amount_captured type", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Manual Update with invalid amount_captured type"+ );+ return;+ }++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["ManualPaymentUpdateAmountCapturedInvalidType"];++ cy.manualPaymentStatusUpdateTest(globalState, data);+ });+ });+ });+context("Manual Payment Update - Edge Cases", () => {it("Create Payment Intent -> Manual Update with Custom Error -> Verify Persistence", () => {let shouldContinue = true;diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 17e2151927..c9fe11af23 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -8786,6 +8786,10 @@ Cypress.Commands.add("manualPaymentStatusUpdateTest", (globalState, data) => {manualUpdateBody.error_message = requestData.error_message;}+ if (typeof requestData.amount_captured !== "undefined") {+ manualUpdateBody.amount_captured = requestData.amount_captured;+ }+cy.request({method: "PUT",url: completeUrl,@@ -8826,6 +8830,31 @@ Cypress.Commands.add("manualPaymentStatusUpdateTest", (globalState, data) => {responseData.body.error_message);}++ if (+ responseData.body &&+ typeof responseData.body.amount_captured !== "undefined"+ ) {+ expect(response.body.amount_captured, "amount_captured").to.equal(+ responseData.body.amount_captured+ );+ }++ if (+ responseData.body &&+ typeof responseData.body.amount_capturable !== "undefined"+ ) {+ expect(response.body.amount_capturable, "amount_capturable").to.equal(+ responseData.body.amount_capturable+ );+ }+ } else if (responseData.body && responseData.body.error) {+ // Expected error response (e.g. 400/422 IR_06 validation failures).+ // defaultErrorHandler asserts the keys configured in+ // Response.body.error, so it covers both error body shapes: 422+ // validation errors use "type" while 400 deserialize errors use+ // "error_type", and deserialize messages are matched by substring.+ defaultErrorHandler(response, responseData);} else {throw new Error(`Payment Update Call Failed with error code "${response.body.error.code}" error message "${response.body.error.message}"`