@bitcoin-suisse/pay
v1.0.7
Published
Bitcoin Suisse Pay plugin for crypto payments
Downloads
82
Readme
Bitcoin Suisse Pay plugin
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.
Pre-requisites
- BTCS Pay merchant account. Please sign up here.
- Merchant domiciled in Switzerland or Liechtenstein
- Legal form GmbH or AG
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. Generate auth-key
The format of the auth-key consists the Terminal ID + secret (found on the Merchant site below Customer Details -> API -> SharedSecret
)
MacOS
Run shasum -a 256 /path/to/file
Windows
Run certutil -hashfile /path/to/file SHA256
Example:
TerminalID: 987654321
Secret: 000000001
Format: <terminalID><secret>
input.txt contains: 987654321000000001
shasum -a 256 input.txt
SHA256/auth-key: 360d768442b399b2de3dded67681b3cca5eecde955c44c0b5db63353ec267ae6
4. 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
paymentId: Adding this instead of amount and fromCurrency directs to specific payments request
amount: Payment amount (not valid if paymentId is added)
fromCurrency: Currency (abbriviation e.g. EUR, USD, CHF) (not valid if paymentId is added)
-------------------------------------
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
*/
new CryptoPayments({
terminalId: '123456789',
auth: '0000...',
paymentId: '0000000001',
amount: 1337,
fromCurrency: 'CHF',
paymentCallbackUrl: 'https://www.example.com',
language: 'en',
target: document.getElementById('terminal-container'),
referenceId: '12345-12345-12345',
})
.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 or 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)}
¤cy={payment.FromCurrencyName}
&date={Date(yyyyMMdd) | ""}
&time={Date("hhmm") | ""}
&publickey={payment.CCAddress}
&paymentType={payment.ToCurrencyName}
&terminal={payment.TerminalKey}
&hash={Sha256}
Browser Support
- ES2015
- Commonjs