How to Build a Reliable Payment Service for Your Online Business

Roman Glushach
7 min readMay 22, 2023

--

If you run an online business, you know how important it is to have a reliable payment service that can handle your transactions smoothly and securely. You want to make sure that your customers can pay for your products or services easily and quickly, and that you can receive your money without any hassle or delay.

The Components of a Payment Service

Payment system

Payment event

This is the trigger that initiates a payment process. When a user clicks the “Buy” button on the marketplace website, a payment event is generated and sent to the payment service.

Payment service

This is the core component that orchestrates the payment process. It receives the payment event and stores it in the database. It also validates the payment details, such as the amount, currency, and payment method. It then splits the payment event into one or more payment orders, depending on how many sellers are involved in the transaction.

Payment order

This is a sub-unit of a payment event that represents a single payment transaction between a buyer and a seller. For example, if a user buys products from three different sellers in one checkout process, the payment service will create three payment orders for each seller. Each payment order has its own status, such as pending, processing, completed, failed, or refunded.

Payment executor

This is the component that executes the payment order by calling an external payment service provider (PSP) to finish the credit card payment. It also stores the payment order in the database and updates its status according to the response from the PSP.

Payment service provider (PSP)

This is an external service that handles the actual credit card processing and transfers money from the buyer’s account to the seller’s account. The PSP also provides information about the transaction status, such as success, failure, or error.

Wallet

This is the component that keeps track of how much money each seller has in their account on the marketplace platform. After the payment executor has successfully executed the payment order, the payment service will update the wallet to record how much money the seller has earned from the sale.

Ledger

This is the component that records all the financial transactions that take place on the marketplace platform. It provides an audit trail of all the payments, refunds, fees, commissions, and taxes that are involved in each transaction. The ledger also helps with reporting and reconciliation purposes.

Settlement file

This is a file that contains information about all the transactions that took place on a given bank account during a day. The PSP or banks send settlement files to their clients every night to inform them about their balance and activity.

The Process of a Payment Service

  1. When a user clicks the “Buy” button on the marketplace website, a payment event is generated and sent to the payment service.
  2. The payment service stores the payment event in the database.
  3. The payment service validates the payment details and splits the payment event into one or more payment orders depending on how many sellers are involved in the transaction.
  4. The payment service sends each payment order to the corresponding payment executor.
  5. The payment executor stores the payment order in the database and calls an external PSP to finish the credit card payment.
  6. The PSP processes the credit card transaction and returns the transaction status to the payment executor.
  7. The payment executor updates the status of the payment order in the database according to the response from the PSP.
  8. The payment executor notifies the payment service about the outcome of the payment order.
  9. The payment service updates the status of the payment event in the database based on the status of all the related payment orders.
  10. If all the related payment orders are completed successfully, the payment service updates the wallet to record how much money each seller has earned from the sale.
  11. The wallet stores the updated balance information in the database.
  12. The wallet notifies the ledger about the updated balance information for each seller.
  13. The ledger appends the new ledger information to the database.
  14. Every night, the PSP or banks send settlement files to their clients, including the marketplace platform, to inform them about their balance and activity.

Payment Reconciliation

Payment reconciliation is a crucial process that verifies every set of records, from bank statements to balance sheets, is correct and up-to-date. It ensures that your internal records match any statements you get from vendors, and it is essential to keep track of the precise state of your company’s accounts.

Best practices

Automate the Process

Payment reconciliation can be a long, multi-step process with many sub-steps that you may experience depending on whether your team handles the process manually or automatically. Automating the process can save time and reduce errors.

Keep Accurate Records

Keeping accurate records is essential for payment reconciliation. Ensure that all transactions are recorded accurately and in a timely manner. This will help you identify discrepancies quickly and resolve them before they become bigger problems.

Reconcile Regularly

