Skip to content

Commit bc7831b

Browse files
docs(payment-service): updated readme
BREAKING CHANGE: Added mandatory authentication and authorization checks to API endpoints. GH-2138
1 parent 0e79739 commit bc7831b

File tree

6 files changed

+87
-34
lines changed

6 files changed

+87
-34
lines changed

services/payment-service/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ copy the credentials to the sandbox account and use them to develop payment-serv
213213

214214
Order creation , capture and refund is supported right now.
215215

216+
The **`place-order-and-pay`** API endpoint allows creating a new order and initiate payment through PayPal. When a request is made, it first creates an order with the given details and saves it to the database.
217+
218+
The create method in it handles the payment process by checking if a payment transaction already exists for the order. If not, it creates a new PayPal order and retrieves a payment link, which is then returned along with the order ID.
219+
220+
The redirect url redirect users to the PayPal checkout page where they can review and complete their payment for a transaction associated with the provided orderId and receive a token or approval link in the response redirecting users to either the `SUCCESS_CALLBACK_URL` for successful payments with token and payerID or the `FAILURE_CALLBACK_URL` for canceled or failed transactions provided in env file.
221+
222+
The **`transactionscharge`** API endpoint processes a payment charge and redirects the user based on the result.Upon receiving a successful response, it updates the order and transaction records to reflect the payment status.
223+
216224
#### API Details
217225

218226
##### POST /payment-gateways

