Common Workflows
This section outlines several common workflows that developers might use when integrating with the UCanPay API. These workflows are designed to guide you through typical use cases, from simple payment processing to more complex transaction management.
Workflow 1: Processing a Payment
Processing a payment is a fundamental function of the UCanPay API. Here’s a step-by-step guide:
Create a Payment Order
Use the
POST /payment/unifiedorderendpoint to initiate a payment.Required details include the transaction amount, currency, and merchant identifier.
Customer Authorization
Redirect the customer to the payment gateway using the URL provided in the response of the Unified Order Placement.
The customer will authorize the payment and may need to enter payment details depending on the setup.
Payment Confirmation
After payment authorization, UCanPay will redirect back to your specified return URL.
A payment notification will be sent to your server's webhook endpoint.
Verify Payment Status
Call the
GET /payment/statusendpoint with the order ID to verify the payment status and ensure it was processed successfully.
Workflow 2: Refunding a Transaction
Refunding a transaction may be necessary due to customer returns or order cancellations.
Send a Refund Request
Use the
POST /payment/refundendpoint to initiate a refund.Include the original transaction ID and the amount to be refunded.
Check Refund Status
Use the
GET /payment/refund/statusendpoint to check the status of the refund.Ensure the refund has been processed successfully, or handle errors as needed.
Workflow 3: Recurring Payments
Setting up recurring payments can facilitate subscriptions and other regular transactions.
Create a Subscription
Use the
POST /subscriptions/createendpoint to set up a new subscription.Define the billing frequency, amount, start date, and customer details.
Handle Subscription Notifications
Implement webhook endpoints to receive notifications about subscription status updates, such as renewals or cancellations.
Manage Subscription
Use endpoints like
POST /subscriptions/cancelorPOST /subscriptions/updateto manage existing subscriptions based on user actions or business needs.
Workflow 4: Handling Errors
Proper error handling ensures a smoother experience for users and easier debugging for developers.
Understand Error Codes
Familiarize yourself with the common error codes that UCanPay API might return (detailed in the Error Handling section).
Implement Error Handling
In your API calls, implement error handling that catches and logs errors.
Provide meaningful error messages to users when something goes wrong.
Retry Mechanism
For recoverable errors, implement a retry mechanism that attempts the request again before failing.
By following these common workflows, developers can ensure they are using the UCanPay API effectively and handling different scenarios appropriately. For more detailed information on each endpoint mentioned in these workflows, refer to the API Endpoints section.