Skip to content

Instantly share code, notes, and snippets.

@siddarth
Created August 15, 2013 14:44
Show Gist options
  • Select an option

  • Save siddarth/6241382 to your computer and use it in GitHub Desktop.

Select an option

Save siddarth/6241382 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"
}
@wesbos

wesbos commented Nov 4, 2014

Copy link
Copy Markdown

thank you - this is really helpful

@zot24

zot24 commented Dec 3, 2014

Copy link
Copy Markdown

Do we have access to the exchange rate?

@sebastiansulinski

Copy link
Copy Markdown

You can also obtain converted values by expanding objects - it will give you similar result as above
https://stripe.com/docs/api/curl#expanding_objects

curl https://api.stripe.com/v1/charges/ch_18WjOEBOpc3jzxLvhpXJAgfH \
   -u sk_test_1k5krhYfNScp2SoDk3PPUgrE: \
   -d expand[]=customer

@bassu

bassu commented Jun 1, 2017

Copy link
Copy Markdown

Stripe doesn't list FX charges into fees anymore! It is now done prior to charging any fees.
So you'll have to calculate this manually.
Their markup is 2% now on top of the mid-market rate.

@emkman

emkman commented Sep 12, 2017

Copy link
Copy Markdown

@bassu do you have any source for their 2% markup. I cannot find it mentioned anywhere in their docs, however I am seeing very poor conversion rates indicating you are correct. https://stripe.com/docs/currencies/conversions specifically states "When Stripe performs a currency conversion, funds are usually converted at the daily mid-market rate." and they go on to only mention their standard processing fees, no mention of conversion fees or mid-market markups. Very disingenuous if true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment