## Drakemall Payment Gateway

## Quickstart

```
 $ npm install
 $ cp .env.example .env
 $ npm run dev
```

### Rough architecture

Describe how payment provider works with external payment system

![Image of Yaktocat](/docs/rabbitmq.png)

### Description
The idea behind this service is to work with payment providers and their logic seperetly from drakemall.
Currently it works as npm [package](https://www.npmjs.com/package/@ekingdom/drakemall-payment-gateway).

### How to work
1. After your branch was merged make bump the version of package using `npm version`.
2. Create a commit like `Bump version to v1.1.1`
3. Publish your changes - `npm publish`

### Coinpayments Configuration
1. Provide `COINPAYMENTS_URL` env variable to our config service - currently it's at [drakemall](https://github.com/skinholdings/drakemall).
2. Login to [Coinpayments](https://www.coinpayments.net/).
3. Provide IPN URL (it's an URL for postbacks, e.g. https://drakemall.com/api/payment/coinpayments/postback) [here](https://www.coinpayments.net/acct-settings) in the 4 tab.
4. Done.

### Accent Pay Configuration
1. Provide `ACCENT_PAY_URL` env variable to our config service - currently it's at [drakemall](https://github.com/skinholdings/drakemall).
2. For test purposes you can use the following
```bash
$ export ACCENT_PAY_URL=https://accentpay.com?currency=USD&site_id=418&salt=1d69b4066130fc6a9193e2ec7749788218b9c492a4008bc73aa1cfbed3f3df95b6dffe42c951fa921499aebd6255c471a7a2863b3a1c6b66d621d93ef9e2c543
```
3. For local/dev environments configure webhooks via [my.webhookrelay.com](https://my.webhookrelay.com/)
4. If you want to launch on local machine use:
```bash
$ relay forward --bucket accent-pay-local # (you also must have relay CLI installed to do so, https://webhookrelay.com/v1/guide/installation.html#Install-CLI)
```
5. To test different responses you must use the following cards:
    - *4314220000000056* **success**
    - *5413330000000019* **success**
    - *4314220000000072* **decline**
    - *5413330000000035* **decline**
    - *4314220000000098* **decline**
    - *5413330000000092* **decline**
6. All the other credentials can be filled randomly
7. In order to change webhooks - contact accent pay support (support@ecommpay.com), current webhooks:
    - production: POST https://drakemall.com/api/payment/accent_pay/postback
    - test: POST https://my.webhookrelay.com/v1/webhooks/5aadb029-550f-4c54-acd2-cd9c943bb817
8. Done.

### Voucherify Configuration

1. For local/dev environment configure webhooks via [my.webhookrelay.com](https://my.webhookrelay.com/)
WebHook endpoint should point to `http://localhost:3031/api/payment/voucherify/webhook`

    **Contact** to [Maintainers](#Maintainers) to get access to webhookrelay.com account
2. Setup [WebHook endpoint](https://docs.voucherify.io/docs/webhooks) on [Voucherify Admin Dashboard](https://app.voucherify.io), select events and click to `redemption succeeded` in order to receive http requests
3. Start `relay` cli to begin to receive webhooks for development purposes
```bash
$ relay forward --bucket voucherify-pay-local # (you also must have relay CLI installed to do so, https://webhookrelay.com/v1/guide/installation.html#Install-CLI)
```
4. Copy WebHook secret from Admin Dashboard and set `VOUCHERIFY_WEBHOOK_SECRET` env variable directly or put to `.env`

5. In **production** environment, please use **production credentials** and setup webhook endpoint to **production** site, and disable all others endoints. **Please** *dont use the same Voucherify.io account for development and in production environment at the same time!!!*
6. Done

### Card Pay v3.0
[Integration Manual](https://integration.cardpay.com/v3/#introduction)
1. Provide `CARDPAY_V3_URL` env variable to our config service - currently it's at [drakemall](https://github.com/skinholdings/drakemall).
2. For test purposes you can use the following
```bash
$ CARDPAY_V3_URL=https://sandbox.cardpay.com/api?currency=USD&walletId=14265&callbackSecret=m5SgFW903nbQ&merchantSecret=sO5QSDpr1x80&maxUserCardsCount=2&orderDescription=Drakemall.com cases open purchase
```
3. For local/dev environments configure webhooks via [my.webhookrelay.com](https://my.webhookrelay.com/)
4. If you want to launch on local machine use:
```bash
$ relay forward --bucket cardpay-local # (you also must have relay CLI installed to do so, https://webhookrelay.com/v1/guide/installation.html#Install-CLI)
```
5. To test different responses you must use the following cards:
    - *4000000000000002*: **CONFIRMED as 3-D Secure transaction**
    - *5555555555554444*: **DECLINED as 3-D Secure transaction**
    - *4000000000000044*: **PENDING as 3-D Secure transaction**
    - *4000000000000077*: **CONFIRMED as non 3-D Secure transaction**
    - *5555555555554477*: **DECLINED as non 3-D Secure transaction**
    - *4000000000000051*: **PENDING as non 3-D Secure transaction**
6. All the other credentials can be filled randomly
7. In order to change webhooks - contact card pay support
8. Done.

## Maintainers
* **Vitaliy Krivtsov** - *Initial work* - [vkrivtsov](https://github.com/vkrivtsov)
* **Victor Klynets** - *Initial work* - [klinyecviktor](https://github.com/klinyecviktor)
* **Nikita Mazur** - *Maintenance* - [ipirius](https://github.com/ipirius)
* **Denis Kublitskiy** - *Maintenance* - [deniskublitskiy](https://github.com/deniskublitskiy)
