Skip to content

Commit efed596

Browse files
fix(connector): [Forte] Response Handling for Verify Action (#2601)
Co-authored-by: Prasunna Soppa <[email protected]>
1 parent 13c66df commit efed596

File tree

11 files changed

+276
-0
lines changed

11 files changed

+276
-0
lines changed

crates/router/src/connector/forte/transformers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl ForeignFrom<(ForteResponseCode, ForteAction)> for enums::AttemptStatus {
179179
ForteResponseCode::A01 => match action {
180180
ForteAction::Authorize => Self::Authorized,
181181
ForteAction::Sale => Self::Pending,
182+
ForteAction::Verify => Self::Charged,
182183
},
183184
ForteResponseCode::A05 | ForteResponseCode::A06 => Self::Authorizing,
184185
_ => Self::Failure,
@@ -232,6 +233,7 @@ pub struct ResponseStatus {
232233
pub enum ForteAction {
233234
Sale,
234235
Authorize,
236+
Verify,
235237
}
236238

237239
#[derive(Debug, Deserialize)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"childrenOrder": ["Payments - Create", "Payments - Retrieve"]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"eventOrder": ["event.test.js"]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Validate status 2xx
2+
pm.test("[POST]::/payments - Status code is 2xx", function () {
3+
pm.response.to.be.success;
4+
});
5+
6+
// Validate if response header has matching content-type
7+
pm.test("[POST]::/payments - Content-Type is application/json", function () {
8+
pm.expect(pm.response.headers.get("Content-Type")).to.include(
9+
"application/json",
10+
);
11+
});
12+
13+
// Validate if response has JSON Body
14+
pm.test("[POST]::/payments - Response has JSON Body", function () {
15+
pm.response.to.have.jsonBody();
16+
});
17+
18+
// Set response object as internal variable
19+
let jsonData = {};
20+
try {
21+
jsonData = pm.response.json();
22+
} catch (e) {}
23+
24+
// pm.collectionVariables - Set payment_id as variable for jsonData.payment_id
25+
if (jsonData?.payment_id) {
26+
pm.collectionVariables.set("payment_id", jsonData.payment_id);
27+
console.log(
28+
"- use {{payment_id}} as collection variable for value",
29+
jsonData.payment_id,
30+
);
31+
} else {
32+
console.log(
33+
"INFO - Unable to assign variable {{payment_id}}, as jsonData.payment_id is undefined.",
34+
);
35+
}
36+
37+
// pm.collectionVariables - Set mandate_id as variable for jsonData.mandate_id
38+
if (jsonData?.mandate_id) {
39+
pm.collectionVariables.set("mandate_id", jsonData.mandate_id);
40+
console.log(
41+
"- use {{mandate_id}} as collection variable for value",
42+
jsonData.mandate_id,
43+
);
44+
} else {
45+
console.log(
46+
"INFO - Unable to assign variable {{mandate_id}}, as jsonData.mandate_id is undefined.",
47+
);
48+
}
49+
50+
// pm.collectionVariables - Set client_secret as variable for jsonData.client_secret
51+
if (jsonData?.client_secret) {
52+
pm.collectionVariables.set("client_secret", jsonData.client_secret);
53+
console.log(
54+
"- use {{client_secret}} as collection variable for value",
55+
jsonData.client_secret,
56+
);
57+
} else {
58+
console.log(
59+
"INFO - Unable to assign variable {{client_secret}}, as jsonData.client_secret is undefined.",
60+
);
61+
}
62+
63+
// Response body should have value "processing" for "status"
64+
if (jsonData?.status) {
65+
pm.test(
66+
"[POST]::/payments - Content check if value for 'status' matches 'succeeded'",
67+
function () {
68+
pm.expect(jsonData.status).to.eql("succeeded");
69+
},
70+
);
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"method": "POST",
3+
"header": [
4+
{
5+
"key": "Content-Type",
6+
"value": "application/json"
7+
},
8+
{
9+
"key": "Accept",
10+
"value": "application/json"
11+
}
12+
],
13+
"body": {
14+
"mode": "raw",
15+
"options": {
16+
"raw": {
17+
"language": "json"
18+
}
19+
},
20+
"raw_json_formatted": {
21+
"amount": 0,
22+
"currency": "USD",
23+
"confirm": true,
24+
"capture_method": "automatic",
25+
"capture_on": "2022-09-10T10:11:12Z",
26+
"customer_id": "StripeCustomer",
27+
"email": "[email protected]",
28+
"name": "John Doe",
29+
"phone": "999999999",
30+
"phone_country_code": "+65",
31+
"description": "Its my first payment request",
32+
"authentication_type": "no_three_ds",
33+
"routing": {
34+
"type": "single",
35+
"data": "forte"
36+
},
37+
"return_url": "https://duck.com",
38+
"payment_method": "card",
39+
"payment_method_data": {
40+
"card": {
41+
"card_number": "4242424242424242",
42+
"card_exp_month": "10",
43+
"card_exp_year": "25",
44+
"card_holder_name": "joseph Doe",
45+
"card_cvc": "123"
46+
}
47+
},
48+
"billing": {
49+
"address": {
50+
"line1": "1467",
51+
"line2": "Harrison Street",
52+
"line3": "Harrison Street",
53+
"city": "San Fransico",
54+
"state": "California",
55+
"zip": "94122",
56+
"country": "US",
57+
"first_name": "PiX",
58+
"last_name": "Fix"
59+
}
60+
},
61+
"shipping": {
62+
"address": {
63+
"line1": "1467",
64+
"line2": "Harrison Street",
65+
"line3": "Harrison Street",
66+
"city": "San Fransico",
67+
"state": "California",
68+
"zip": "94122",
69+
"country": "US",
70+
"first_name": "PiX",
71+
"last_name": "Fix"
72+
}
73+
},
74+
"statement_descriptor_name": "joseph",
75+
"statement_descriptor_suffix": "JS",
76+
"metadata": {
77+
"udf1": "value1",
78+
"new_customer": "true",
79+
"login_date": "2019-09-10T10:11:12Z"
80+
}
81+
}
82+
},
83+
"url": {
84+
"raw": "{{baseUrl}}/payments",
85+
"host": ["{{baseUrl}}"],
86+
"path": ["payments"]
87+
},
88+
"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"
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"eventOrder": ["event.test.js"]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Validate status 2xx
2+
pm.test("[GET]::/payments/:id - Status code is 2xx", function () {
3+
pm.response.to.be.success;
4+
});
5+
6+
// Validate if response header has matching content-type
7+
pm.test("[GET]::/payments/:id - Content-Type is application/json", function () {
8+
pm.expect(pm.response.headers.get("Content-Type")).to.include(
9+
"application/json",
10+
);
11+
});
12+
13+
// Validate if response has JSON Body
14+
pm.test("[GET]::/payments/:id - Response has JSON Body", function () {
15+
pm.response.to.have.jsonBody();
16+
});
17+
18+
// Set response object as internal variable
19+
let jsonData = {};
20+
try {
21+
jsonData = pm.response.json();
22+
} catch (e) {}
23+
24+
// pm.collectionVariables - Set payment_id as variable for jsonData.payment_id
25+
if (jsonData?.payment_id) {
26+
pm.collectionVariables.set("payment_id", jsonData.payment_id);
27+
console.log(
28+
"- use {{payment_id}} as collection variable for value",
29+
jsonData.payment_id,
30+
);
31+
} else {
32+
console.log(
33+
"INFO - Unable to assign variable {{payment_id}}, as jsonData.payment_id is undefined.",
34+
);
35+
}
36+
37+
// pm.collectionVariables - Set mandate_id as variable for jsonData.mandate_id
38+
if (jsonData?.mandate_id) {
39+
pm.collectionVariables.set("mandate_id", jsonData.mandate_id);
40+
console.log(
41+
"- use {{mandate_id}} as collection variable for value",
42+
jsonData.mandate_id,
43+
);
44+
} else {
45+
console.log(
46+
"INFO - Unable to assign variable {{mandate_id}}, as jsonData.mandate_id is undefined.",
47+
);
48+
}
49+
50+
// pm.collectionVariables - Set client_secret as variable for jsonData.client_secret
51+
if (jsonData?.client_secret) {
52+
pm.collectionVariables.set("client_secret", jsonData.client_secret);
53+
console.log(
54+
"- use {{client_secret}} as collection variable for value",
55+
jsonData.client_secret,
56+
);
57+
} else {
58+
console.log(
59+
"INFO - Unable to assign variable {{client_secret}}, as jsonData.client_secret is undefined.",
60+
);
61+
}
62+
63+
// Response body should have value "processing" for "status"
64+
if (jsonData?.status) {
65+
pm.test(
66+
"[POST]::/payments/:id - Content check if value for 'status' matches 'succeeded'",
67+
function () {
68+
pm.expect(jsonData.status).to.eql("succeeded");
69+
},
70+
);
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"method": "GET",
3+
"header": [
4+
{
5+
"key": "Accept",
6+
"value": "application/json"
7+
}
8+
],
9+
"url": {
10+
"raw": "{{baseUrl}}/payments/:id?force_sync=true",
11+
"host": ["{{baseUrl}}"],
12+
"path": ["payments", ":id"],
13+
"query": [
14+
{
15+
"key": "force_sync",
16+
"value": "true"
17+
}
18+
],
19+
"variable": [
20+
{
21+
"key": "id",
22+
"value": "{{payment_id}}",
23+
"description": "(Required) unique payment id"
24+
}
25+
]
26+
},
27+
"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"
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)