@bitcoin-suisse/pay

Bitcoin Suisse Pay plugin for crypto payments

Usage no npm install needed!

<script type="module">
  import bitcoinSuissePay from 'https://cdn.skypack.dev/@bitcoin-suisse/pay';
</script>

README

logo

Bitcoin Suisse Pay plugin

npm version

By implementing the @bitcoin-suisse/pay plugin and by having a Bitcoin Suisse merchant account, you will be able accept crypto currencies as online payment method for goods and services, alongside credit cards 💳 and other payment methods in your checkout process.

Get started

1. Installation

Run the following to install the package.

npm install @bitcoin-suisse/pay

2. Add script

Either add the script directly, preferably in <head> tag.

<script type="text/javascript" src="~/node_modules/@bitcoin-suisse/pay/index.js"></script>

Or import the script into a larger codebase.

import { CryptoPayments } from '@bitcoin-suisse/pay';

3. Instantiate CryptoPayments

At the end of your <body> tag, or directly from within a SPA, instantiate an instance of the CryptoPayments lib.

/*
    Required:

    terminalId: Terminal ID
    auth: The auth-key enables the callback response as part of the paymentCallbackUrl if this is supplied
    amount: Payment amount
    fromCurrency: Currency (abbriviation e.g. EUR, USD, CHF)

    -------------------------------------

    Optional:

    paymentCallbackUrl: Platform specific callback (avoid querstrings in URL)
    language: en (default), de, fr, it
    target: Append target to an HTML element (default: appended to body)
    referenceId: Adds a reference note to the payment request
    paymentId: For invoice purpose deeplinking to a specific receipt
*/
new CryptoPayments({
    terminalId: '123456789',
    auth: '0000...',
    amount: 1337,
    fromCurrency: 'CHF',
    paymentCallbackUrl: 'https://www.example.com',
    language: 'en',
    target: document.getElementById('terminal-container'),
    referenceId: '12345-12345-12345',
    paymentId: '0000000001',
})
    .create()
    .then((data) => {
        console.log('data:', data);
        // This is called when a payment has been successfully interacted with.
        // The terminal view will remove itself.

        // Payment states 👇
        // "crypto-payments-status-PAID":
        // "crypto-payments-status-PAIDOVER":
        // "crypto-payments-status-PAIDLATE":
        // "crypto-payments-status-PAIDPARTIAL":

        // Up to the client if they want to redirect to a certain success URL or update SPA accordingly.
    })
    .catch((errorData) => {
        console.log('data:', errorData);
        // This is called when a payment has an error
        // Terminal view will remove itself

        // Payment states 👇
        // "crypto-payments-status-CANCELED":
        // "crypto-payments-status-EXPIRED":

        // Up to the client if they want to redirect to a certain error URL up update SPA accordingly.
    });

Callback response format

CallbackURL will get the following parameters appended (querystring)

?transactionid={payment.Key}
    &orderid={payment.OrderNumberRef}
    &state={state.Enumeration}
    &amount={Convert.ToString(payment.Amount)}
    &currency={payment.FromCurrencyName}
    &date={Date(yyyyMMdd) | ""}
    &time={Date("hhmm") | ""}
    &publickey={payment.CCAddress}
    &paymentType={payment.ToCurrencyName}
    &terminal={payment.TerminalKey}
    &hash={Sha256}

Browser Support

  • ES2015
  • Commonjs