services/payment-service/openapi.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"content": {
3535
"application/json": {
3636
"schema": {
37-
"type": "object"
37+
"$ref": "#/components/schemas/NewSubscriptions"
3838
}
3939
}
4040
}
@@ -749,7 +749,7 @@
749749
"content": {
750750
"application/json": {
751751
"schema": {
752-
"$ref": "#/components/schemas/NewMessage"
752+
"$ref": "#/components/schemas/NewOrder"
753753
}
754754
}
755755
}
@@ -1585,6 +1585,7 @@
15851585
}
15861586
}
15871587
},
1588+
"description": "\n\n| Permissions |\n| ------- |\n| CreateRefund |\n| CreateRefundNum |\n",
15881589
"parameters": [
15891590
{
15901591
"name": "id",
@@ -1618,6 +1619,7 @@
16181619
}
16191620
}
16201621
},
1622+
"description": "\n\n| Permissions |\n| ------- |\n| CreateRefund |\n| CreateRefundNum |\n",
16211623
"parameters": [
16221624
{
16231625
"name": "id",
@@ -2278,10 +2280,10 @@
22782280
"additionalProperties": false,
22792281
"x-typescript-type": "Partial<Transactions>"
22802282
},
2281-
"NewMessage": {
2282-
"title": "NewMessage",
2283+
"NewOrder": {
2284+
"title": "NewOrder",
22832285
"type": "object",
2284-
"description": "(tsType: Omit<Orders, 'id'>, schemaOptions: { title: 'NewMessage', exclude: [ 'id' ] })",
2286+
"description": "(tsType: Omit<Orders, 'id'>, schemaOptions: { title: 'NewOrder', exclude: [ 'id' ] })",
22852287
"properties": {
22862288
"totalAmount": {
22872289
"type": "number"
@@ -2576,11 +2578,8 @@
25762578
"NewSubscriptions": {
25772579
"title": "NewSubscriptions",
25782580
"type": "object",
2579-
"description": "(tsType: Subscriptions, schemaOptions: { title: 'NewSubscriptions' })",
2581+
"description": "(tsType: Omit<Subscriptions, 'id'>, schemaOptions: { title: 'NewSubscriptions', exclude: [ 'id' ] })",
25802582
"properties": {
2581-
"id": {
2582-
"type": "string"
2583-
},
25842583
"totalAmount": {
25852584
"type": "number"
25862585
},
@@ -2615,12 +2614,11 @@
26152614
}
26162615
},
26172616
"required": [
2618-
"id",
26192617
"totalAmount",
26202618
"status"
26212619
],
26222620
"additionalProperties": false,
2623-
"x-typescript-type": "Subscriptions"
2621+
"x-typescript-type": "Omit<Subscriptions, 'id'>"
26242622
},
26252623
"SubscriptionsWithRelations": {
26262624
"title": "SubscriptionsWithRelations",

services/payment-service/openapi.md

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,18 @@ Base URLs:
3535
> Code samples
3636
3737
```javascript
38-
const inputBody = '{}';
38+
const inputBody = '{
39+
"totalAmount": 0,
40+
"currency": "string",
41+
"status": "string",
42+
"paymentGatewayId": "string",
43+
"paymentMethod": "string",
44+
"metaData": {},
45+
"startDate": "2019-08-24T14:15:22Z",
46+
"endDate": "2019-08-24T14:15:22Z",
47+
"gatewaySubscriptionId": "string",
48+
"planId": "string"
49+
}';
3950
const headers = {
4051
'Content-Type':'application/json',
4152
'Accept':'text/html'
@@ -57,7 +68,18 @@ fetch('/create-subscription-and-pay',
5768

5869
```javascript--nodejs
5970
const fetch = require('node-fetch');
60-
const inputBody = {};
71+
const inputBody = {
72+
"totalAmount": 0,
73+
"currency": "string",
74+
"status": "string",
75+
"paymentGatewayId": "string",
76+
"paymentMethod": "string",
77+
"metaData": {},
78+
"startDate": "2019-08-24T14:15:22Z",
79+
"endDate": "2019-08-24T14:15:22Z",
80+
"gatewaySubscriptionId": "string",
81+
"planId": "string"
82+
};
6183
const headers = {
6284
'Content-Type':'application/json',
6385
'Accept':'text/html'
@@ -87,14 +109,25 @@ fetch('/create-subscription-and-pay',
87109
> Body parameter
88110
89111
```json
90-
{}
112+
{
113+
"totalAmount": 0,
114+
"currency": "string",
115+
"status": "string",
116+
"paymentGatewayId": "string",
117+
"paymentMethod": "string",
118+
"metaData": {},
119+
"startDate": "2019-08-24T14:15:22Z",
120+
"endDate": "2019-08-24T14:15:22Z",
121+
"gatewaySubscriptionId": "string",
122+
"planId": "string"
123+
}
91124
```
92125

93126
<h3 id="subscriptiontransactionscontroller.subscriptionandtransactionscreate-parameters">Parameters</h3>
94127

95128
|Name|In|Type|Required|Description|
96129
|---|---|---|---|---|
97-
|body|body|object|false|none|
130+
|body|body|[NewSubscriptions](#schemanewsubscriptions)|false|none|
98131

99132
> Example responses
100133
@@ -1860,7 +1893,7 @@ fetch('/place-order-and-pay',
18601893

18611894
|Name|In|Type|Required|Description|
18621895
|---|---|---|---|---|
1863-
|body|body|[NewMessage](#schemanewmessage)|false|none|
1896+
|body|body|[NewOrder](#schemaneworder)|false|none|
18641897

18651898
> Example responses
18661899
@@ -2172,6 +2205,11 @@ fetch('/transactions/refund/parse/{id}',
21722205

21732206
`GET /transactions/refund/parse/{id}`
21742207

2208+
| Permissions |
2209+
| ------- |
2210+
| CreateRefund |
2211+
| CreateRefundNum |
2212+
21752213
<h3 id="transactionscontroller.transactionsrefundparse-parameters">Parameters</h3>
21762214

21772215
|Name|In|Type|Required|Description|
@@ -2242,6 +2280,11 @@ fetch('/transactions/refund/{id}',
22422280

22432281
`POST /transactions/refund/{id}`
22442282

2283+
| Permissions |
2284+
| ------- |
2285+
| CreateRefund |
2286+
| CreateRefundNum |
2287+
22452288
<h3 id="transactionscontroller.transactionsrefund-parameters">Parameters</h3>
22462289

22472290
|Name|In|Type|Required|Description|
@@ -3519,7 +3562,6 @@ None
35193562
35203563
```javascript
35213564
const inputBody = '{
3522-
"id": "string",
35233565
"totalAmount": 0,
35243566
"currency": "string",
35253567
"status": "string",
@@ -3553,7 +3595,6 @@ fetch('/subscriptions',
35533595
```javascript--nodejs
35543596
const fetch = require('node-fetch');
35553597
const inputBody = {
3556-
"id": "string",
35573598
"totalAmount": 0,
35583599
"currency": "string",
35593600
"status": "string",
@@ -3595,7 +3636,6 @@ fetch('/subscriptions',
35953636
35963637
```json
35973638
{
3598-
"id": "string",
35993639
"totalAmount": 0,
36003640
"currency": "string",
36013641
"status": "string",
@@ -4992,12 +5032,12 @@ TransactionsPartial
49925032
|orderId|string|false|none|none|
49935033
|res|object|false|none|none|
49945034

4995-
<h2 id="tocS_NewMessage">NewMessage</h2>
5035+
<h2 id="tocS_NewOrder">NewOrder</h2>
49965036
<!-- backwards compatibility -->
4997-
<a id="schemanewmessage"></a>
4998-
<a id="schema_NewMessage"></a>
4999-
<a id="tocSnewmessage"></a>
5000-
<a id="tocsnewmessage"></a>
5037+
<a id="schemaneworder"></a>
5038+
<a id="schema_NewOrder"></a>
5039+
<a id="tocSneworder"></a>
5040+
<a id="tocsneworder"></a>
50015041

50025042
```json
50035043
{
@@ -5011,7 +5051,7 @@ TransactionsPartial
50115051

50125052
```
50135053

5014-
NewMessage
5054+
NewOrder
50155055

50165056
### Properties
50175057

@@ -5307,7 +5347,6 @@ Subscriptions
53075347

53085348
```json
53095349
{
5310-
"id": "string",
53115350
"totalAmount": 0,
53125351
"currency": "string",
53135352
"status": "string",
@@ -5328,7 +5367,6 @@ NewSubscriptions
53285367

53295368
|Name|Type|Required|Restrictions|Description|
53305369
|---|---|---|---|---|
5331-
|id|string|true|none|none|
53325370
|totalAmount|number|true|none|none|
53335371
|currency|string|false|none|none|
53345372
|status|string|true|none|none|

services/payment-service/src/controllers/subscriptions-transactions.controller.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Request,
99
Response,
1010
RestBindings,
11+
getModelSchemaRef,
1112
post,
1213
requestBody,
1314
} from '@loopback/rest';
@@ -59,9 +60,10 @@ export class SubscriptionTransactionsController {
5960
@requestBody({
6061
content: {
6162
[CONTENT_TYPE.JSON]: {
62-
schema: {
63-
type: 'object',
64-
},
63+
schema: getModelSchemaRef(Subscriptions, {
64+
title: 'NewSubscriptions',
65+
exclude: ['id'],
66+
}),
6567
},
6668
},
6769
})

services/payment-service/src/controllers/transactions.controller.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export class TransactionsController {
369369
content: {
370370
[CONTENT_TYPE.JSON]: {
371371
schema: getModelSchemaRef(Orders, {
372-
title: 'NewMessage',
372+
title: 'NewOrder',
373373
exclude: ['id'],
374374
}),
375375
},
@@ -491,7 +491,10 @@ export class TransactionsController {
491491
);
492492
}
493493
}
494-
494+
@authenticate(STRATEGY.BEARER)
495+
@authorize({
496+
permissions: [PermissionKey.CreateRefund, PermissionKey.CreateRefundNum],
497+
})
495498
@post(`/transactions/refund/{id}`, {
496499
security: OPERATION_SECURITY_SPEC,
497500
responses: {
@@ -537,7 +540,10 @@ export class TransactionsController {
537540
return 'Transaction does not exist';
538541
}
539542
}
540-
543+
@authenticate(STRATEGY.BEARER)
544+
@authorize({
545+
permissions: [PermissionKey.CreateRefund, PermissionKey.CreateRefundNum],
546+
})
541547
@get(`/transactions/refund/parse/{id}`, {
542548
security: OPERATION_SECURITY_SPEC,
543549
responses: {

services/payment-service/src/enums/permission-key.enum.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const enum PermissionKey {
2424
ViewTransaction = 'ViewTransaction',
2525
UpdateTransaction = 'UpdateTransaction',
2626
DeleteTransaction = 'DeleteTransaction',
27-
27+
CreateRefund = 'CreateRefund',
2828
GetSubscriptionCountNum = '1',
2929
CreateSubscriptionNum = '2',
3030
GetSubscriptionsNum = '3',
@@ -46,4 +46,5 @@ export const enum PermissionKey {
4646
ViewTransactionNum = '19',
4747
UpdateTransactionNum = '20',
4848
DeleteTransactionNum = '21',
49+
CreateRefundNum = 'CreateRefundNum',
4950
}

0 commit comments

Comments
 (0)