Skip to content

ScootKit/paysafecard

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PaySafeCard

Unofficial PaySafeCard Node.js wrapper. This is a fork of pieczorx/PaySafeCard a package with some bugs and which seems unmaintained. As we use this package in our production environment, we will update it regular and provide support if needed.

Important

This module uses ES6 promises, so if you need older Node version support please use Babel.

Install

npm i @scnetwork/paysafecard

Set api key and environment

const PaySafeCard = require('@scnetwork/paysafecard');

const psc = new PaySafeCard({
  key: 'psc_123456789012345678901-123456789', //Paste your api key here
  environment: 'TEST' //or PRODUCTION
});

Usage

Create payment

async () => {
  try {
    const response = await psc.createPayment({
      currency: 'USD',
      amount: 19.99,
      urls: {
        redirectSuccess: 'https://example.com/successUrl',
        redirectFailure: 'https://example.com/failureUrl',
        notification: 'https://example.com/notificationUrl'
      },
      customer: {
        id: '241', //Customer id from your system, can be anything
        minAge: null, //optional
        kycRestriction: null, //optional
        countryRestriction: null //optional
      },
      shopId: null //optional, read official docs for more info
    });
    console.log('Payment link generated! ', response.redirect.auth_url)
    const PAYMENT_ID = response.id
    console.log('Store this id in your database for future use: ', PAYMENT_ID)
  } catch(e) {
    //Handle error
  }
}

Check payment status & capture it if succeeded

async () => {
  try {
    //Check if payment is completed
    const info = await psc.getPaymentInfo(PAYMENT_ID) //Payment id from previous request
    if(info.status == 'AUTHORIZED') {
      //Capture payment
      const captureInfo = await psc.capturePayment(PAYMENT_ID)
      if(captureInfo.status == 'SUCCESS') {
        /*
        Payment completed, update your database here
        */
      }
    }
  } catch(e) {
    //Handle error
  }
}

About

Unofficial PaySafeCard Node.js wrapper

Resources

License

Stars

Watchers

Forks

Languages

  • JavaScript 100.0%