PG Charge (API-only integration guide)
This guide is for payment gateways and merchants that want a direct API integration with Open Fabric (no Web SDK).
With the PG Charge flow:
- You create a transaction via the Open Fabric API.
- You redirect the customer to Open Fabric for approval.
- If approved, Open Fabric creates a one-time virtual card and charges it using your configured payment gateway credentials.
- Open Fabric redirects the customer back to you and sends you a notification.
Refunds are handled via your existing card/gateway refund flows (refund against the original card transaction).
Prerequisites
- Client ID / Client Secret for Open Fabric OAuth
- Your card processing gateway credentials configured with Open Fabric (so we can charge on your behalf)
- A place to receive webhook notifications
Flow and system interactions
Integration steps
| Step | Description |
|---|---|
| Step 1: Get an access token | Generate an OAuth access token on your backend and cache it. |
| Step 2: Create a Partner Transaction (PG Charge) | Create a transaction with pg_flow: "charge" and receive payment_redirect_web_url. |
| Step 3: Redirect customer for approval | Redirect the customer to payment_redirect_web_url for payment approval. |
| Step 4: Handle redirect back + notifications | Handle redirect back to your site and consume webhook notifications (recommended). |
Step 1: Get an access token
Your backend generates an access token using your Open Fabric credentials (client ID and client secret). The access token is needed to initialize the Merchant SDK.
See API reference in our API Reference for more details.
Recommended scopes:
resources/transactions.readresources/transactions.create
The access token is valid for a limited time. Cache and reuse it on your server to reduce latency and avoid unnecessary token requests.
Step 2: Create a Partner Transaction (PG Charge)
Create the transaction via Open Fabric:
See the Create Merchant Transaction API in our API Reference for more details.
Set:
pg_name: your card processing gateway (e.g.xendit)pg_flow:charge
{
"partner_reference_id": "P1293201980299030",
"partner_redirect_success_url": "https://merchant.example/success?state=PAID",
"partner_redirect_fail_url": "https://merchant.example/fail?state=CANCELLED",
"amount": 1200.1,
"currency": "PHP",
"pg_name": "xendit",
"pg_flow": "charge",
"customer_info": {
"first_name": "John",
"last_name": "Doe",
"mobile_number": "+6326418142",
"email": "jdoe@example.com"
},
"transaction_details": {
"items": [
{
"item_id": "P100",
"name": "iPhone",
"price": 1200.1,
"quantity": 1,
"variation_name": "Black, 128GB",
"categories": [ "Electronics" ]
}
]
}
}
The API responds with a payment_redirect_web_url that you redirect the customer to.
Step 3: Redirect customer to Open Fabric for approval
Redirect the customer to the payment_redirect_web_url returned in Step 2.
Step 4: Handle redirect back + notifications (required)
When Open Fabric approves the transaction and successfully charges using your gateway, the customer is redirected back to:
partner_redirect_success_urlon successpartner_redirect_fail_urlon failure
When using the PG Charge integration it is required to process the notification. In some scenarios a payment approval can be delayed, for instance when a Payment Method need to approve a loan towards the customer. Redirection back to your website can also fail for other reasons, for instance when the customer closed their browser or lost internet connectivity.
We will only send Transaction approved notifications when the charge has succeeded. The Transaction failed notifications may come in various scenarios, such as when the customer cancels, the Payment Method does not approve, or the charge has failed.
Additional use cases
Refunds
Issue refunds using your existing gateway/card processor refund flow (refund against the card transaction). You do not need to integrate separately with Open Fabric or the Payment Method to issue refunds. Refunds against virtual cards can be issued up to 180 days.
Get transaction status
Use our Get transaction status API to get the current transaction status.