Payment Callback (Webhook)

MugglePay can send webhook events that notify your application any time order status has been paid.

Depending on how you fulfill your payment, you will be informed about the status changes after the payment has been authenticated. You might also use webhooks as the basis to:

  • Update a customer’s membership record in your database when a subscription payment succeeds

  • Email a customer when a subscription payment fails

  • Log an accounting entry when a transfer is paid

This is the ONLY thing needed on the backend to keep track of the Payment status.


Request

  1. Callback data is sent in POST method.

  2. Content-Type: application/json

  3. Authentication will be the token provided in CreateOrder.

  4. MugglePay sends payment notification while your application returns response 200 (OK) HTTP status code. You should respond in json format with content:

 {
     "status": 200
 }
  1. Pay attention to token. The token sent in the body, is provided by merchants. Merchants will use it to validate the callback request (to prevent fraud attemps callbacks).

Example

	const body = { 
		merchant_order_id: merchant_order_id, // provided by CreateOrder
		order_id: order_id,
		status: 'PAID',
		price_amount: 0.14,
		price_currency: 'USD',
		pay_amount: 1,
		pay_currency: 'CNY',
		created_at: '2019-04-24T17:23:54.311Z'),
		created_at_t: 1556126634311,
		token: token,                          // token provided by CreateOrder
		meta: {
			payment: 'ALIPAY', // ALIPAY or WECHAT
			total_amount: 1.00, // Amount in CNY, ¥8.50
			trade_no: 123, // Only in Alipay
			out_trade_no: 123, // merchant_order_id
		}
	}
	return request(merchant_callback_url, { // url provided by CreateOrder
		method: 'POST',
		body: body
	})

Data Structure

Retry Time

The MugglePay server attempts to send callbacks multiple times until the send is either successful or the MugglePay server gives up. The MugglePay server attempts retries using an exponential back on the following schedule:

  • 1-minute delay

  • 2-minute delay

  • 4-minute delay

  • 8-minute delay

  • 16-minute delay

  • 32-minute delay

  • 64-minute delay

  • 128-minute delay

  • 256-minute delay

  • Retry attempt times double for up to 3 days

Last updated