Skip to content

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

fix(connector): [Stripe] add decline_code in error_reason (#2735)

Sai Harsha Vardhan0a44f5699ed7
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs
index 59700ecf35..e3551306e6 100644
--- a/crates/router/src/connector/stripe.rs
+++ b/crates/router/src/connector/stripe.rs
@@ -216,7 +216,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -334,7 +342,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -448,7 +464,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -570,7 +594,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -702,7 +734,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -848,7 +888,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -959,7 +1007,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -1105,7 +1161,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -1214,7 +1278,15 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -1309,7 +1381,15 @@ impl services::ConnectorIntegration<api::RSync, types::RefundsData, types::Refun
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -1445,7 +1525,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -1539,7 +1627,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
@@ -1656,7 +1752,15 @@ impl
.error
.code
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
- reason: response.error.message,
+ reason: response.error.message.map(|message| {
+ response
+ .error
+ .decline_code
+ .map(|decline_code| {
+ format!("message - {}, decline_code - {}", message, decline_code)
+ })
+ .unwrap_or(message)
+ }),
})
}
}
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index a3711a5497..fa9d7d6170 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -2118,6 +2118,7 @@ impl Deref for PaymentSyncResponse {
pub struct LastPaymentError {
code: String,
message: String,
+ decline_code: Option<String>,
}
#[derive(Deserialize, Debug)]
@@ -2463,7 +2464,16 @@ impl<F, T>
.map(|error| types::ErrorResponse {
code: error.code.to_owned(),
message: error.code.to_owned(),
- reason: Some(error.message.to_owned()),
+ reason: error
+ .decline_code
+ .clone()
+ .map(|decline_code| {
+ format!(
+ "message - {}, decline_code - {}",
+ error.message, decline_code
+ )
+ })
+ .or(Some(error.message.clone())),
status_code: item.http_code,
});
@@ -2772,6 +2782,7 @@ pub struct ErrorDetails {
pub error_type: Option<String>,
pub message: Option<String>,
pub param: Option<String>,
+ pub decline_code: Option<String>,
}
#[derive(Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/.meta.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/.meta.json
new file mode 100644
index 0000000000..69b505c6d8
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/.meta.json
@@ -0,0 +1,3 @@
+{
+ "childrenOrder": ["Payments - Create", "Payments - Retrieve"]
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/.event.meta.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/.event.meta.json
new file mode 100644
index 0000000000..0731450e6b
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/.event.meta.json
@@ -0,0 +1,3 @@
+{
+ "eventOrder": ["event.test.js"]
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/event.test.js b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/event.test.js
new file mode 100644
index 0000000000..2be75ec008
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/event.test.js
@@ -0,0 +1,100 @@
+// Validate status 2xx
+pm.test("[POST]::/payments - Status code is 2xx", function () {
+ pm.response.to.be.success;
+});
+
+// Validate if response header has matching content-type
+pm.test("[POST]::/payments - Content-Type is application/json", function () {
+ pm.expect(pm.response.headers.get("Content-Type")).to.include(
+ "application/json",
+ );
+});
+
+// Validate if response has JSON Body
+pm.test("[POST]::/payments - Response has JSON Body", function () {
+ pm.response.to.have.jsonBody();
+});
+
+// Set response object as internal variable
+let jsonData = {};
+try {
+ jsonData = pm.response.json();
+} catch (e) {}
+
+// pm.collectionVariables - Set payment_id as variable for jsonData.payment_id
+if (jsonData?.payment_id) {
+ pm.collectionVariables.set("payment_id", jsonData.payment_id);
+ console.log(
+ "- use {{payment_id}} as collection variable for value",
+ jsonData.payment_id,
+ );
+} else {
+ console.log(
+ "INFO - Unable to assign variable {{payment_id}}, as jsonData.payment_id is undefined.",
+ );
+}
+
+// pm.collectionVariables - Set mandate_id as variable for jsonData.mandate_id
+if (jsonData?.mandate_id) {
+ pm.collectionVariables.set("mandate_id", jsonData.mandate_id);
+ console.log(
+ "- use {{mandate_id}} as collection variable for value",
+ jsonData.mandate_id,
+ );
+} else {
+ console.log(
+ "INFO - Unable to assign variable {{mandate_id}}, as jsonData.mandate_id is undefined.",
+ );
+}
+
+// pm.collectionVariables - Set client_secret as variable for jsonData.client_secret
+if (jsonData?.client_secret) {
+ pm.collectionVariables.set("client_secret", jsonData.client_secret);
+ console.log(
+ "- use {{client_secret}} as collection variable for value",
+ jsonData.client_secret,
+ );
+} else {
+ console.log(
+ "INFO - Unable to assign variable {{client_secret}}, as jsonData.client_secret is undefined.",
+ );
+}
+
+// Response body should have value "succeeded" for "status"
+if (jsonData?.status) {
+ pm.test(
+ "[POST]::/payments - Content check if value for 'status' matches 'failed'",
+ function () {
+ pm.expect(jsonData.status).to.eql("failed");
+ },
+ );
+}
+
+// Response body should have "connector_transaction_id"
+pm.test(
+ "[POST]::/payments - Content check if 'connector_transaction_id' exists",
+ function () {
+ pm.expect(typeof jsonData.connector_transaction_id !== "undefined").to.be
+ .true;
+ },
+);
+
+// Response body should have value "card_declined" for "error_code"
+if (jsonData?.error_code) {
+ pm.test(
+ "[POST]::/payments/:id/confirm - Content check if value for 'error_code' matches 'card_declined'",
+ function () {
+ pm.expect(jsonData.error_code).to.eql("card_declined");
+ },
+ );
+}
+
+// Response body should have value "message - Your card has insufficient funds., decline_code - insufficient_funds" for "error_message"
+if (jsonData?.error_message) {
+ pm.test(
+ "[POST]::/payments/:id/confirm - Content check if value for 'error_message' matches 'message - Your card has insufficient funds., decline_code - insufficient_funds'",
+ function () {
+ pm.expect(jsonData.error_message).to.eql("message - Your card has insufficient funds., decline_code - insufficient_funds");
+ },
+ );
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/request.json
new file mode 100644
index 0000000000..150139b8e1
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/request.json
@@ -0,0 +1,94 @@
+{
+ "method": "POST",
+ "header": [
+ {
+ "key": "Content-Type",
+ "value": "application/json"
+ },
+ {
+ "key": "Accept",
+ "value": "application/json"
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "options": {
+ "raw": {
+ "language": "json"
+ }
+ },
+ "raw_json_formatted": {
+ "amount": 6540,
+ "currency": "USD",
+ "confirm": true,
+ "business_country": "US",
+ "business_label": "default",
+ "capture_method": "automatic",
+ "capture_on": "2022-09-10T10:11:12Z",
+ "amount_to_capture": 1,
+ "customer_id": "bernard123",
+ "email": "[email protected]",
+ "name": "John Doe",
+ "phone": "999999999",
+ "phone_country_code": "+65",
+ "description": "Its my first payment request",
+ "authentication_type": "no_three_ds",
+ "return_url": "https://duck.com",
+ "setup_future_usage": "on_session",
+ "payment_method": "card",
+ "payment_method_type": "debit",
+ "payment_method_data": {
+ "card": {
+ "card_number": "4000000000009995",
+ "card_exp_month": "01",
+ "card_exp_year": "24",
+ "card_holder_name": "joseph Doe",
+ "card_cvc": "123"
+ }
+ },
+ "billing": {
+ "address": {
+ "line1": "1467",
+ "line2": "Harrison Street",
+ "line3": "Harrison Street",
+ "city": "San Fransico",
+ "state": "California",
+ "zip": "94122",
+ "country": "US",
+ "first_name": "sundari",
+ "last_name": "sundari"
+ }
+ },
+ "shipping": {
+ "address": {
+ "line1": "1467",
+ "line2": "Harrison Street",
+ "line3": "Harrison Street",
+ "city": "San Fransico",
+ "state": "California",
+ "zip": "94122",
+ "country": "US",
+ "first_name": "sundari",
+ "last_name": "sundari"
+ }
+ },
+ "statement_descriptor_name": "joseph",
+ "statement_descriptor_suffix": "JS",
+ "metadata": {
+ "udf1": "value1",
+ "new_customer": "true",
+ "login_date": "2019-09-10T10:11:12Z"
+ },
+ "routing": {
+ "type": "single",
+ "data": "stripe"
+ }
+ }
+ },
+ "url": {
+ "raw": "{{baseUrl}}/payments",
+ "host": ["{{baseUrl}}"],
+ "path": ["payments"]
+ },
+ "description": "To process a payment you will have to create a payment, attach a payment method and confirm. Depending on the user journey you wish to achieve, you may opt to all the steps in a single request or in a sequence of API request using following APIs: (i) Payments - Update, (ii) Payments - Confirm, and (iii) Payments - Capture"
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/response.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/response.json
new file mode 100644
index 0000000000..fe51488c70
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Create/response.json
@@ -0,0 +1 @@
+[]
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/.event.meta.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/.event.meta.json
new file mode 100644
index 0000000000..0731450e6b
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/.event.meta.json
@@ -0,0 +1,3 @@
+{
+ "eventOrder": ["event.test.js"]
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/event.test.js b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/event.test.js
new file mode 100644
index 0000000000..f8825a3357
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/event.test.js
@@ -0,0 +1,100 @@
+// Validate status 2xx
+pm.test("[GET]::/payments/:id - Status code is 2xx", function () {
+ pm.response.to.be.success;
+});
+
+// Validate if response header has matching content-type
+pm.test("[GET]::/payments/:id - Content-Type is application/json", function () {
+ pm.expect(pm.response.headers.get("Content-Type")).to.include(
+ "application/json",
+ );
+});
+
+// Validate if response has JSON Body
+pm.test("[GET]::/payments/:id - Response has JSON Body", function () {
+ pm.response.to.have.jsonBody();
+});
+
+// Set response object as internal variable
+let jsonData = {};
+try {
+ jsonData = pm.response.json();
+} catch (e) {}
+
+// pm.collectionVariables - Set payment_id as variable for jsonData.payment_id
+if (jsonData?.payment_id) {
+ pm.collectionVariables.set("payment_id", jsonData.payment_id);
+ console.log(
+ "- use {{payment_id}} as collection variable for value",
+ jsonData.payment_id,
+ );
+} else {
+ console.log(
+ "INFO - Unable to assign variable {{payment_id}}, as jsonData.payment_id is undefined.",
+ );
+}
+
+// pm.collectionVariables - Set mandate_id as variable for jsonData.mandate_id
+if (jsonData?.mandate_id) {
+ pm.collectionVariables.set("mandate_id", jsonData.mandate_id);
+ console.log(
+ "- use {{mandate_id}} as collection variable for value",
+ jsonData.mandate_id,
+ );
+} else {
+ console.log(
+ "INFO - Unable to assign variable {{mandate_id}}, as jsonData.mandate_id is undefined.",
+ );
+}
+
+// pm.collectionVariables - Set client_secret as variable for jsonData.client_secret
+if (jsonData?.client_secret) {
+ pm.collectionVariables.set("client_secret", jsonData.client_secret);
+ console.log(
+ "- use {{client_secret}} as collection variable for value",
+ jsonData.client_secret,
+ );
+} else {
+ console.log(
+ "INFO - Unable to assign variable {{client_secret}}, as jsonData.client_secret is undefined.",
+ );
+}
+
+// Response body should have value "Succeeded" for "status"
+if (jsonData?.status) {
+ pm.test(
+ "[POST]::/payments/:id - Content check if value for 'status' matches 'failed'",
+ function () {
+ pm.expect(jsonData.status).to.eql("failed");
+ },
+ );
+}
+
+// Response body should have "connector_transaction_id"
+pm.test(
+ "[POST]::/payments - Content check if 'connector_transaction_id' exists",
+ function () {
+ pm.expect(typeof jsonData.connector_transaction_id !== "undefined").to.be
+ .true;
+ },
+);
+
+// Response body should have value "card_declined" for "error_code"
+if (jsonData?.error_code) {
+ pm.test(
+ "[POST]::/payments/:id/confirm - Content check if value for 'error_code' matches 'card_declined'",
+ function () {
+ pm.expect(jsonData.error_code).to.eql("card_declined");
+ },
+ );
+}
+
+// Response body should have value "message - Your card has insufficient funds., decline_code - insufficient_funds" for "error_message"
+if (jsonData?.error_message) {
+ pm.test(
+ "[POST]::/payments/:id/confirm - Content check if value for 'error_message' matches 'message - Your card has insufficient funds., decline_code - insufficient_funds'",
+ function () {
+ pm.expect(jsonData.error_message).to.eql("message - Your card has insufficient funds., decline_code - insufficient_funds");
+ },
+ );
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/request.json
new file mode 100644
index 0000000000..6cd4b7d96c
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/request.json
@@ -0,0 +1,28 @@
+{
+ "method": "GET",
+ "header": [
+ {
+ "key": "Accept",
+ "value": "application/json"
+ }
+ ],
+ "url": {
+ "raw": "{{baseUrl}}/payments/:id?force_sync=true",
+ "host": ["{{baseUrl}}"],
+ "path": ["payments", ":id"],
+ "query": [
+ {
+ "key": "force_sync",
+ "value": "true"
+ }
+ ],
+ "variable": [
+ {
+ "key": "id",
+ "value": "{{payment_id}}",
+ "description": "(Required) unique payment id"
+ }
+ ]
+ },
+ "description": "To retrieve the properties of a Payment. This may be used to get the status of a previously initiated payment or next action for an ongoing payment"
+}
diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/response.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/response.json
new file mode 100644
index 0000000000..fe51488c70
--- /dev/null
+++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario27-Create a failure card payment with confirm true/Payments - Retrieve/response.json
@@ -0,0 +1 @@
+[]