This guide will help you integrate Notch Pay into your application or website quickly. We’ll walk through the basic steps to accept your first payment.
from flask import redirectreturn redirect(data["authorization_url"])
4
Handle the Callback
When the payment is completed (or fails), Notch Pay will redirect the customer back to your callback URL with the payment status:
// Example callback handler in Express.jsapp.get('/callback', (req, res) => { const reference = req.query.reference; // Verify the payment status fetch(`https://api.notchpay.co/payments/${reference}`, { headers: { 'Authorization': 'YOUR_PUBLIC_KEY' } }) .then(response => response.json()) .then(data => { if (data.transaction.status === 'complete') { // Payment successful, update your database and show success page res.send('Payment successful!'); } else { // Payment failed or is still pending res.send('Payment not completed.'); } }) .catch(error => { console.error('Error:', error); res.status(500).send('Error verifying payment'); });});
<?php// Example callback handler in PHP$reference = $_GET['reference'];$curl = curl_init();curl_setopt_array($curl, [ CURLOPT_URL => "https://api.notchpay.co/payments/{$reference}", CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ "Authorization: YOUR_PUBLIC_KEY" ]]);$response = curl_exec($curl);$data = json_decode($response, true);curl_close($curl);if ($data['transaction']['status'] === 'complete') { // Payment successful, update your database and show success page echo 'Payment successful!';} else { // Payment failed or is still pending echo 'Payment not completed.';}
@app.route('/callback')def callback(): reference = request.args.get('reference') headers = { "Authorization": "YOUR_PUBLIC_KEY" } response = requests.get(f"https://api.notchpay.co/payments/{reference}", headers=headers) data = response.json() if data['transaction']['status'] == 'complete': # Payment successful, update your database and show success page return 'Payment successful!' else: # Payment failed or is still pending return 'Payment not completed.'
Always verify the payment status on your server before fulfilling orders or providing services to customers.
5
Set Up Webhooks (Recommended)
Callbacks can fail if users close their browsers before being redirected. Webhooks provide a more reliable way to receive payment notifications.
For more reliable payment notifications, set up webhooks to receive real-time updates about payment status changes:
1
Create Webhook Endpoint
Create an endpoint on your server to receive webhook events:
// Example webhook handler in Express.jsapp.post('/webhooks', express.json(), (req, res) => { const event = req.body; // Verify webhook signature (recommended for security) // ... // Handle different event types switch (event.type) { case 'payment.complete': // Update order status to paid break; case 'payment.failed': // Handle failed payment break; // Handle other event types } // Acknowledge receipt of the webhook res.status(200).send('Webhook received');});
<?php// Example webhook handler in PHP$payload = file_get_contents('php://input');$event = json_decode($payload, true);// Verify webhook signature (recommended for security)// ...// Handle different event typesswitch ($event['type']) { case 'payment.complete': // Update order status to paid break; case 'payment.failed': // Handle failed payment break; // Handle other event types}// Acknowledge receipt of the webhookhttp_response_code(200);echo 'Webhook received';
2
Register Webhook URL
Go to your Dashboard > Settings > Webhooks
Add a new webhook with your endpoint URL (e.g., https://your-website.com/webhooks)
Select the events you want to receive (e.g., payment.complete, payment.failed)
3
Secure Your Webhooks
Always verify webhook signatures to ensure they’re coming from Notch Pay and not from an attacker.