ProBuy Logo
PB

ProBuy Docs

Version 1.0

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.

Integration Architecture

1. Frontend

Your website or app collects order data

2. Your Backend

Server makes secure API calls to ProBuy

3. ProBuy API

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)

Quick Integration Steps

Complete Integration Flow

1

Set Up Your Backend Server

Create an endpoint on your server to handle checkout requests:

// Example: Node.js with Express
import express from 'express';
import axios from 'axios';
const app = express();
app.use(express.json());
// Store your API token securely
const 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');
});
2

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>
3

Handle Return URLs

Create pages to handle payment results:

// success.html - Payment successful
const 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 failed
if (status === 'declined') {
showErrorMessage('Payment was declined. Please try again.');
// Optionally show retry button
}
// cancel.html - User cancelled
if (status === 'cancelled') {
showInfoMessage('Payment was cancelled. Your cart has been saved.');
// Redirect back to cart
}
4

Verify Payment Status

Always verify payment status on your backend:

// Backend endpoint to verify payment
app.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
/api/checkouts/session
Method
POST
Description
Create a new checkout session
Endpoint
/api/checkouts/{checkoutId}
Method
GET
Description
Get checkout session details
Endpoint
/api/orders/{orderId}/authorise
Method
POST
Description
Authorize an order for processing

Environment URLs

Environment
Sandbox
API Base URL
https://sandboxapi.probuy.dev
Company Portal
https://sandboxcompany.probuy.dev
Environment
Production
API Base URL
https://api.probuy.me
Company Portal
https://company.probuy.me

Required 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": {
"email": "[email protected]",
"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

Using the Backend SDK Instead

For easier integration with built-in security and error handling, consider using our official Backend SDK:

Next Steps

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