---
# System prepended metadata

title: Credit management

---

# CREDIT MANAGEMENT

### Flow of payment

![](https://hackmd.io/_uploads/ryomXrCb6.png)

![](https://hackmd.io/_uploads/B1k9-e2ZT.png)

* buy credit
* redeem credit
* dashboard/view (user specific or whilter specific)
* management user (whilter will add money)
* Organisation contain multiple users

# Buy credit:
![](https://hackmd.io/_uploads/SkEjibaWa.png)

1. Integrate phonepe for make payment.

```
curl --request POST \
     --url https://mercury-uat.phonepe.com/enterprise-sandbox/v3/charge \
     --header 'Content-Type: application/json' \
     --header 'X-VERIFY: 2dbfabed915b9b9759bc10a3ce6ecfbeb0c1169d5eada325668fcf31be8d360e###1' \
     --header 'accept: application/json'
```
2. Check Status of payment.

```
curl --request GET \
     --url https://mercury-uat.phonepe.com/enterprise-sandbox/v3/transaction/MERCHANTUAT/TX123456789/status \
     --header 'X-VERIFY: 90443659f151a86831b7502c797c2ee4f3bcf63cbdad141c154effc2aad5c762###1' \
     --header 'accept: application/json'
```

3. Add data in db of **phonepeDataDb** transaction (**Fetch from phonepe**)
> * transaction_id
> * date
> * mobile_number
> * payment_status
> * amount

![](https://hackmd.io/_uploads/SyAJLEpbT.png)

4. If status of payment is success.
    4.1. Create **POST** api of credit amount in whilter wallet.
    4.2. Add the amount value as credit in whilter wallet.
    4.3. Create db of whilter wallet & **GET** api which gives the account details.
    > * id (automatically generated)
    > * date (from **phonepeDataDb** table)
    > * transaction_id (from **phonepeDataDb** table)
    > * mobile_number(from **phonepeDataDb** table)
    > * email_id(from **cognitoUserDb** table)
    > * total_amount(from **phonepeDataDb** table)

![](https://hackmd.io/_uploads/ByEySB6bT.png)

5. If status of payment is failed/pending/cancelled.
    5.1 Amount in wallet not changed.

# Redeem credit:

1. **POST** api for debit the amount & change the amount of available & used amount in db.
2. Fields for user wallet db
> * id
> * date
> * credit
> * debit
> * available_amount

![](https://hackmd.io/_uploads/rkpWrH6-p.png)


# Dashboard:

### 1. phonePeTransactionDetails (ADMIN)

1. transactionId
2. status
3. amount
4. mobileNumber
5. date
6. paymentMode

![](https://hackmd.io/_uploads/HyQGMe2Za.png)

### 2. userTransaction (WHILTER-USERS)
1. userEmail
2. mobileNumber
3. pointbalance
4. pointCredit
5. pointDebit
6. dateOfTransaction
7. transactionId