Skip to content

Instantly share code, notes, and snippets.

@farazdagi
Forked from siddarth/gist:6241382
Last active September 12, 2015 12:07
Show Gist options
  • Save farazdagi/b60972f006fb272c2fc8 to your computer and use it in GitHub Desktop.
Save farazdagi/b60972f006fb272c2fc8 to your computer and use it in GitHub Desktop.
Stripe FX: Getting the converted amount from the BalanceTransaction

Creating a USD charge on a GBP account:

$ curl https://api.stripe.com/v1/charges \
    -u REDACTED: \
    -d amount=400 \
    -d currency=usd \
    -d card[number]=4242424242424242 \
    -d card[exp_month]=04 \
    -d card[exp_year]=16 \
    -d card[cvv]=390 \
    -d description="USD charge on a GBP account"

Charge creation response:

{
  "id": "ch_2OEK6e5bc72wce",
  "object": "charge",
  "created": 1376577420,
  "livemode": false,
  "paid": true,
  "amount": 400,
  "currency": "usd",
  "refunded": false,
  "card": {
    "id": "card_2OEKpoYfZYhGSW",
    "object": "card",
    "last4": "4242",
    "type": "Visa",
    "exp_month": 4,
    "exp_year": 2016,
    "fingerprint": "rpUHa9dMscdvhsqc",
    "customer": null,
    "country": "US",
    "name": null,
    "address_line1": null,
    "address_line2": null,
    "address_city": null,
    "address_state": null,
    "address_zip": null,
    "address_country": null,
    "cvc_check": null,
    "address_line1_check": null,
    "address_zip_check": null
  },
  "captured": true,
  "refunds": [],
  "balance_transaction": "txn_2OEKdVhXOvMZQ5",
  "failure_message": null,
  "failure_code": null,
  "amount_refunded": 0,
  "customer": null,
  "invoice": null,
  "description": "USD charge on a GBP account",
  "dispute": null
}

The BalanceTransaction from the Charge creation response:

$ curl https://api.stripe.com/v1/balance/history/txn_2OEKdVhXOvMZQ5 \
>    -u REDACTED:

BalanceTransaction response:

{
  "id": "txn_2OEKdVhXOvMZQ5",
  "object": "balance_transaction",
  "source": "ch_2OEK6e5bc72wce",
  "amount": 258,                    # <-- The converted amount.
  "currency": "gbp",
  "net": 220,
  "type": "charge",
  "created": 1376577420,
  "available_on": 1377129600,
  "status": "pending",
  "fee": 38,
  "fee_details": [
    {
      "amount": 5,
      "currency": "gbp",
      "type": "stripe_fee",
      "description": "Stripe currency conversion fee",
      "application": null
    },
    {
      "amount": 7,
      "currency": "gbp",
      "type": "tax",
      "description": "VAT",
      "application": null
    },
    {
      "amount": 26,
      "currency": "gbp",
      "type": "stripe_fee",
      "description": "Stripe processing fees",
      "application": null
    }
  ],
  "description": "USD charge on a GBP account"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment