npm install openpay
Full API documentation available at http://docs.openpay.mx/.
//class
var Openpay = require('openpay');
//instantiation
var openpay = new Openpay(' your merchant id ', ' your private key ', [ isProduction ]);
//use the api
openpay.< resource_name >.< method_name >( ... )
All methods accept an optional callback as last argument.
The callback function should follow the format: function(error, body, response) {...}.
- error: null if the response status code is 200, 201, 204
- body: null if the response status code is different from 200, 201, 204
var newCustomer = {
"name":"John",
"email":"[email protected]",
"last_name":"Doe",
"address":{
"city":"Queretaro",
"state":"Queretaro",
"line1":"Calle Morelos no 10",
"line2":"col. san pablo",
"postal_code":"76000",
"country_code":"MX"
},
"phone_number":"44209087654"
};
openpay.customers.create(newCustomer, function(error, body, response) {
error; // null if no error occurred (status code != 200||201||204)
body; // contains the object returned if no error occurred (status code == 200||201||204)
response; // contains the complete response including the status, statusCode, statusMessage, and more information
});
var newCharge = {
"method": "card",
"card": {
"card_number": "4111111111111111",
"holder_name": "John Doe",
"expiration_year": "20",
"expiration_month": "12",
"cvv2": "110",
},
"amount" : 200.00,
"description" : "Service Charge",
"order_id" : "oid-00721"
};
openpay.charges.create(testCreateCharge, function (error, body, response){
// ...
});
var payout = {
"method": "bank_account",
"bank_account":{
"clabe":"012298026516924616",
"holder_name": "John Doe"
},
"amount" : 10.50,
"description" : "Monthly payment"
};
openpay.payouts.create(payout, function (error, body, response){
// ...
});
Before use the library will be necessary to set up your Merchant ID and Private key.
var Openpay = require('openpay');
var openpay = new Openpay('your merchant id', 'your private key', 'mx', false);
openpay.setTimeout(30000);
In addition, you can set the merchant id, private key, and the mode like this
openpay.setMerchantId(' your merchant id ');
openpay.setPrivateKey(' your private key ');
openpay.setProductionReady(true)
Once configured the library, you can use it to interact with Openpay API services.
To run the tests you'll need your sandbox credentials: merchant id and private key from your Dashboard:
$ npm install -g mocha
$ npm test
var customerId = 'customer ID';
var newBankAccount = {
"clabe": "111111111111111111",
"holder_name": "Juan H",
"alias": "Alias"
};
openpay.customers.bankaccounts.create(
customerId,
newBankAccount,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var bankAccountId = 'Bank Account Id';
openpay.customers.bankaccounts.get(
customerId,
bankAccountId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var bankAccountId = 'Bank Account Id';
openpay.customers.bankaccounts.delete(
customerId,
bankAccountId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var data = {
"creation": "2021-10-22", // Format yyyy-mm-dd
"offset": "",
"limit": ""
}
openpay.customers.bankaccounts.list(
customerId,
data,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'data' object, you can use:
- "creation[gte]" : "2021-10-22" to find bank accounts created after the given date
- "creation[lte]" : "2021-10-22" to find bank accounts created before the given date
var newCard = {
"card_number": "4111111111111111",
"holder_name": "Juan Perez",
"expiration_year": 2021,
"expiration_month": "12",
"cvv2": "111"
};
openpay.cards.create(
newCard,
function (error, body, response) {
// ...
});
Other way to create a card is through a customer
var customerId = 'Customer ID';
var newCard = {
"card_number": "4111111111111111",
"holder_name": "Juan Perez",
"expiration_year": 2021,
"expiration_month": "12",
"cvv2": "111"
};
openpay.customers.cards.create(
customerId, newCard,
function (error, body, response) {
// ...
});
var cardId = 'Card ID';
openpay.cards.get(
cardId,
function (error, body, response) {
// ...
});
Just as the method to create a new card, you can get a card through a customer, as is shown below:
var cardId = 'Card ID';
var customerId = 'Customer ID';
openpay.customers.cards.get(
cardId,
customerId,
function (error, body, response) {
// ...
});
There are three ways to create a card, the first one is with a token.
var data = {
"token_id": "Token ID",
"device_session_id": "Device session ID"
};
openpay.cards.create(
data,
function (error, body, response) {
// ...
});
The second one is with the card information only.
var newCard = {
"card_number": "4111111111111111",
"holder_name": "Juan Perez",
"expiration_year": '28',
"expiration_month": "12",
"cvv2": "111"
};
openpay.cards.create(newCard,
function (error, body, response) {
// ...
});
And the last one is through a customer.
var customerId = 'Customer ID';
var newCard = {
"card_number": "4111111111111111",
"holder_name": "Juan Perez",
"expiration_year": '28',
"expiration_month": "12",
"cvv2": "111"
};
openpay.customers.cards.create(
customerId,
newCard,
function (error, body, response) {
// ...
});
var cardId = 'Card ID';
openpay.cards.get(
cardId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var cardId = 'Card ID';
openpay.customers.cards.get(
customerId,
cardId,
function (error, body, response) {
// ...
});
var cardId = 'Card ID';
openpay.cards.delete(
cardId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var cardId = 'Card ID';
openpay.customers.cards.delete(
customerId,
cardId,
function (error, body, response) {
// ...
});
var searchParams = {
"creation": "2021-10-22", // Format yyyy-mm-dd
"offset": "",
"limit": ""
}
openpay.cards.list(
searchParams,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var searchParams = {
"creation": "2021-10-22", // Format yyyy-mm-dd
"offset": "",
"limit": ""
}
openpay.customers.cards.list(
customerId,
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find bank accounts created after the given date
- "creation[lte]" : "2021-10-22" to find bank accounts created before the given date
var customerId = 'Customer ID';
var newCharge = {
"method": "card",
"source_id": "",
"amount": 20,
"description": "Test Charge",
"currency": "COP",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f"
}
openpay.customers.charges.create(
customerId,
newCharge,
function (error, body, response) {
// ...
});
var newCharge = {
"source_id": "kdx205scoizh93upqbte",
"method": "card",
"amount": 200,
"currency": "COP",
"iva": "10",
"description": "Cargo inicial a mi cuenta",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f",
"customer": {
"name": "Cliente Colombia",
"last_name": "Vazquez Juarez",
"phone_number": "4448936475",
"email": "[email protected]"
}
}
penpay.charges.create(
newCharge,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var newCharge = {
"method": "store",
"source_id": "",
"amount": 20,
"description": "Test Charge",
"currency": "COP",
"device_session_id": null
}
openpay.customers.charges.create(
customerId,
newCharge,
function (error, body, response) {
// ...
});
var newCharge = {
"source_id": null,
"method": "store",
"amount": 200,
"currency": "COP",
"iva": "10",
"description": "Cargo inicial a mi cuenta",
"device_session_id": null,
"customer": {
"name": "Cliente Colombia",
"last_name": "Vazquez Juarez",
"phone_number": "4448936475",
"email": "[email protected]"
}
}
penpay.charges.create(
newCharge,
function (error, body, response) {
// ...
});
Only card charges can be refunded.
var chargeId = 'Charge ID';
var data = {
"description": "testing refound",
"amount": 200
}
openpay.charges.refund(
chargeId,
data,
function (error, body, response) {
// ...
});
var chargeId = 'Charge ID';
openpay.charges.get(
chargeId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var chargeId = 'Charge ID';
openpay.customers.charges.get(
customerId,
chargeId,
function (error, body, response) {
// ...
});
var searchParams = {
'order_id': 'Order ID',
'creation': 'yyyy-mm-dd',
'offset': 1,
'limit': 1,
'amount': 100,
'status': 'IN_PROGRESS'
}
openpay.charges.list(searchParams,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var searchParams = {
'order_id': 'Order ID',
'creation': 'yyyy-mm-dd',
'offset': 1,
'limit': 1,
'amount': 100,
'status': 'IN_PROGRESS'
}
openpay.customers.charges.list(
customerId,
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find charges created after the given date
- "creation[lte]" : "2021-10-22" to find charges created before the given date
Instead of the 'amount' field in the 'searchParams' object, you can use:
- "amount[gte]" : 100 to find charges with amount bigger than the amount given
- "amount[lte]" : 100 to find charges with amount smaller than the amount given
Allowed statuses:
- IN_PROGRESS
- COMPLETED
- REFUNDED
- CHARGEBACK_PENDING
- CHARGEBACK_ACCEPTED
- CHARGEBACK_ADJUSTMENT
- CHARGE_PENDING
- CANCELLED
- FAILED
####Create a customer
var newCustomer = {
'external_id' : '',
"name": "Pedro Diego",
"last_name": "Alatorre MartĂnez",
"email": "[email protected]",
"phone_number" : "5744484951",
"customer_address": {
"department":"MedellĂn",
"city":"AntioquĂa",
"additional":"Avenida 7f bis # 138-58 Apartamento 942"
}
};
openpay.customers.create(
newCustomer,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var newData = {
"name": "Pedro Diego",
"last_name": "Alatorre MartĂnez",
"email": "[email protected]",
"phone_number": "5744484951",
"customer_address": {
"department": "MedellĂn",
"city": "AntioquĂa",
"additional": "Avenida 7f bis # 138-58 Apartamento 942"
}
};
openpay.customers.update(
customerId,
newData,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
openpay.customers.get(
customerId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
openpay.customers.delete(
customerId,
function (error, body, response) {
// ...
});
const searchParams = {
'external_id': 'External ID',
'creation': 'yyyy-mm-dd',
'offset': 1,
'limit': 1
}
openpay.customers.list(
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find customers created after the given date
- "creation[lte]" : "2021-10-22" to find customers created before the given date
var newPlan = {
"amount": 150,
"status_after_retry": "CANCELLED",
"retry_times": 2,
"name": "Curso de ingles",
"repeat_unit": "month",
"trial_days": "30",
"repeat_every": "1"
};
openpay.plans.create(
newPlan,
function (error, body, response) {
// ...
});
Allowed values for 'status_after_retry':
- UNPAID
- CANCELLED
var planId = 'Plan ID';
var newData = {
"name": "New name",
"trial_days": 1
}
openpay.plans.update(
planId,
newData,
function (error, body, response) {
// ...
});
var planId = 'Plan ID';
openpay.plans.get(
planId,
function (error, body, response) {
// ...
});
var planId = 'Plan ID';
openpay.plans.delete(
planId,
function (error, body, response) {
// ...
});
var searchParams = {
'creation': 'yyyy-mm-dd',
'limit': 10,
'offset': 1
};
openpay.plans.list(searchParams, function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find plans created after the given date
- "creation[lte]" : "2021-10-22" to find plans created before the given date
var newPse = {
"method": "bank_account",
"amount": 10000,
"currency": "COP",
"description": "Cargo inicial a mi cuenta",
"iva": "1900",
"redirect_url": "/",
"customer": {
"name": "Cliente Colombia",
"last_name": "Vazquez Juarez",
"email": "[email protected]",
"phone_number": "4448936475",
"requires_account": false,
"customer_address": {
"department": "MedellĂn",
"city": "AntioquĂa",
"additional": "Avenida 7m bis #174-25 Apartamento 637"
}
}
}
openpay.pse.create(
newPse,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var newPse = {
"method": "bank_account",
"amount": 10000,
"currency": "COP",
"description": "Cargo inicial a mi cuenta",
"iva": "1900",
"redirect_url": "/"
}
openpay.customers.pse.create(
customerId,
newPse,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var newSubscription = {
"card": {
"card_number": "4111111111111111",
"holder_name": "Juan Perez Ramirez",
"expiration_year": "20",
"expiration_month": "12",
"cvv2": "110",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f"
},
"plan_id": "pbi4kb8hpb64x0uud2eb",
"trial_end_date": "yyyy-mm-dd",
"source_id": "pbiskbfhps64f0uudgeb"
}
openpay.customers.subscriptions.create(
customerId,
newSubscription,
function (error, body, response) {
// ...
});
var subscriptionId = 'Subscription ID';
const newData = {
"trial_end_date": "2021-12-12",
"cancel_at_period_end": true,
"source_id": "pbiskbfhps64f0uudgeb",
"card": {
"card_number": "4111111111111111",
"holder_name": "Juan Perez Ramirez",
"expiration_year": "20",
"expiration_month": "12",
"cvv2": "110",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f"
}
}
openpay.customers.subscriptions.update(
subscriptionId,
newData,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var subscriptionId = 'Subscription ID';
openpay.customers.subscriptions.get(
customerId,
subscriptionId,
function (error, body, response) {
// ...
});
var subscriptionId = 'Subscription ID';
openpay.customers.subscriptions.delete(
subscriptionId,
function (error, body, response) {
// ...
});
var searchParams = {
'creation': 'yyyy-mm-dd',
'limit': 10,
'offset': 1
};
openpay.customers.subscriptions.list(
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find subscriptions created after the given date
- "creation[lte]" : "2021-10-22" to find subscriptions created before the given date
var newWebhook = {
"url": "https://my-site.com/my-webhook",
"user": "juanito",
"password": "passjuanito",
"event_types": [
"charge.refunded",
"charge.failed",
"charge.cancelled",
"charge.created",
"chargeback.accepted"
]
}
openpay.webhooks.create(
newWebhook,
function (error, body, response) {
// ...
});
var webhookId = 'Webhook ID';
openpay.webhooks.get(
webhookId,
function (error, body, response) {
// ...
});
var webhookId = 'Webhook ID';
openpay.webhooks.delete(
webhookId,
function (error, body, response) {
// ...
});
openpay.webhooks.list(
function (error, body, response) {
// ...
});
var newToken = {
"card_number": "4111111111111111",
"holder_name": "Juan Perez Ramirez",
"expiration_year": "29",
"expiration_month": "12",
"cvv2": "110",
"address": {
"city": "Bogotá",
"country_code": "CO",
"postal_code": "110511",
"line1": "Av 5 de Febrero",
"line2": "Roble 207",
"line3": "col carrillo",
"state": "Bogota"
}
};
openpay.tokens.create(
tokenNew,
function (error, body, response) {
// ...
});
var tokenId = 'Token ID';
openpay.tokens.get(
tokenId,
function (error, body, response) {
// ...
});
var location = {
"latitud": 4.65589142889691,
"longitud": -74.11335673251888,
"kilometers": 10,
"amount": 1
}
openpay.stores.list(
location,
function (error, body, response) {
// ...
});
####Create a charge
var customerId = 'Customer ID';
const newCharge = {
"source_id": "kdx205scoizh93upqbte",
"method": "card",
"amount": 716,
"currency": "PEN",
"description": "Cargo inicial a mi cuenta",
"order_id": "oid-65584",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f"
}
openpay.customers.charges.create(
customerId,
newCharge,
function (error, body, response) {
// ...
});
var newCharge = {
"source_id": "kdx205scoizh93upqbte",
"method": "card",
"amount": 100,
"currency": "PEN",
"description": "Cargo inicial a mi cuenta",
"order_id": "oid-65584",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f",
"customer": {
"name": "Cliente PerĂş",
"last_name": "Vazquez Juarez",
"phone_number": "4448936475",
"email": "[email protected]"
}
};
openpay.charges.create(
newCharge,
function (error, body, response) {
// ...
});
var newCharge = {
"source_id": null,
"method": "store",
"amount": 100,
"currency": "PEN",
"description": "Cargo inicial a mi cuenta",
"order_id": "oid-65584",
"device_session_id": "kR1MiQhz2otdIuUlQkbEyitIqVMiI16f",
"customer": {
"name": "Cliente PerĂş",
"last_name": "Vazquez Juarez",
"phone_number": "4448936475",
"email": "[email protected]"
}
};
openpay.charges.create(
newCharge,
function (error, body, response) {
// ...
});
var chargeId = 'Charge ID';
openpay.charges.get(
chargeId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var chargeId = 'Charge ID';
openpay.customers.charges.get(
customerId,
chargeId,
function (error, body, response) {
// ...
});
var searchParams = {
'order_id': 'Order ID',
'creation': 'yyyy-mm-dd',
'offset': 1,
'limit': 1,
'amount': 100,
'status': 'IN_PROGRESS'
}
openpay.charges.list(
searchParams,
function (error, body, response) {
// ...
});
######With customer
var customerId = 'Customer ID';
var searchParams = {
'order_id': 'Order ID',
'creation': 'yyyy-mm-dd',
'offset': 1,
'limit': 1,
'amount': 100,
'status': 'IN_PROGRESS'
};
openpay.customers.charges.list(
customerId,
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find charges created after the given date
- "creation[lte]" : "2021-10-22" to find charges created before the given date
Instead of the 'amount' field in the 'searchParams' object, you can use:
- "amount[gte]" : 100 to find charges with amount bigger than the amount given
- "amount[lte]" : 100 to find charges with amount smaller than the amount given
Allowed statuses:
- IN_PROGRESS
- COMPLETED
- REFUNDED
- CHARGEBACK_PENDING
- CHARGEBACK_ACCEPTED
- CHARGEBACK_ADJUSTMENT
- CHARGE_PENDING
- CANCELLED
- FAILED
var newCheckout = {
"amount": 250,
"currency": "PEN",
"description": "Cargo cobro con link",
"redirect_url": "https://misitioempresa.pe",
"order_id": "oid-66393",
"expiration_date": "2021-08-31 12:50",
"send_email": "true",
"customer": {
"name": "Cliente PerĂş",
"last_name": "Vazquez Juarez",
"phone_number": "4448936475",
"email": "[email protected]"
}
}
openpay.checkouts.create(
newCheckout,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var newCheckout = {
"amount": 250,
"currency": "PEN",
"description": "Cargo cobro con link cliente",
"redirect_url": "https://misitioempresa.pe",
"order_id": "oid-87491",
"send_email": "true"
}
openpay.customers.checkouts.create(
customerId,
newCheckout,
function (error, body, response) {
// ...
});
var searchParams = {
"limit": 2,
"startDate": "20211001", // Format: yyyymmdd
"endDate": "20211011" // Format: yyyymmdd
};
openpay.checkouts.list(
searchParams,
function (error, body, response) {
// ...
});
var checkoutId = 'Checkout ID';
var newStatus = "available";
var newData = {
"expiration_date": "2021-10-26 13:43" //Format: yyyy-mm-dd HH:mm
}
openpay.checkouts.update(
checkoutId,
newStatus,
newData,
function (error, body, response) {
// ...
});
Allowed statuses:
- available
- other
- other
var checkoutId = 'Checkout ID';
openpay.checkouts.get(
checkoutId,
function (error, body, response) {
// ...
});
var newCustomer = {
"name": "Juan",
"last_name": "Perez",
"email": "[email protected]",
"phone_number": "1234567890",
"address": {
"country_code": "PE",
"postal_code": "12345",
"city": "Lima",
"state": "Lima",
"line1": "PerĂş",
"line2": "PerĂş",
"line3": "PerĂş"
}
};
openpay.customers.create(
newCustomer,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var newData = {
"name": "Juan",
"last_name": "Perez",
"email": "[email protected]",
"phone_number": "1234567890",
"address": {
"country_code": "PE",
"postal_code": "12345",
"city": "Lima",
"state": "Lima",
"line1": "PerĂş",
"line2": "PerĂş",
"line3": "PerĂş"
}
}
openpay.customers.update(
customerId,
newData,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
openpay.customers.get(
customerId,
function (error, body, respose) {
// ...
});
var customerId = 'Customer ID';
openpay.customers.delete(
customerId,
function (error, body, respose) {
// ...
});
var searchParams = {
'external_id': 'External ID',
'creation': 'yyyy-mm-dd',
'offset': 1,
'limit': 1
};
openpay.customers.list(
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find customers created after the given date
- "creation[lte]" : "2021-10-22" to find customers created before the given date
var customerId = 'Customer ID';
var newCard = {
"holder_name": "Juan Perez",
"card_number": "4111111111111111",
"cvv2": "651",
"expiration_month": "09",
"expiration_year": "25"
};
openpay.customers.cards.create(
customerId,
newCard,
function (error, body, response) {
// ...
});
var newCard = {
"holder_name": "Juan Perez",
"card_number": "4111111111111111",
"cvv2": "651",
"expiration_month": "09",
"expiration_year": "25"
};
openpay.cards.create(
newCard,
function (error, body, response) {
// ...
});
var data = {
"token_id": "Token ID",
"device_session_id": "Device session ID"
};
openpay.customers.cards.create(
data,
function (error, body, response) {
// ...
});
var data = {
"token_id": "Token ID",
"device_session_id": "Device session ID"
};
var customerId = 'Customer ID';
openpay.customers.cards.create(
customerId,
data,
function (error, body, response) {
// ...
});
var cardId = 'Card ID';
openpay.cards.get(
cardId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var cardId = 'Card ID';
openpay.customers.cards.get(
customerId,
cardId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var cardId = 'Card ID';
openpay.customers.cards.delete(
customerId,
cardId,
function (error, body, response) {
// ...
});
var cardId = 'Card ID';
openpay.cards.delete(
cardId,
function (error, body, response) {
// ...
});
var customerId = 'Customer ID';
var searchParams = {
'creation': '2021-01-01', // Format yyyy-mm-dd
'offset': 10,
'limit': 1
};
openpay.customers.cards.list(
customerId,
searchParams,
function (error, body, response) {
// ...
});
var searchParams = {
'creation': '2021-01-01', // Format yyyy-mm-dd
'offset': 10,
'limit': 1
};
openpay.cards.list(
searchParams,
function (error, body, response) {
// ...
});
Instead of the 'creation' field in the 'searchParams' object, you can use:
- "creation[gte]" : "2021-10-22" to find cards created after the given date
- "creation[lte]" : "2021-10-22" to find cards created before the given date
var webhook = {
"url": "https://mysite.com/myWebhook",
"user": "juanito",
"password": "passjuanito",
"event_types": [
"charge.failed",
"charge.cancelled",
"charge.created",
"chargeback.accepted"
]
}
openpay.webhooks.create(webhook, function (error, body, response) {
printLog(response.statusCode, body, error);
assert.equal(response.statusCode, 201, '');
done();
});
The allowed values fot the field event_types are:
- charge.refunded
- charge.failed
- charge.cancelled
- charge.created
- charge.succeeded
- charge.rescored.to.decline
- subscription.charge.failed
- payout.created
- payout.succeeded
- payout.failed
- transfer.succeeded
- fee.succeeded
- fee.refund.succeeded
- spei.received
- chargeback.created
- chargeback.rejected
- chargeback.accepted
- order.created
- order.activated
- order.payment.received
- order.completed
- order.expired
- order.cancelled
- order.payment.cancelled
var webhookId = 'Webhook ID';
openpay.webhooks.get(webhookId,
function (error, body, response) {
// ...
});
var webhookId = 'Webhook ID';
openpay.webhooks.delete(
webhookId,
function (error, body, response) {
// ...
});
openpay.webhooks.list(
function (error, body, response) {
// ...
});
const newToken = {
"card_number": "4111111111111111",
"holder_name": "Juan Perez Ramirez",
"expiration_year": "21",
"expiration_month": "12",
"cvv2": "110",
"address": {
"city": "Lima",
"country_code": "PE",
"postal_code": "110511",
"line1": "Av 5 de Febrero",
"line2": "Roble 207",
"line3": "col carrillo",
"state": "Lima"
}
}
openpay.tokens.create(
newToken,
function (error, body, response) {
// ...
});
var tokenId = 'Token ID';
openpay.tokens.get(
tokenId,
function (error, body, response) {
// ...
});