Code Examples

Practical code examples for integrating Graphexia software solutions into your application.

PHP Integration

Complete PHP example for creating payments

<?php
// Initialize Graphexia client
$graphexia = new GraphexiaClient('YOUR_API_KEY');

// Create payment
$payment = $graphexia->payments->create([
    'amount' => 10000,
    'currency' => 'usd',
    'order_id' => 'order_123',
    'return_url' => 'https://yourstore.com/success',
    'cancel_url' => 'https://yourstore.com/cancel'
]);

// Redirect customer to payment page
header('Location: ' . $payment->payment_url);
?>

JavaScript/Node.js

Node.js example using the Graphexia SDK

const Graphexia = require('@graphexia/sdk');

const graphexia = new Graphexia('YOUR_API_KEY');

// Create payment
const payment = await graphexia.payments.create({
  amount: 10000,
  currency: 'usd',
  order_id: 'order_123',
  return_url: 'https://yourstore.com/success',
  cancel_url: 'https://yourstore.com/cancel'
});

// Redirect to payment URL
window.location.href = payment.payment_url;

Shopify Integration

Shopify app integration example

// Shopify checkout extension
import { useGraphexia } from '@graphexia/shopify';

export default function Checkout() {
  const { createPayment } = useGraphexia();
  
  const handlePayment = async () => {
    const payment = await createPayment({
      amount: cart.totalPrice,
      order_id: cart.id,
      return_url: `${shop.url}/checkout/success`,
      cancel_url: `${shop.url}/checkout`
    });
    
    window.location.href = payment.payment_url;
  };
  
  return <button onClick={handlePayment}>Pay Now</button>;
}

Webhook Handler

Handle payment webhooks securely

// Express.js webhook handler
const express = require('express');
const app = express();

app.post('/webhooks/graphexia', express.raw({type: 'application/json'}), (req, res) => {
  const signature = req.headers['x-graphexia-signature'];
  const payload = req.body;
  
  // Verify webhook signature
  if (verifySignature(signature, payload)) {
    const event = JSON.parse(payload);
    
    if (event.type === 'payment.succeeded') {
      // Update order status
      updateOrderStatus(event.data.order_id, 'paid');
    }
    
    res.status(200).send('OK');
  } else {
    res.status(401).send('Unauthorized');
  }
});

Need More Help?

Explore our troubleshooting guide or contact support for assistance.

Code Examples - Graphexia Documentation | Graphexia