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

mypos-js

v1.0.5

Published

myPOS Checkout SDK for the JS programming language

Downloads

17

Readme

myPOS Checkout SDK for the JS programming language

npm install --save mypos-js

Please note this SDK is not currently developed or supported in anyway by myPOS. It has been barely tested too. It is based mostly on the php sdk and the developer documentation. Currently passes all tests described the integration section ot the documentation:

  • implements all of the myPOS SDK 1.4 endpoints

  • handles both checkout experiences

  • implements signature on all API calls including verification on complex object responses

  • implements all crypto functions needed for communicating to myPOS servers

  • handles all necessary validations upon any new object instance

  • implements transliteration on customer details, so it wont bother if you send those written in cyrillic for example.

  • autodetect card type, based on the card bin (please note it does not recognise VPAY and BANCONTACT cards)

  • by default it handles the demo/test data, so it is really easy to start.

  • Includes a sample with fully functional server based on express, that handles all request to and from myPOS servers (please note that to be able to debug a transaction scenario, you need to configure a public hostname to your machines IP and exposing port 80 and 443. The server will pick up an SSL for your host and only then you will be able to simulate the process)

  • includes a sample that calls all client exposed functions in a row

  • This SDK has the "SDK_JS_1.4" source tag and is based on the 1.4 version of myPOS SDK specification.
  • The library was developed and tested against node 10.16, but it should work with any version of node beyond 10.

  • Requires OpenSSL to be pressent on the host

const _host = require('./greenlock.d/config').sites[0].subject;

const  myPOS = require('mypos-js');
var  _myPOS = new  myPOS(false, {
	// keyIndex: 1,
	// sid: '000000000000010',
	// wallet: 61938166610,
	// lang: 'en',
	// developerKey: null, //Currently not used
	// privateKey: fs.readFileSync(`${__dirname}/certs/test.key`, 'utf-8'),
	// APIPublicKey: fs.readFileSync(`${__dirname}/certs/test.pub`, 'utf-8'), //Currently not used
	// encryptPublicKey: fs.readFileSync(`${__dirname}/certs/test.key`, 'utf-8'),
	lang:  'bg'
}, {
	cancelUrl:  `https://${_host}/mypos/cancel`,
	notifyUrl:  `https://${_host}/mypos/notify`,
	okUrl:  `https://${_host}/mypos/ok`,
	// reverseUrl: `https://${_host}/mypos/reverse` //optional
}, {
	// cardTokenRequest: enums.CARD_TOKEN_REQUEST.CARD_TOKEN_REQUEST_PAY_AND_STORE,
	// purchaseType: enums.PURCHASE_TYPE.PURCHASE_TYPE_SIMPLIFIED_PAYMENT_PAGE,
	// paymentMethod: enums.PAYMENT_METHOD.PAYMENT_METHOD_STANDARD,
	// outputFormat: enums.COMMUNICATION_FORMAT.COMMUNICATION_FORMAT_JSON,
	// cardVerification: enums.CARD_VERIFICATION.CARD_VERIFICATION_YES,
	// accountSettlement: false
});
  1. first argument defines production or test environment. True will make the sdk connect to the production servers.
  2. if you are using the test data, none of the properties that are commented out are needed. Set their values only when testing with your own store or when going into production.
  3. urls are mandatory and should point to your public IP address. You can configure the host inside the greenlock.d/config.json replace "your.dev.server.com" with your fqdn.
  4. The last argument has all the default values for parameters. You can overwrite any of them on per call bases, or set them globaly on the first init of the sdk as shown the this sample.

Please do not forget that while using js Date objects, the month prop always starts at 0, so be carefull when making new instances of Card.

var  _card = new  _myPOS.Card({
	// token:  'IF SET, THE CC NUMBER AND OTHER PROPS ARE NO LONGER NEEDED',
	firstNames:  'TEST',
	// lastName: 'TEST',
	number:  '4006090000000007',
	cvc:  111,
	month:  12,
	year:  2020,
	eci:  1,
	// avv: '',
	// xid: '',
});

var  _cart = new  _myPOS.Cart();
_cart.addItem('Online book', 1, 9.55);
_cart.addDiscount(3.35); //You can still add discount as normal item as shown in the documentation, but I added that function as it makes more sence to me when having the discount on a sepparate call.

var  _customer = new  _myPOS.Customer({
	email:  '[email protected]',
	phone:  '+359898000000',
	firstNames:  'Петко',
	lastName:  'Петков',
	country:  'BGR',
	city:  'Стара Загора',
	zip:  '6000',
	address:  'Центъра на Вселената'
});

You have two options

  1. Print a blank webpage that triggers submit ones loaded at the client side and get redirected to the myPOS payment gateway. To do that, just call
var  html = await  _myPOS.Purchase(_customer, _cart, {
	orderId:  'TEST_ORDER_' + new  Date().getTime(),
	currency:  'EUR',
	note:  ''  // Optional
})
  1. You can call the APIs internally within your application, but depending on your case and functions, you have to comply with some further regulations that you should first consider before proceeding with this option. Read the full details here . In most cases you should be fine if you understand the basic concepts of their API logic and if you correctly handle the 3D Secure code it will work pretty straightforward.
const  IPC_Trnref = await  _myPOS.IAPurchase({
	orderId:  'TEST_ORDER_' + new Date().getTime()
	currency:  'EUR',
	note:  ''  // Optional
	}, _card, _cart);

Check out all the examples. Spot any issue? I am happy to accept any PR. Happy codding ✌️