---
description: >-
  This page describes how payments are made for purchasing membership plan  in
  the Bolbhav App.
---

# User to Bolbhav

We are utilizing the PhonePe Payment Gateway to facilitate user payments for the Bolbhav App directly from their accounts.

{% hint style="info" %}
For more information on how PhonePe is integrated into the Bolbhav app, visit the [PhonePe page](../../../chapter-10-saas-products/payment/phonepe) in Chapter 10 - SaaS Products
{% endhint %}

Membership Plan Purchase Page:

<figure><img src="https://3898150257-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrjNYs8KmxBlZvBKyEb2T%2Fuploads%2F8XdMCp2HIrKgpR4R897d%2FToken%20page.jpg?alt=media&#x26;token=89541675-5c7c-4b60-8f87-c374822e55d2" alt=""><figcaption><p>Membeship Plan Purchase Page</p></figcaption></figure>

### Payment scenarios

In the Bolbhav App, users can make payments to purchase Membership Plans. Each membership plan has associated tokens to grant. Once a membership plan is purchased, the corresponding tokens are added to the user wallet.\


Active Membership Plans:

1. **25-Day Plan**:
   * Price: Rs. 100
   * Benefits: Offers 400 Silver Tokens
   * Availability: Available for purchase directly from Bolbhav or listed users.
   * Purpose: Designed for users or farmers who frequently check prices during the harvesting season or prefer not to use tokens on a per-usage basis. This plan provides convenience by offering a bulk amount of tokens for a fixed price.
2.  **Yearly Plan**:

    * Price: Exclusively available for purchase from Bolbhav (currently priced at Rs 1460)
    * Validity: 365 days
    * Purpose: Tailored for traders or users who rely on the Bolbhav app for daily price viewing. This plan eliminates the hassle of frequent token purchases and daily token deductions, offering a seamless experience for users who need tokens for daily use.



## API endpoints used to initiate payments:

1. **Fetch PhonePe Payment Gateway Credentials**:\
   This API endpoint ([`{{base_url}}/get-payment-credentials`)](https://bold-moon-807876.postman.co/workspace/Bolbhav-Android-app~337874ea-5b97-4a7a-85db-3f89368f6cf4/request/27013507-8b10c88c-757e-4399-81cd-c133fb95d089?ctx=documentation) is utilized to retrieve payment credentials from the PhonePe payment gateway.
2. **Get Payment Payload for Plan Purchase**:\
   The API ([`{{base_url}}/get-payment-payload`](https://bold-moon-807876.postman.co/workspace/Bolbhav-Android-app~337874ea-5b97-4a7a-85db-3f89368f6cf4/request/27013507-158a893a-23ff-4ef5-bfea-426346ad6153?ctx=documentation)) is employed to obtain the payment payload for the plan to be purchased. This API returns the payment amount required for the specified plan.
3. **Check Payment Transaction Endpoint**:\
   The endpoint ([`{{base_url}}/payment-complete`)](https://bold-moon-807876.postman.co/workspace/Bolbhav-Android-app~337874ea-5b97-4a7a-85db-3f89368f6cf4/request/27013507-216fa85b-8d7b-4669-9995-09bf514d0580?ctx=documentation) serves the purpose of verifying payment transactions. It is used to ensure the completion and status of payment transactions.

These endpoints collectively facilitate the initiation, verification, and processing of payment transactions within the system.\


## &#x20;Payment Workflow for the Yearly Plan:

1. **User Selection**: The user selects the Yearly Plan option within the Bolbhav App.
2. **Redirect to Payment Gateway**: Upon selection, the user is automatically redirected to the PhonePe Pay Page Screen, where they can proceed with the payment process.
3. **Payment Options**: On the PhonePe Pay Page Screen, the user is presented with various payment options such as UPI Apps, Cards, and Net Banking.
4. **Payment Processing**: The user selects their preferred payment method and completes the payment transaction.
5. **Payment Confirmation**: Once the payment is successfully processed, the user receives a confirmation message or notification indicating the successful completion of the payment.
6. **Subscription Activation**: After successful payment, the Bolbhav App automatically extends the user's subscription validity by 365 days, thereby activating the Yearly Plan subscription.
7. **Access Granted**: The user now has full access to the features and benefits associated with the Yearly Plan for the next 365 days.

<figure><img src="https://3898150257-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrjNYs8KmxBlZvBKyEb2T%2Fuploads%2FuSFbuvk1eNAU5eHFqVi6%2FReceipt%20number%20(1).jpg?alt=media&#x26;token=3501537a-b063-4af3-8b0a-4f908c8fdee9" alt=""><figcaption><p>Yearly Plan Purchase Success </p></figcaption></figure>

8. **Validity Date :** User can verify the plan validity date in the profile screen

Note: For Yearly plan purchases, transactions are not processed through user wallets. Instead, users can review their payment history on the Payment Passbook page.

Endpoint Triggered: [`{{base-url}}/payment-passbook`](https://bold-moon-807876.postman.co/workspace/Bolbhav-Android-app~337874ea-5b97-4a7a-85db-3f89368f6cf4/request/32452504-8d04ef6a-9641-4491-9da0-21d8e4eba9da?ctx=documentation)

Purpose of this API: This API retrieves all payment transactions completed by the user, providing comprehensive visibility into their financial activity

## Payment Workflow for the Rs. 100 Membership Plan purchase:

1. **Plan Selection**: Within the Membership Plan purchase screen, users have the option to choose between the Rs. 100 or Rs. 1460 plan.
2. **User's Choice**: Upon selecting the Rs. 100 plan, users are prompted to choose whether to purchase from a listed user or directly from Bolbhav.
3. **Payment Gateway Integration**: Upon selection of the preferred purchase option, users are directed to the PhonePe Pay Page Screen, where they can select their desired payment method, such as UPI or wallet apps.
4. **Transaction Logging**: Upon opening the Pay Page, a transaction entry is recorded in the Payment Transaction Table, capturing user ID details and transaction specifics.
5. **Payment Processing**: If the user successfully completes the payment, 400 silver tokens are credited to their account. In case of payment failure or pending status, the transaction details, including the reason for failure, are meticulously logged in the Payment Transaction Table. Silver tokens are not granted in these cases.
6. **Pending Payment Handling**: In the event of pending status, a cron job continuously monitors payment statuses. Once payment is received or marked as complete, the user is granted the corresponding silver tokens.
7. **Listing Users' Participation**: The inclusion of listed users in the subscription plan screen facilitates transactions within the user community. When a buyer purchases from a listed user, the payment initially goes to Bolbhav's account. After successful payment received, the seller user receives the plan amount via the RazorPayX Gateway, user receives payment from Bolbhav.

<figure><img src="https://3898150257-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrjNYs8KmxBlZvBKyEb2T%2Fuploads%2FZI9jRpsygk6kS9j0Ndii%2FBuy%20Subscription.jpg?alt=media&#x26;token=e7cad525-55b4-4006-bd9f-5a446929af42" alt=""><figcaption><p>Confirmation of Payment</p></figcaption></figure>

<figure><img src="https://3898150257-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrjNYs8KmxBlZvBKyEb2T%2Fuploads%2F2zPqnvtVVae2nC3KUeVR%2FReceipt%20number.jpg?alt=media&#x26;token=8ee57e2a-4127-4a33-a13c-8a4ca0b53e4e" alt=""><figcaption><p>Payment Success Page</p></figcaption></figure>

### Logic to calculate users from which a buyer can purchase tokens

To determine eligible users from whom a buyer can purchase tokens, the following criteria are considered:

1. **Silver Token Balance**: Only users with 1000 or more silver tokens are displayed.
2. **Profile Completion**: Users must have completed their profile details, including name, address, profile image, and account information.
3. **Consent for Selling Tokens**: Users who meet the above criteria can enable consent for selling silver tokens from the Silver Token Passbook screen.

\
Users meeting these criteria are showcased, ensuring transparency and facilitating token transactions within the community.

**Criteria for displaying users to the buyers for  purchasing silver tokens**

1. The highest contributor in the mandi, viewed  by the buyer in  descending order from the most viewed mandi to the least viewed mandi&#x20;

### Database transactions between a buyer and Bolbhav

1. When a buyer selects a membership plan and initiates a payment transaction, Bolbhav records the transaction details in the payment\_transaction table within its database.
2. The payment\_transaction table maintains a comprehensive record of all payment transactions between buyers and Bolbhav.
3. Users can access their payment transaction history via the "My Payments" screen.
4. The transaction history provides users with a detailed overview of past transactions, including:
   * Transaction Date: The date and time when the transaction occurred.
   * Amount: The monetary value associated with the transaction.
   * Payment Status: Indicates whether the payment was successful, pending, or failed.
5. Bolbhav promotes transparency and accountability by providing users with access to their transaction history.This access empowers users to effortlessly monitor their payment activities.
6. Users can stay updated on the status of their transactions through this feature.
7.  For the Rs. 100 plan, upon successful payment, an entry is logged in the wallet ledger, specifically against the user's membership wallet, which is their silver token wallet. Here's how the entry is recorded in the wallet\_ledgers table:

    * **Source Wallet ID**: The Buyer membership wallet ID is designated as the source.
    * **Target Wallet ID**: The bank's membership wallet ID serves as the target.
    * **Amount**: The amount credited to the membership wallet corresponds to the credit associated with the membership plan. For Rs. 100, the credit amount is 400 tokens.
    * **Reason**: The reason field indicates the purpose of the transaction, specifying the membership plan purchased with money. This could be formatted as `{membership_plan_id} purchased by money` (e.g., new\_unique\_days\_100 purchased by money).
    * **Ref ID**: A unique identifier is generated to reference the payment transaction, typically in the format of `payment_transaction_id_{payment_transaction.id}` (e.g., payment\_transaction\_id\_198).


8. When a user purchases a plan from another Bolbhav user through successful payment, the transaction involves debiting tokens from the seller user's membership wallet and crediting them to the buyer user's membership wallet. Simultaneously, the payout amount equivalent to the membership plan purchased is credited to the seller user's account and payback wallet briefly described  in this [page](broken-reference)

It's important to note that for the Yearly Membership plan, no wallet ledger entries are made, as this plan does not involve credit transactions with tokens.

#### To do:

1. Details about the different transaction status for yearly plan purchase show in **Meri Payment** section
2. Pop up box displayed (screen shot and description) when yearly plan purchase transaction failure occurs&#x20;
3. Need to add scenario where silver tokens are reduced from the user account, but money is not received in his account, then silver tokens are reverted back to his wallet
4. Pop up box displayed (screen shot and description) when failure occurs in purchasing silver token from the user







