Direct API Integration Quick Start
This guide will help you integrate ProBuy payment solution directly into your application using our REST API. You'll implement a secure backend integration that protects your API credentials.
Security First
Important: Always use a backend server for API integration. Never expose your API token in frontend code or client-side JavaScript.
- โ Store API tokens securely on your server
- โ Make API calls from your backend only
- โ Use HTTPS for all communications
- โ Never put API tokens in browser code
Integration Architecture
Your website or app collects order data
Server makes secure API calls to ProBuy
Processes payment and handles checkout
Prerequisites
Before you begin, ensure you have:
- โ An approved ProBuy Supplier account
- โ Your API Token from the Supplier Portal
- โ A backend server (Node.js, PHP, Python, etc.)
- โ HTTPS-enabled website (required for production)
Need credentials? Follow our Getting Started Guide to create your account and obtain API credentials.
Quick Integration Steps
Complete Integration Flow
Set Up Your Backend Server
Create an endpoint on your server to handle checkout requests:
// Example: Node.js with Expressimport express from 'express';import axios from 'axios';
const app = express();app.use(express.json());
// Store your API token securelyconst PROBUY_API_TOKEN = process.env.PROBUY_API_TOKEN;const PROBUY_API_URL = 'https://api.probuy.me'; // Use 'https://sandboxapi.probuy.dev' for sandbox
// Your backend endpoint (not ProBuy's API)app.post('/api/checkout', async (req, res) => { try { // Prepare order data from your frontend const orderData = { order_reference_id: 'ref-' + Date.now(), order_number: req.body.orderNumber, currency: 'SAR', total_amount: req.body.totalAmount, tax_amount: req.body.taxAmount, consumer: req.body.consumer, country_code: 'SA', merchant_url: { success: 'https://yoursite.com/payment/success', failure: 'https://yoursite.com/payment/failure', cancel: 'https://yoursite.com/payment/cancel' }, billing_address: req.body.billingAddress, items: req.body.items };
// Call ProBuy API const response = await axios.post( `${PROBUY_API_URL}/api/checkouts/session`, orderData, { headers: { 'Authorization': `Bearer ${PROBUY_API_TOKEN}`, 'Content-Type': 'application/json' } } );
// Return checkout URL to frontend res.json({ success: true, checkoutUrl: response.data.checkout_url });
} catch (error) { console.error('Checkout error:', error); res.status(500).json({ success: false, error: 'Failed to create checkout session' }); }});
app.listen(3000, () => { console.log('Server running on port 3000');});Frontend: Collect Order Data
Collect order information from your customer:
<!-- Your checkout form --><form id="checkout-form"> <input type="text" id="firstName" placeholder="First Name" required> <input type="text" id="lastName" placeholder="Last Name" required> <input type="email" id="email" placeholder="Email" required> <input type="tel" id="phone" placeholder="Phone Number" required>
<!-- Billing Address --> <input type="text" id="address" placeholder="Address" required> <input type="text" id="city" placeholder="City" required>
<button type="submit">Proceed to Payment</button></form>
<script>document.getElementById('checkout-form').addEventListener('submit', async (e) => { e.preventDefault();
// Collect form data const orderData = { orderNumber: 'ORD-' + Date.now(), totalAmount: 1500.00, // Your cart total taxAmount: 225.00, consumer: { first_name: document.getElementById('firstName').value, last_name: document.getElementById('lastName').value, email: document.getElementById('email').value, phone_number: document.getElementById('phone').value }, billingAddress: { line1: document.getElementById('address').value, city: document.getElementById('city').value, country_code: 'SA' }, items: [ { name: 'Order Items', type: 'Physical', quantity: 1, unit_price: 1275, total_amount: 1500 } ] };
// Call YOUR backend (not ProBuy directly) const response = await fetch('/api/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(orderData) });
const result = await response.json();
if (result.success) { // Redirect to ProBuy checkout window.location.href = result.checkoutUrl; } else { alert('Payment initialization failed'); }});</script>Handle Return URLs
Create pages to handle payment results:
// success.html - Payment successfulconst urlParams = new URLSearchParams(window.location.search);const checkoutId = urlParams.get('checkout_id');const status = urlParams.get('status');
if (status === 'approved') { // Verify on backend and complete order fetch('/api/verify-payment', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ checkoutId }) }) .then(res => res.json()) .then(data => { if (data.verified) { showSuccessMessage('Payment completed successfully!'); clearCart(); } });}
// failure.html - Payment failedif (status === 'declined') { showErrorMessage('Payment was declined. Please try again.'); // Optionally show retry button}
// cancel.html - User cancelledif (status === 'cancelled') { showInfoMessage('Payment was cancelled. Your cart has been saved.'); // Redirect back to cart}Verify Payment Status
Always verify payment status on your backend:
// Backend endpoint to verify paymentapp.post('/api/verify-payment', async (req, res) => { const { checkoutId } = req.body;
try { // Get checkout details from ProBuy const response = await axios.get( `${PROBUY_API_URL}/api/checkouts/${checkoutId}`, { headers: { 'Authorization': `Bearer ${PROBUY_API_TOKEN}` } } );
const checkout = response.data;
if (checkout.status === 'approved') { // Payment successful - complete the order await completeOrder(checkout.order_reference_id);
res.json({ verified: true, orderNumber: checkout.order_number }); } else { res.json({ verified: false, status: checkout.status }); } } catch (error) { console.error('Verification error:', error); res.status(500).json({ error: 'Verification failed' }); }});API Endpoints Reference
| Endpoint | Method | Description |
|---|---|---|
/api/checkouts/session | POST | Create a new checkout session |
/api/checkouts/{checkoutId} | GET | Get checkout session details |
/api/orders/{orderId}/authorise | POST | Authorize an order for processing |
/api/checkouts/session/api/checkouts/{checkoutId}/api/orders/{orderId}/authoriseEnvironment URLs
| Environment | API Base URL | Company Portal |
|---|---|---|
| Sandbox | https://sandboxapi.probuy.dev | https://sandboxcompany.probuy.dev |
| Production | https://api.probuy.me | https://company.probuy.me |
https://sandboxapi.probuy.devhttps://sandboxcompany.probuy.devhttps://api.probuy.mehttps://company.probuy.meRequired Order Data Fields
{ // Required fields "order_reference_id": "ORD-2025-001", // Your unique order reference "order_number": "ORDER-12345", // Your order number "currency": "SAR", // Currency code "total_amount": 1500.00, // Total order amount "country_code": "SA", // ISO country code
// Consumer information (required) "consumer": { "first_name": "Ahmed", "last_name": "Mohammed", "phone_number": "+966501234567" // Include country code },
// Return URLs (required) "merchant_url": { "success": "https://yourstore.com/success", // Where to redirect on success "failure": "https://yourstore.com/failure", // Where to redirect on failure "cancel": "https://yourstore.com/cancel" // Where to redirect on cancel },
// Billing address (required) "billing_address": { "city": "Riyadh", "country_code": "SA", "first_name": "Ahmed", "last_name": "Mohammed", "line1": "123 King Fahd Road", "line2": "Apt 5", // Optional "phone_number": "+966501234567", "region": "As Sulimaniyah" // Optional },
// Items array - at least one item required "items": [ { "name": "Laptop - MacBook Pro 16", "type": "Physical", // "Physical" or "Digital" "quantity": 1, "unit_price": 1275.00, "total_amount": 1275.00, "reference_id": "PROD-001", // Your product ID (optional) "sku": "MBP-16-M3-MAX", // Product SKU (optional) "description": "M3 Max, 36GB RAM" // Optional } ],
// Optional fields "shipping_amount": 25.00, // Optional "tax_amount": 200.00, // Optional "discount": { // Optional "amount": 50.00, "name": "New Customer Discount" }, "shipping_address": { // Optional - same structure as billing_address "city": "Jeddah", "country_code": "SA", "first_name": "Ahmed", "last_name": "Mohammed", "line1": "456 Corniche Road", "phone_number": "+966501234567" }, "platform": "WooCommerce", // Your platform name (optional) "locale": "en_US" // e.g., 'en_US', 'ar_SA' (optional)}Payment Button Design
Before integrating the ProBuy API, you'll need to add a payment button to your checkout page. We've created comprehensive design guidelines to ensure brand consistency.
๐ ProBuy Payment Button Widget
Get official brand colors, ready-to-use code, and design guidelines for the ProBuy payment button.
View Button Widget Documentation โTesting Checklist
- Backend server is running and secure
- API token is stored in environment variables
- Checkout session creation works
- Customer can complete payment flow
- Success URL receives correct parameters
- Failure URL handles declined payments
- Cancel URL restores cart state
- Payment verification works correctly
- Orders appear in Supplier Portal
- Error handling is implemented
Pro Tips
- ๐ Always validate and sanitize input data
- ๐ Log all API requests and responses for debugging
- ๐ Implement retry logic for network failures
- โฑ๏ธ Set appropriate timeouts for API calls
- ๐พ Store checkout IDs for order tracking
- ๐ Monitor API response times and errors
Using the Backend SDK Instead
For easier integration with built-in security and error handling, consider using our official Backend SDK:
@probuy/backend-sdk - Official Node.js SDK for backend integration
npm install @probuy/backend-sdkNext Steps
๐ฆ Backend SDK
Simplify integration with our official Node.js SDK.
๐งช Testing Guide
Comprehensive testing strategies and go-live checklist.
Need Help?
We're here to assist with your integration:
- ๐ง Email: [email protected]
- ๐ Documentation: You're already here!
- ๐ฌ Support: Contact us through the Supplier Portal