Skip to main content

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 NameDescriptionExample
Content-TypeAlways application/jsonapplication/json
Martian-Pay-SignatureSignature header for authenticity verificationt=1745580845,v1=c16a830eae640a659025a5f4bf91866d...
User-AgentAlways MartianPay/1.0MartianPay/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 t field in the Martian-Pay-Signature header
  • 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 NameTypeDescription
idstringUnique event identifier
objectstringAlways event
api_versionstringAPI version
createdint64Event creation timestamp (Unix seconds)
dataEventDataEvent data payload
data.objectobjectFull resource data (e.g., PaymentIntent, Refund)
data.previous_attributesobjectPrevious data before update (for *.updated)
livemodebooltrue for production, false for test
pending_webhooksint64Number of undelivered webhooks
typestringEvent type (see below)

5. Supported Event Types

5.1 Payment Intent Events

Event TypeDescription
payment_intent.createdNew payment intent is created
payment_intent.succeededPayment intent has been fully paid and completed successfully
payment_intent.payment_failedPayment attempt for a payment intent fails
payment_intent.processingPayment intent is being processed (e.g., waiting for blockchain confirmation)
payment_intent.partially_paidPayment intent has received partial payment but is not yet fully paid
payment_intent.canceledPayment intent is canceled

5.2 Refund Events

Event TypeDescription
refund.createdNew refund is created
refund.succeededRefund has been successfully processed and funds returned to customer
refund.updatedRefund's details are updated
refund.failedRefund attempt fails

5.3 Payout Events

Event TypeDescription
payout.createdNew payout is created
payout.succeededPayout has been successfully transferred to the recipient
payout.updatedPayout's details are updated
payout.failedPayout attempt fails

5.4 Payroll Events

Event TypeDescription
payroll.createdNew payroll batch is created
payroll.approvedPayroll batch has been approved for execution
payroll.rejectedPayroll batch approval is rejected
payroll.canceledPayroll batch is canceled
payroll.executingPayroll batch execution has started
payroll.completedAll items in a payroll batch have been processed successfully
payroll.failedPayroll batch execution fails

5.5 Payroll Item Events

Event TypeDescription
payroll_item.processingIndividual payroll item is being processed
payroll_item.succeededIndividual payroll item has been successfully paid
payroll_item.failedIndividual payroll item payment fails
payroll_item.address_verification_sentAddress verification email has been sent to the recipient
payroll_item.address_verifiedRecipient has verified their wallet address

5.6 Subscription Events

Event TypeDescription
subscription.createdNew subscription is created
subscription.updatedSubscription's details are updated (e.g., plan, quantity, billing cycle)
subscription.deletedSubscription is deleted or permanently canceled
subscription.pausedSubscription is temporarily paused
subscription.resumedPaused subscription is resumed
subscription.trial_will_endSubscription's trial period is about to end (typically 3 days before)

5.7 Invoice Events

Event TypeDescription
invoice.createdNew invoice is created (draft state)
invoice.finalizedInvoice is finalized and ready for payment
invoice.paidInvoice has been fully paid
invoice.payment_succeededPayment attempt for an invoice succeeds
invoice.payment_failedPayment attempt for an invoice fails
invoice.payment_action_requiredInvoice payment requires additional action from the customer
invoice.upcomingUpcoming invoice will be generated soon (for subscriptions)
invoice.updatedInvoice's details are updated
invoice.voidedInvoice is voided and can no longer be paid

6. Reference Implementation

For production-ready sample code, refer to the official SDKs: