Skip to content

Square Setup & Integration Guide

The square provider integrates Square Orders, Payment Links, Subscriptions, Saved Cards, and Disputes into the Kirak payments runtime.


Square integration requires the official squareup Python SDK. Install the Kirak extra:

Terminal window
pip install "kirak[payments-square]"

In the Square Developer Dashboard:

  1. Select or create an application.
  2. In the Credentials tab, copy the Access Token (Sandbox or Production).
  3. In the Locations tab, copy the target Location ID.

Declare the Square provider instance:

{
"payments": {
"default_provider": "square",
"providers": {
"square": {
"type": "square",
"location_id": "LXXXXXXXXXXXX",
"environment": "sandbox",
"webhook_notification_url": "https://your-domain.com/payments/webhook/square",
"success_url": "https://your-domain.com/payment/success",
"cancel_url": "https://your-domain.com/payment/cancel"
}
}
}
}

[!IMPORTANT] Exact URL Match Requirement for Signatures: Square computes its webhook HMAC signature over: $$\text{Signature} = \text{HMAC-SHA256}(\text{notification_url} + \text{raw_body})$$ The webhook_notification_url setting in kirak.json must exactly match the URL registered in the Square Developer Dashboard (including protocol, domain, port, and trailing slashes). Any difference will cause signature verification to fail with 400 INVALID_WEBHOOK_SIGNATURE.

Terminal window
KIRAK_PAYMENT_SQUARE_ACCESS_TOKEN=EAAA...
KIRAK_PAYMENT_SQUARE_WEBHOOK_SIGNATURE_KEY=... # Obtained in Step 3

In the Square Developer Dashboard $\rightarrow$ your App $\rightarrow$ Webhooks $\rightarrow$ Add Endpoint:

  1. Endpoint Name: Kirak Webhook
  2. URL: Use the exact same URL configured in webhook_notification_url (https://your-domain.com/payments/webhook/square).
  3. Select Events:
    • Payments: payment.created, payment.updated
    • Orders: order.updated
    • Refunds: refund.created, refund.updated
    • Subscriptions: subscription.created, subscription.updated
    • Saved Cards: card.disabled, card.forgotten, card.updated, card.automatically_updated
  4. Copy the Signature Key and export it as KIRAK_PAYMENT_SQUARE_WEBHOOK_SIGNATURE_KEY.

Creates a Square Order and returns a Square-hosted Checkout Link:

result = await kirak.payments.initiate_payment({
"provider": "square",
"user_id": "usr_300",
"amount": 2999, # 29.99 GBP in pence
"currency": "GBP",
"name": "Standard License",
"type": "one_time",
})
checkout_url = result["data"]["url"]

Note that Square uses subscription_plan_variation_id (create the subscription plan and variation in Square Dashboard first):

result = await kirak.payments.initiate_payment({
"provider": "square",
"user_id": "usr_300",
"amount": 0, # Billed at first-phase price from Square catalog
"currency": "GBP",
"name": "Pro Membership",
"type": "subscription",
"subscription_plan_variation_id": "SQVARIATION123",
})

[!NOTE] Cancellation Behavior: Square’s API only supports canceling subscriptions at the end of the current billing cycle. Calling cancel_subscription with at_period_end: False is not available in Square’s API and defaults to period-end cancellation.

  • Save while paying: Supported for one-time payments (save_payment_method: True).
  • Attach token: Supported from Square Web Payments SDK (attach_payment_method with client card token).
  • Off-session charge: Executes a payment against the customer’s vaulted card on file.

Normalized event Gateway Events Description
payment_completed payment.created, payment.updated (status="COMPLETED") Charge completed successfully
payment_failed payment.created, payment.updated (status="FAILED") Payment failed
subscription_updated subscription.created, subscription.updated Subscription created or updated
subscription_cancelled subscription.updated with status CANCELED or DEACTIVATED Subscription ended
refund_completed refund.created, refund.updated (status="COMPLETED") Refund completed
payment_method_removed card.disabled, card.forgotten Card vaulted at Square deleted