Skip to content

Commit

Permalink
docs(payment-service): updated readme
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Added mandatory authentication and authorization checks to API endpoints.

GH-2138
  • Loading branch information
Surbhi-sharma1 committed Jul 31, 2024
1 parent 0e79739 commit bc7831b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 34 deletions.
8 changes: 8 additions & 0 deletions services/payment-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ copy the credentials to the sandbox account and use them to develop payment-serv

Order creation , capture and refund is supported right now.

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.

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.

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.

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.

#### API Details

##### POST /payment-gateways
Expand Down
20 changes: 9 additions & 11 deletions services/payment-service/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"content": {
"application/json": {
"schema": {
"type": "object"
"$ref": "#/components/schemas/NewSubscriptions"
}
}
}
Expand Down Expand Up @@ -749,7 +749,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewMessage"
"$ref": "#/components/schemas/NewOrder"
}
}
}
Expand Down Expand Up @@ -1585,6 +1585,7 @@
}
}
},
"description": "\n\n| Permissions |\n| ------- |\n| CreateRefund |\n| CreateRefundNum |\n",
"parameters": [
{
"name": "id",
Expand Down Expand Up @@ -1618,6 +1619,7 @@
}
}
},
"description": "\n\n| Permissions |\n| ------- |\n| CreateRefund |\n| CreateRefundNum |\n",
"parameters": [
{
"name": "id",
Expand Down Expand Up @@ -2278,10 +2280,10 @@
"additionalProperties": false,
"x-typescript-type": "Partial<Transactions>"
},
"NewMessage": {
"title": "NewMessage",
"NewOrder": {
"title": "NewOrder",
"type": "object",
"description": "(tsType: Omit<Orders, 'id'>, schemaOptions: { title: 'NewMessage', exclude: [ 'id' ] })",
"description": "(tsType: Omit<Orders, 'id'>, schemaOptions: { title: 'NewOrder', exclude: [ 'id' ] })",
"properties": {
"totalAmount": {
"type": "number"
Expand Down Expand Up @@ -2576,11 +2578,8 @@
"NewSubscriptions": {
"title": "NewSubscriptions",
"type": "object",
"description": "(tsType: Subscriptions, schemaOptions: { title: 'NewSubscriptions' })",
"description": "(tsType: Omit<Subscriptions, 'id'>, schemaOptions: { title: 'NewSubscriptions', exclude: [ 'id' ] })",
"properties": {
"id": {
"type": "string"
},
"totalAmount": {
"type": "number"
},
Expand Down Expand Up @@ -2615,12 +2614,11 @@
}
},
"required": [
"id",
"totalAmount",
"status"
],
"additionalProperties": false,
"x-typescript-type": "Subscriptions"
"x-typescript-type": "Omit<Subscriptions, 'id'>"
},
"SubscriptionsWithRelations": {
"title": "SubscriptionsWithRelations",
Expand Down
70 changes: 54 additions & 16 deletions services/payment-service/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ Base URLs:
> Code samples
```javascript
const inputBody = '{}';
const inputBody = '{
"totalAmount": 0,
"currency": "string",
"status": "string",
"paymentGatewayId": "string",
"paymentMethod": "string",
"metaData": {},
"startDate": "2019-08-24T14:15:22Z",
"endDate": "2019-08-24T14:15:22Z",
"gatewaySubscriptionId": "string",
"planId": "string"
}';
const headers = {
'Content-Type':'application/json',
'Accept':'text/html'
Expand All @@ -57,7 +68,18 @@ fetch('/create-subscription-and-pay',

```javascript--nodejs
const fetch = require('node-fetch');
const inputBody = {};
const inputBody = {
"totalAmount": 0,
"currency": "string",
"status": "string",
"paymentGatewayId": "string",
"paymentMethod": "string",
"metaData": {},
"startDate": "2019-08-24T14:15:22Z",
"endDate": "2019-08-24T14:15:22Z",
"gatewaySubscriptionId": "string",
"planId": "string"
};
const headers = {
'Content-Type':'application/json',
'Accept':'text/html'
Expand Down Expand Up @@ -87,14 +109,25 @@ fetch('/create-subscription-and-pay',
> Body parameter
```json
{}
{
"totalAmount": 0,
"currency": "string",
"status": "string",
"paymentGatewayId": "string",
"paymentMethod": "string",
"metaData": {},
"startDate": "2019-08-24T14:15:22Z",
"endDate": "2019-08-24T14:15:22Z",
"gatewaySubscriptionId": "string",
"planId": "string"
}
```

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

|Name|In|Type|Required|Description|
|---|---|---|---|---|
|body|body|object|false|none|
|body|body|[NewSubscriptions](#schemanewsubscriptions)|false|none|

> Example responses
Expand Down Expand Up @@ -1860,7 +1893,7 @@ fetch('/place-order-and-pay',

|Name|In|Type|Required|Description|
|---|---|---|---|---|
|body|body|[NewMessage](#schemanewmessage)|false|none|
|body|body|[NewOrder](#schemaneworder)|false|none|

> Example responses
Expand Down Expand Up @@ -2172,6 +2205,11 @@ fetch('/transactions/refund/parse/{id}',

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

| Permissions |
| ------- |
| CreateRefund |
| CreateRefundNum |

<h3 id="transactionscontroller.transactionsrefundparse-parameters">Parameters</h3>

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

`POST /transactions/refund/{id}`

| Permissions |
| ------- |
| CreateRefund |
| CreateRefundNum |

<h3 id="transactionscontroller.transactionsrefund-parameters">Parameters</h3>

|Name|In|Type|Required|Description|
Expand Down Expand Up @@ -3519,7 +3562,6 @@ None
```javascript
const inputBody = '{
"id": "string",
"totalAmount": 0,
"currency": "string",
"status": "string",
Expand Down Expand Up @@ -3553,7 +3595,6 @@ fetch('/subscriptions',
```javascript--nodejs
const fetch = require('node-fetch');
const inputBody = {
"id": "string",
"totalAmount": 0,
"currency": "string",
"status": "string",
Expand Down Expand Up @@ -3595,7 +3636,6 @@ fetch('/subscriptions',
```json
{
"id": "string",
"totalAmount": 0,
"currency": "string",
"status": "string",
Expand Down Expand Up @@ -4992,12 +5032,12 @@ TransactionsPartial
|orderId|string|false|none|none|
|res|object|false|none|none|

<h2 id="tocS_NewMessage">NewMessage</h2>
<h2 id="tocS_NewOrder">NewOrder</h2>
<!-- backwards compatibility -->
<a id="schemanewmessage"></a>
<a id="schema_NewMessage"></a>
<a id="tocSnewmessage"></a>
<a id="tocsnewmessage"></a>
<a id="schemaneworder"></a>
<a id="schema_NewOrder"></a>
<a id="tocSneworder"></a>
<a id="tocsneworder"></a>

```json
{
Expand All @@ -5011,7 +5051,7 @@ TransactionsPartial

```

NewMessage
NewOrder

### Properties

Expand Down Expand Up @@ -5307,7 +5347,6 @@ Subscriptions

```json
{
"id": "string",
"totalAmount": 0,
"currency": "string",
"status": "string",
Expand All @@ -5328,7 +5367,6 @@ NewSubscriptions

|Name|Type|Required|Restrictions|Description|
|---|---|---|---|---|
|id|string|true|none|none|
|totalAmount|number|true|none|none|
|currency|string|false|none|none|
|status|string|true|none|none|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Request,
Response,
RestBindings,
getModelSchemaRef,
post,
requestBody,
} from '@loopback/rest';
Expand Down Expand Up @@ -59,9 +60,10 @@ export class SubscriptionTransactionsController {
@requestBody({
content: {
[CONTENT_TYPE.JSON]: {
schema: {
type: 'object',
},
schema: getModelSchemaRef(Subscriptions, {
title: 'NewSubscriptions',
exclude: ['id'],
}),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export class TransactionsController {
content: {
[CONTENT_TYPE.JSON]: {
schema: getModelSchemaRef(Orders, {
title: 'NewMessage',
title: 'NewOrder',
exclude: ['id'],
}),
},
Expand Down Expand Up @@ -491,7 +491,10 @@ export class TransactionsController {
);
}
}

@authenticate(STRATEGY.BEARER)
@authorize({
permissions: [PermissionKey.CreateRefund, PermissionKey.CreateRefundNum],
})
@post(`/transactions/refund/{id}`, {
security: OPERATION_SECURITY_SPEC,
responses: {
Expand Down Expand Up @@ -537,7 +540,10 @@ export class TransactionsController {
return 'Transaction does not exist';
}
}

@authenticate(STRATEGY.BEARER)
@authorize({
permissions: [PermissionKey.CreateRefund, PermissionKey.CreateRefundNum],
})
@get(`/transactions/refund/parse/{id}`, {
security: OPERATION_SECURITY_SPEC,
responses: {
Expand Down
3 changes: 2 additions & 1 deletion services/payment-service/src/enums/permission-key.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const enum PermissionKey {
ViewTransaction = 'ViewTransaction',
UpdateTransaction = 'UpdateTransaction',
DeleteTransaction = 'DeleteTransaction',

CreateRefund = 'CreateRefund',
GetSubscriptionCountNum = '1',
CreateSubscriptionNum = '2',
GetSubscriptionsNum = '3',
Expand All @@ -46,4 +46,5 @@ export const enum PermissionKey {
ViewTransactionNum = '19',
UpdateTransactionNum = '20',
DeleteTransactionNum = '21',
CreateRefundNum = 'CreateRefundNum',
}

0 comments on commit bc7831b

Please sign in to comment.