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

payfastjs-helper

v1.2.1

Published

Create payments/subscriptions via payfast

Downloads

5

Readme

Package Description

Create payments and subscriptions using Payfast on any website

Features

  • Supports 'return_url' & 'cancel_url' redirects
  • Supports onSuccess callback

Installing

Using npm:

$ npm install payfastjs-helper

Using yarn:

$ yarn add payfastjs-helper

Parameters

new PayfastHandler(merchantKey, merchantId, passPhrase)

  • merchantKey: Get this key from your Payfast account (required)
  • merchantId: Get this id from your Payfast account (required)
  • passPhrase: You have to set this in your Payfast account (required if set in Payfast account or when using subscriptions)

await... ().createPayment(paymentData, options, callback)

PaymentData:

  • notify_url (required)
  • return_url (Required if 'onsite' is false)
  • cancel_url (Required if 'onsite' is false)
  • name_first
  • name_last
  • email_address (required if 'cell_number' not provided)
  • cell_number (required if 'email_address' not provided)
  • m_payment_id
  • amount (required)
  • item_name
  • item_description
  • custom_str1
  • custom_str2
  • custom_str3
  • custom_str4
  • custom_str5
  • custom_int1
  • custom_int2
  • custom_int3
  • custom_int4
  • custom_int5
  • email_confirmation
  • confirmation_address
  • payment_method

await... ().createSubscription(paymentData, options, callback)

Payment Data:

  • All above
  • subscription_type (Required, default: 1 (subscription))
  • billing_date
  • recurring_amount
  • frequency (Required, Default: 3 (monthly))
  • cycles (Required)

Options

  • onsite (false by default)
  • sandbox (false by default)
options: {
	onsite: true,
	sandbox: false
}

Callback

(success: boolean) => {}

Checkout Payfast developer documentation to see what parameters mean.

Example

  • With Redirect Urls
    import { PayfastHandler } from 'payfastjs-helper'

    const paymentHandler = new PayfastPayment('123', 'abc', 'mypassphrase);

    // create payment
    await paymentHandler.createPayment({
    	amount: '100.00',
    	email_address: '[email protected]',
    	item_name: 'my demo product',
	    cancel_url: 'https://demo.demo/cancel_payment',
	    return_url: 'https://demo.demo/return_payment',
	    notify_url: 'https://demo.demo/post_to_notify_url'
    }, {sandbox: false, onsite: true})

Method will redirect you to your cancel_url / return_url

  • With Callback
    import {PayfastHandler} from 'payfastjs-helper'

    const paymentHandler = new PayfastHandler('123', 'abc', 'mypassphrase);

    // create payment
    await paymentHandler.createPayment({
    	amount: '100.00',
    	email_address: '[email protected]',
    	item_name: 'my demo product',
	    notify_url: 'https://demo.demo/post_to_notify_url'
    }, {onsite: true} ,(success) => {
		if (success){
			// payment successful
		}else{
			// payment cancelled or failed
		}
	})
  • Method will not redirect you to your cancel_url / return_url, but rather return callback if both 'cancel_url' and 'return_url' is empty.

Roadmap

  • Tokenization
  • Split payments
  • Better error handeling
  • Class to handle Server Side validations and methods