0.0.3 • Published 7 years ago

loopback-component-openpay v0.0.3

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

loopback-component-openpay

LoopBack component to use openpay platform.

Description

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

Getting ready

This component is meant to be used inside a loopback application, there is no point to use it in any other kind of application.

Dependencies

In order to work with openpay you need to install the corresponding package:

npm install --save openpay

Environment variables

Set the following environment variables to work with openpay platform

export MERCHANT_ID="your merchant id"
export MERCHANT_SK="your merchant secret key"

Enabling the component

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.

{
  "loopback-component-openpay": {
     "isProduction": "boolean"
   }
}

isProduction will help you to indicate if you are in production mode.

Enabling models

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.

{
  "card": {
    "dataSource": "<datasource>",
    "public": true
  },
  "customer": {
      "dataSource": "<datasource>",
      "public": true
  },
  "request_openpay": {
      "dataSource": "<datasource>",
      "public": true
  }
}

Remember to put the datasource of your preference.

Features availables

Create cards and customers.

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.

{
   "card_number": "number",
   "holder_name": "string",
   "expiration_year": "number",
   "expiration_month": "number",
   "cvv2": "number",
   "customer_id": "string" 
}

WARNING: Include customer_id field with string value if you want to create a card for an specific customer. The customer_id is the one given by the openpay platform.

Request to create a customer POST /api/customers ,most include structure below.

{
   "name": "string",
   "email": "string"
}

INFO: Include requires_account field with boolean value, set false value if you need to create the customer without an account to manage the balance. It will take true as default value.

Charges

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.

{
   "customer_id": "string",
   "source_id": "string", 
   "amount": "number",
   "description": "string",
   "device_session_id": "string"
}

WARNING: 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.

{
   "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.

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago