Skip to main content
Version: Live

processWalletTransaction

Charges a payment from Apple Pay, Google Pay or Paze. Pass the payload the wallet gave you and Pay Theory creates the transaction.


Function​

await messenger.processWalletTransaction(payload);

Parameters​

ParameterTypeRequiredDescription
payloadObjectYesTransaction payload object

Payload​

Keytyperequireddescription
amountIntYesAmount to charge, in cents.
digitalWalletPayloadObjectYesThe payment data the wallet returned. Its shape is set by the wallet provider.
walletTypeStringYesAPPLE_PAY, GOOGLE_PAY or PAZE. Use the wallet type constants.
payorPayorNoThe payor to create for this payment. Leave it out if you pass payorId.
payorIdStringNoID of an existing payor.
referenceStringNoYour own reference for the payment. Shows on the transaction and in the portal.
accountCodeStringNoCode for tracking a payment or group of payments.
metadataObjectNoKey-value data stored with the transaction.
additionalPurchaseDataObjectNoLevel 3 line items and summary data. Same shape as additional_purchase_data on createTransaction.
billingAddressObjectNoBilling address for the payment method.
feeIntNoFee to charge, in cents.
healthExpenseTypeStringNoHealthcare category: HEALTHCARE, RX, VISION, CLINICAL, COPAY, DENTAL or TRANSIT.
invoiceIdStringNoID of the invoice this payment pays. Don't combine with recurringId.
recurringIdStringNoID of the recurring payment this payment pays.
receiptDescriptionStringNoDescription shown on the receipt.
sendReceiptBooleanNoPass true to email a receipt to the payor.
splitObjectNoHow to split the payment between merchants. See Split transactions.

Payor object​

{
full_name: String;
email: String;
phone: String;
address_line1: String;
address_line2: String;
city: String;
region: String;
postal_code: String;
country: String;
}

Returns​

{
type: String; // 'SUCCESS' or 'ERROR'
transaction: Object;
error: String;
}
Keytypedescription
typeStringSUCCESS when Pay Theory processed the payment, even if it was declined. ERROR when the request couldn't run.
transactionTransactionThe transaction, with its payment method and payor. Present when type is SUCCESS. Check transaction.status to see whether it succeeded.
errorStringWhy the request couldn't run. Present when type is ERROR.

Usage​

const payload = {
amount: 1000, // $10.00
digitalWalletPayload: paymentData, // From Apple Pay, Google Pay, etc.
walletType: PayTheoryMessenger.applePay, // or 'APPLE_PAY'
payor: {
full_name: 'Pat Theodore',
email: 'pat@example.com',
phone: '+15555550123',
address_line1: '123 Main Street',
city: 'Cincinnati',
region: 'OH',
postal_code: '45209',
country: 'USA',
},
};

const result = await messenger.processWalletTransaction(payload);

if (result.type === 'ERROR') {
console.error('Payment could not run:', result.error);
} else if (result.transaction.status === 'FAILED') {
console.log('Payment declined:', result.transaction.transaction_id);
} else {
console.log('Payment succeeded:', result.transaction.transaction_id);
}

Notes​

  • Call initialize first.
  • walletType must match the wallet that produced digitalWalletPayload.
  • After an ERROR from Pay Theory's servers, the Messenger refreshes its connection. Call processWalletTransaction again to retry.
  • A processed payment fires the transaction_complete event, whether it succeeded or was declined. An error from Pay Theory's servers also fires transaction_error. Errors the Messenger catches before it sends the payment, such as a missing field, only come back in the ERROR response.