# mypos-js

> myPOS Checkout SDK for the JS programming language

Latest version **1.0.5** (published 2020-03-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install mypos-js
pnpm add mypos-js
yarn add mypos-js
bun add mypos-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-03-03 |
| First published | 2020-02-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 54.3 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | fakedob |
| Maintainers | hedwin |

## Links

- npm: https://www.npmjs.com/package/mypos-js
- Repository: https://github.com/zaralab-org/mypos-js
- Issues: https://github.com/zaralab-org/mypos-js/issues
- npm.io page: https://npm.io/package/mypos-js

## Dependencies (5)

- [he](https://npm.io/package/he.md) ^1.2.0
- [flat](https://npm.io/package/flat.md) ^5.0.0
- [axios](https://npm.io/package/axios.md) ^0.19.2
- [transliteration](https://npm.io/package/transliteration.md) ^2.1.8
- [credit-card-type](https://npm.io/package/credit-card-type.md) ^8.3.0

## Recent versions

- 1.0.5 (latest) — 2020-03-03
- 1.0.4 — 2020-02-27
- 1.0.3 — 2020-02-27
- 1.0.2 — 2020-02-26
- 1.0.1 — 2020-02-26
- 1.0.0 — 2020-02-26

## 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](https://developers.mypos.eu/en/doc/online_payments/v1_4/20-api-reference). 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


```javascript
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.

```javascript
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:  'god@me.com',
	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

```javascript
var  html = await  _myPOS.Purchase(_customer, _cart, {
	orderId:  'TEST_ORDER_' + new  Date().getTime(),
	currency:  'EUR',
	note:  ''  // Optional
})
```

2. 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](https://developers.mypos.eu/en/doc/online_payments/v1_4/39-api-call--ipciapurchase) . 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.

```javascript
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 ✌️

---
_Source: https://npm.io/package/mypos-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
