CorvidReference

Events

Events fired by payments created using the Pay API.

Wix Payments events are fired in you site's backend when certain events occur with payments created using the Pay API. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to payment events.

Note that backend events don't work when previewing your site.

To add a payment event handler, add an events.js file to the Backend section of your site if one does not already exist. All event handler functions for your site are defined in this file.

Event handler functions are defined using the following pattern:

 export function <wixAppName>_<eventName>(event) { }

For example, an event handler that handles payment updates looks like this:

 export function wixPay_onPaymentUpdate(event) { }

Table of Contents

FUNCTIONS

?
Perform actions on an object.
onPaymentUpdate( )An event that fires when a payment's transaction status is changed.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
PaymentUpdateEventAn object representing a payment update.

onPaymentUpdate( )

An event that fires when a payment's transaction status is changed.

Description

The onPaymentUpdate() event handler runs when a payment's transaction status has changed. The received PaymentUpdateEvent object contains information about the payment transaction.

Note

Backend events don't work when previewing your site.

Syntax

function onPaymentUpdate(event: PaymentUpdateEvent): void

Examples

An event fired when a payment transaction status is changed

// Place this code in the events.js file
// of your site's Backend section.

export function wixPay_onPaymentUpdate(event) {
  let paymentId = event.payment.id;
  let newTransactionStatus = event.status;
}

/*  Full event object:
 *  {
 *    "payment": {
 *      "id": "8b3c1a90-c09e-4cd7-ae9d-9801151d8ad9",
 *      "amount": 15.99,
 *      "currency": "USD",
 *      "items": [
 *        {
 *          "name": "Baseball Bat",
 *          "quantity": 1,
 *          "price": 15.99
 *        }
 *      ],
 *      "userInfo": {
 *        "firstName": "Mike",
 *        "lastName": "Trout",
 *        "countryCode": "USA",
 *        "phone": null,
 *        "email": "mike.trout@email.com"
 *      }
 *    },
 *    "status": "Successful",
 *    "transactionId": "83f1830a-c74e-4abe-894d-3ee388b7e985"
 *  }
 */

PaymentUpdateEvent

An object representing a payment update.

See Also

onPaymentUpdate( )

Syntax

type PaymentUpdateEvent = {
  payment: Payment
  status: string
  transactionId: string
  userInfo: PaymentUserInfo
}
MEMBERS
?
The properties of an object.
payment
The payment's information.
status
string

Payment status. One of:

  • "Successful"
  • "Pending"
  • "Failed"
  • "Chargeback"
  • "Refunded"
  • "Offline"
  • "PartiallyRefunded"
  • "Cancelled"
  • "Undefined"
transactionId
string
ID of the payment transaction.
userInfo
User information.

Examples

An event fired when a payment transaction status is changed

// Place this code in the events.js file
// of your site's Backend section.

export function wixPay_onPaymentUpdate(event) {
  let paymentId = event.payment.id;
  let newTransactionStatus = event.status;
}

/*  Full event object:
 *  {
 *    "payment": {
 *      "id": "8b3c1a90-c09e-4cd7-ae9d-9801151d8ad9",
 *      "amount": 15.99,
 *      "currency": "USD",
 *      "items": [
 *        {
 *          "name": "Baseball Bat",
 *          "quantity": 1,
 *          "price": 15.99
 *        }
 *      ],
 *      "userInfo": {
 *        "firstName": "Mike",
 *        "lastName": "Trout",
 *        "countryCode": "USA",
 *        "phone": null,
 *        "email": "mike.trout@email.com"
 *      }
 *    },
 *    "status": "Successful",
 *    "transactionId": "83f1830a-c74e-4abe-894d-3ee388b7e985"
 *  }
 */