New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

stripe-fees

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stripe-fees

Calculate Stripe fees for international and domestic transactions

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
99
decreased by-57.87%
Maintainers
1
Weekly downloads
 
Created
Source

stripe-fees

Calculate Stripe fees for international and domestic transactions

Often times you would wish to make your customers know the transaction fee before making the transaction (e.g. if you want to ask the customer to cover the fees).

Unfortunately Stripe does not provide any API for that :-(

But this mighty little package is here to help!

Installation

yarn add stripe-fees

Usage

Heads up! All currency amounts are in cents (1/100)!

calculateStripeFee(
  // Transaction amount in cents
  amount: number,
  // Alpha-2 country code of the target account
  accountCountryCode: string,
  // Bank card Alpha-2 country code
  cardCountryCode: string,
  // Your applicationFee in percents, default to 0
  applicationFee: number = 0,
  coverFees: boolean = true,
): {
  totalFeeAmount: number,
  applicationFeeAmount: number,
  providerFeeAmount: number
} // Returns resulting fee amounts in cents: total, provider and application

E.g. transaction from UK card to US account:

import calculateStripeFee from 'stripe-fees'
const stripeFee = calculateStripeFee(10000, 'US', 'UK')

But now you are left wondering, how to get the card country code from the Strip card input element before making the transaction (since it's protected from direct access)? Simple!

import { CardElement, useStripe, useElements } from '@stripe/react-stripe-js'

const YourCardInputComponent = ({ setCardCountryCode }) => {
  const elements = useElements()
  const stripe = useStripe()

  return (
    <CardElement
      onChange={ev => {
        if (ev.complete) {
          const card = elements?.getElement(CardElement)
          if (card) {
            stripe
              ?.createPaymentMethod({
                type: 'card',
                card
              })
              .then(response => {
                const countryCode = response?.paymentMethod?.card?.country
                if (countryCode) {
                  setCardCountryCode(countryCode)
                }
              })
          }
        }
      }}
    />
  )
}

Contribute

Not all countries are yet supported. Add more to stripeFeesByCountry according to https://stripe.com/{countryCode}/pricing#pricing-details and provide a PR!

A note to Stripe

If you guys are reading it, please make an official API for this stuff! Your fees are hard to calculate by hand, really!

Credit

This package has been proudly developed by the Deed team!

Check us out, we may be hiring!

https://www.joindeed.com/

Keywords

FAQs

Package last updated on 18 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc