For production-ready sample code, refer to the official SDKs:
Webhook Event Handling
1. Overview: What Are Webhooks?
MartianPay leverages webhooks to proactively notify merchants of payment event changes, enabling real-time updates on transaction status.
- Trigger Conditions: Key events such as payment success, failure, or refunds will trigger a webhook notification.
- Notification Method: HTTP POST requests to your specified endpoint.
2. Webhook Request Format
- HTTP Method:
POST - Request URL Example:
https://yourdomain.com/webhook_endpoint - Headers:
| Header Name | Description | Example |
|---|---|---|
| Content-Type | Always application/json | application/json |
| Martian-Pay-Signature | Signature header for authenticity verification | t=1745580845,v1=c16a830eae640a659025a5f4bf91866d... |
| User-Agent | Always MartianPay/1.0 | MartianPay/1.0 |
3. Signature Verification
Webhook authenticity is enforced using HMAC SHA-256 signatures.
3.1 Signature Calculation (Go Example)
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(fmt.Sprintf("%d", timestamp)))
mac.Write([]byte("."))
mac.Write(payload)
signature := mac.Sum(nil)
- secret: Your webhook secret key (provided by MartianPay)
- timestamp: The
tfield in theMartian-Pay-Signatureheader - payload: The raw request body (event JSON data)
3.2 Signature Header Example
Martian-Pay-Signature: t=1745580845,v1=c16a830eae640a659025a5f4bf91866ddd4be0c85619a82defad3c10af42ec89
4. Webhook Event Data Structure
A typical webhook event payload:
{
"id": "evt_056qw9fr9PndljykFUqSIf6t",
"object": "event",
"api_version": "2025-01-22",
"created": 1745580845,
"data": {
"object": {...}, // Full resource object (e.g., PaymentIntent)
"previous_attributes": null // Only for *.updated events
},
"livemode": false,
"pending_webhooks": 0,
"type": "payment_intent.succeeded"
}
Field Reference
| Field Name | Type | Description |
|---|---|---|
| id | string | Unique event identifier |
| object | string | Always event |
| api_version | string | API version |
| created | int64 | Event creation timestamp (Unix seconds) |
| data | EventData | Event data payload |
| data.object | object | Full resource data (e.g., PaymentIntent, Refund) |
| data.previous_attributes | object | Previous data before update (for *.updated) |
| livemode | bool | true for production, false for test |
| pending_webhooks | int64 | Number of undelivered webhooks |
| type | string | Event type (see below) |
5. Supported Event Types
5.1 Payment Intent Events
| Event Type | Description |
|---|---|
| payment_intent.created | New payment intent is created |
| payment_intent.succeeded | Payment intent has been fully paid and completed successfully |
| payment_intent.payment_failed | Payment attempt for a payment intent fails |
| payment_intent.processing | Payment intent is being processed (e.g., waiting for blockchain confirmation) |
| payment_intent.partially_paid | Payment intent has received partial payment but is not yet fully paid |
| payment_intent.canceled | Payment intent is canceled |
5.2 Refund Events
| Event Type | Description |
|---|---|
| refund.created | New refund is created |
| refund.succeeded | Refund has been successfully processed and funds returned to customer |
| refund.updated | Refund's details are updated |
| refund.failed | Refund attempt fails |
5.3 Payout Events
| Event Type | Description |
|---|---|
| payout.created | New payout is created |
| payout.succeeded | Payout has been successfully transferred to the recipient |
| payout.updated | Payout's details are updated |
| payout.failed | Payout attempt fails |
5.4 Payroll Events
| Event Type | Description |
|---|---|
| payroll.created | New payroll batch is created |
| payroll.approved | Payroll batch has been approved for execution |
| payroll.rejected | Payroll batch approval is rejected |
| payroll.canceled | Payroll batch is canceled |
| payroll.executing | Payroll batch execution has started |
| payroll.completed | All items in a payroll batch have been processed successfully |
| payroll.failed | Payroll batch execution fails |
5.5 Payroll Item Events
| Event Type | Description |
|---|---|
| payroll_item.processing | Individual payroll item is being processed |
| payroll_item.succeeded | Individual payroll item has been successfully paid |
| payroll_item.failed | Individual payroll item payment fails |
| payroll_item.address_verification_sent | Address verification email has been sent to the recipient |
| payroll_item.address_verified | Recipient has verified their wallet address |
5.6 Subscription Events
| Event Type | Description |
|---|---|
| subscription.created | New subscription is created |
| subscription.updated | Subscription's details are updated (e.g., plan, quantity, billing cycle) |
| subscription.deleted | Subscription is deleted or permanently canceled |
| subscription.paused | Subscription is temporarily paused |
| subscription.resumed | Paused subscription is resumed |
| subscription.trial_will_end | Subscription's trial period is about to end (typically 3 days before) |
5.7 Invoice Events
| Event Type | Description |
|---|---|
| invoice.created | New invoice is created (draft state) |
| invoice.finalized | Invoice is finalized and ready for payment |
| invoice.paid | Invoice has been fully paid |
| invoice.payment_succeeded | Payment attempt for an invoice succeeds |
| invoice.payment_failed | Payment attempt for an invoice fails |
| invoice.payment_action_required | Invoice payment requires additional action from the customer |
| invoice.upcoming | Upcoming invoice will be generated soon (for subscriptions) |
| invoice.updated | Invoice's details are updated |
| invoice.voided | Invoice is voided and can no longer be paid |
6. Reference Implementation
For production-ready sample code, refer to the official SDKs: