npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stripe-fees

v0.2.0

Published

Calculate Stripe fees for international and domestic transactions

Downloads

875

Readme

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/