Reconciling regularly is crucial to ensure that your records are up-to-date and accurate. It is recommended to reconcile daily or weekly, depending on the volume of transactions. This will help you identify discrepancies quickly and resolve them before they become bigger problems.

Foreign Currency Problem

When you operate a store globally, you will come across foreign currency transactions quite frequently. For example, if a transaction happens in a currency different from the standard currency of your payment provider, this will create another layer where the transaction is first received in that currency and exchanged to whatever currency your payment provider is using. This can lead to discrepancies and errors that need to be reconciled. To address this problem, consider using a payment provider that offers real-time automatic payment reconciliation. This will help ensure that all transactions are accurately recorded and reconciled in real-time.

Payment Providers are Only Intermediaries

Payment providers are intermediaries that facilitate transactions between buyers and sellers. However, each purchase does not trigger two events for a company, but actually at least 4.

The purchase via a payment provider (where both the time and the currency dimension can come into play) triggers the debit/credit pair for the transaction and then, usually a few days later, another pair when the money is transferred from the payment provider to a bank account (where there might be yet another FX discrepancy to reconcile if, for example, the initial purchase was in GRB, the payment provider is set up in USD, and your bank account is in EUR). To reconcile all of these transactions, it’s important to have a reliable way to track and match payment IDs across different systems. Ideally, your payment provider and your shop should have an integration/API with the tool you use to (hopefully automatically) create invoices. This usually carries over the order ID from the shop (closing the loop) and sometimes even the payment ID to match it with the invoice ID, which you then can use to reconcile it with your accounts receivable/payable.

Platform-Specific Problems

Some problems also pop up on the buyer side that is very platform-specific. One example is shadow transaction from Paypal: if you buy two items on Paypal with 1 week of time between the two transactions, Paypal will first debit money from your bank account for transaction A. If at the time of transaction B, transaction A has not gone through completely or is canceled, there might be a world where Paypal will use the money from transaction A to partially pay for transaction B, which leads to only a partial amount of transaction B being withdrawn from the bank account. To avoid this problem, it’s important to have a clear and transparent payment process that clearly outlines the steps involved and any potential issues that may arise.

Tips to mitigate payment reconciliation issues

Data Normalization

When comparing records in different systems, they come in different formats. For example, the timestamp can be “2023/01/01” in one system and “Jan 1, 2023” in another. This can cause discrepancies in your records. To solve this problem, you can add a layer to transform different formats into the same format. This process is called data normalization, and it ensures that all records are in the same format, making it easier to compare them.

Massive Data Volume

Processing massive data volumes can be time-consuming and slow down the reconciliation process. To speed up data comparisons, you can use big data processing techniques. If you need near real-time reconciliation, a streaming platform such as Flink is used; otherwise, end-of-day batch processing such as Hadoop is enough.

Cut-off Time Issue

Cut-off time issues can cause discrepancies in your records. For example, if you choose 00:00:00 as the daily cut-off time, one record is stamped with 23:59:55 in the internal system, but might be stamped 00:00:30 in the external system (Paypal), which is the next day. In this case, you couldn’t find this record in today’s Paypal records. It causes a discrepancy. To solve this problem, we need to categorize this break as a “temporary break” and run it later against the next day’s Paypal records. If we find a match in the next day’s Paypal records, the break is cleared, and no more action is needed.

Benefits of Building a Reliable Payment Service

  • improving customer satisfaction and loyalty by providing them with a fast and secure way to pay for your products or services
  • increasing sales and revenue by enabling customers to use different payment methods and currencies according to their preferences and needs
  • reducing operational costs and risks by automating and streamlining your payment processes and reducing manual errors and frauds
  • enhancing your reputation and credibility by complying with industry standards and regulations for online payments

Conclusion

Building a reliable payment service for your online business is not an easy task, but it is definitely worth it if you want to grow your online presence and revenue.

--

--

Roman Glushach
Roman Glushach

Written by Roman Glushach

Senior Software Architect & Engineer Manager at Freelance

No responses yet