Full Transaction Lifecycle Example (Digital Wallet)

Full Transaction Lifecycle — Digital Wallet

Frontend

CollectJS.configure({
  googlePay: true, applePay: true,
  paymentRequest: { total: { label: 'Order', amount: { currency: 'USD', value: '49.99' } } },
  callback: function(token) {
    fetch('/api/process', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ payment_token: token.token, amount: '49.99', save: true })
    }).then(r => r.json()).then(data => {
      if (data.success) window.location = '/thank-you?txn=' + data.txid;
      else showError(data.message);
    });
  },
});

Backend — Process + Store in Vault

$data = json_decode(file_get_contents('php://input'), true);
$post = array(
    'security_key'      => YOUR_PRIVATE_KEY,
    'type'              => 'sale',
    'amount'            => $data['amount'],
    'payment_token'     => $data['payment_token'],
    'customer_vault'    => 'add_customer',
    'customer_vault_id' => 'USER-' . $_SESSION['user_id'],
    'order_id'          => generate_order_id(),
);
$result = gateway_post($post);
if ($result['response'] == '1') {
    save_vault_id($_SESSION['user_id'], $result['customer_vault_id']);
    echo json_encode(['success' => true, 'txid' => $result['transactionid']]);
} else {
    echo json_encode(['success' => false, 'message' => $result['responsetext']]);
}

Take Your Business to the Next Level

Find out how our innovative payment solutions can benefit your business. Reach out to us for more information or to get started!

Let's Get Started