loopback-component-openpay
Version:
Loopback component to work with openpay platform.
122 lines (106 loc) • 3.95 kB
Markdown
[](http://loopback.io) component to use [openpay](http://www.openpay.mx/) platform.
loopback-component-openpay is a package to wrap openpay package inside a loopback app.
After installation you will notice important changes in your application:
* New models created:
- card
- customer
- request_openpay
This component is meant to be used inside a loopback application, there is no point to use it in any other kind of application.
In order to work with openpay you need to install the corresponding package:
```shell
npm install --save openpay
```
Set the following environment variables to work with openpay platform
```shell
export MERCHANT_ID="your merchant id"
export MERCHANT_SK="your merchant secret key"
```
In order to use this component you need to enable it as any other component. Edit the file
``` project-dir/server/component-config.json ``` and include the configuration below.
```json
{
"loopback-component-openpay": {
"isProduction": "boolean"
}
}
```
**isProduction** will help you to indicate if you are in production mode.
As you may notice there is new models generated after installation of this component, to start using "geoposition" model just enable it
as any other model. Edit the file ``` project-dir/server/model-config.json ``` and include it.
```json
{
"card": {
"dataSource": "<datasource>",
"public": true
},
"customer": {
"dataSource": "<datasource>",
"public": true
},
"request_openpay": {
"dataSource": "<datasource>",
"public": true
}
}
```
Remember to put the datasource of your preference.
There is a hook before creating cards and customers which will allow you to store on your database those models after a successfully post on
openpay platform.
It will watch a common post to create card and/or customer models.
Request to create a card ```POST /api/cards``` ,most include structure below.
```json
{
"card_number": "number",
"holder_name": "string",
"expiration_year": "number",
"expiration_month": "number",
"cvv2": "number",
"customer_id": "string"
}
```
**WARNING**: Include **customer_id** field with <b>string value</b> if you want to create a card for an specific customer.
The **customer_id** is the one <b>given by the openpay platform.</b>
Request to create a customer ```POST /api/customers``` ,most include structure below.
```json
{
"name": "string",
"email": "string"
}
```
**INFO**: Include **requires_account** field with <b>boolean value</b>, set **false** value if you need to
create the customer without an account to manage the balance. It will take **true** as default value.
There is remote methods/endpoints to create a charge for your merchant or for an specific customer.
Request to create a charge for a customer: `POST /api/request_openpays/customerCharge`, most include the structure below.
```json
{
"customer_id": "string",
"source_id": "string",
"amount": "number",
"description": "string",
"device_session_id": "string"
}
```
<strong>WARNING:</strong> Field **source_id** is the saved ID card or token id created from where the funds are withdrawn.
**WARNING**: Field **device_session_id** is the identifier of the device generated by the anti fraud tool.
Request to create a charge for a merchant `POST /api/request_openpays/merchantCharge` ,most include structure below.
```json
{
"source_id": "string",
"amount": "number",
"description": "string",
"device_session_id": "string",
"customer": "object"
}
```
**INFO**: Field **customer** is the Customer information who is charged. You can use the same parameters used in
the creation of a customer but an account for the customer will not be created.