### Install Openpay Node.js Library Source: https://github.com/open-pay/openpay-node/blob/master/README.md Installs the Openpay Node.js library using npm. This is the first step to integrate Openpay services into your Node.js application. ```bash npm install openpay ``` -------------------------------- ### Create an Openpay Payout in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Demonstrates how to create a payout using the Openpay Node.js library. This example shows setting up a payout to a bank account with details like CLABE, holder name, amount, and description. ```javascript 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) { // ... }); ``` -------------------------------- ### Create an Openpay Customer in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Provides an example of creating a new customer using the Openpay Node.js library. It defines customer details including name, email, address, and phone number, and sends this data to the Openpay API. ```javascript var newCustomer = { "name":"John", "email":"johndoe@example.com", "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 }); ``` -------------------------------- ### Get Customer Bank Account in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Provides an example of retrieving a specific customer's bank account details using the Openpay Node.js library. It requires both the customer ID and the bank account ID. ```javascript var customerId = 'Customer ID'; var bankAccountId = 'Bank Account Id'; openpay.customers.bankaccounts.get( customerId, bankAccountId, function (error, body, response) { // ... }); ``` -------------------------------- ### Create an Openpay Charge in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Illustrates how to create a charge using the Openpay Node.js library. This example includes details for a card charge, such as card information, amount, description, and order ID. ```javascript 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) { // ... }); ``` -------------------------------- ### Get a Plan (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves a specific plan by its ID. Requires the plan ID as input. Returns plan details upon success. ```javascript var planId = 'Plan ID'; openpay.plans.get( planId, function (error, body, response) { // ... }); ``` -------------------------------- ### Get a Subscription (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details for a specific subscription. Requires both the customer ID and the subscription ID. ```javascript var customerId = 'Customer ID'; var subscriptionId = 'Subscription ID'; openpay.customers.subscriptions.get( customerId, subscriptionId, function (error, body, response) { // ... }); ``` -------------------------------- ### Create Openpay Card in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Provides an example of creating a new card token using the Openpay Node.js library. It includes card details like number, holder name, expiration date, and CVV2. This token can then be used for charges. ```javascript 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) { // ... }); ``` -------------------------------- ### Initialize Openpay Client and Configure Settings (JavaScript) Source: https://context7.com/open-pay/openpay-node/llms.txt Demonstrates how to initialize the Openpay client with merchant credentials, country code, and environment mode (sandbox/production). It also shows how to configure request timeouts and dynamically update credentials. ```javascript var Openpay = require('openpay'); // Initialize for Mexico (sandbox mode - default) var openpay = new Openpay('your_merchant_id', 'your_private_key', 'mx', false); // Initialize for Colombia (production mode) var openpayCol = new Openpay('your_merchant_id', 'your_private_key', 'co', true); // Initialize for Peru (sandbox mode) var openpayPeru = new Openpay('your_merchant_id', 'your_private_key', 'pe', false); // Configure timeout (in milliseconds) openpay.setTimeout(30000); // Update credentials dynamically openpay.setMerchantId('new_merchant_id'); openpay.setPrivateKey('new_private_key'); openpay.setProductionReady(true); // Switch to production ``` -------------------------------- ### Get Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details of a specific customer using their ID. ```javascript var customerId = 'Customer ID'; openpay.customers.get( customerId, function (error, body, response) { // ... }); ``` -------------------------------- ### Get Payout Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves the details of a specific payout using its ID. ```APIDOC ## Get Payout ### Description Retrieves the details of a specific payout using its unique identifier. ### Method GET ### Endpoint /v1/payouts/{payout_id} ### Parameters #### Path Parameters - **payout_id** (string) - Required - The ID of the payout to retrieve. ### Request Example ```javascript var payoutId = 'po_abc123'; openpay.payouts.get(payoutId, function(error, payout, response) {}); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the payout. - **status** (string) - The current status of the payout. - **amount** (number) - The amount of the payout. #### Response Example ```json { "id": "po_abc123", "status": "COMPLETED", "amount": 1050.50 } ``` ``` -------------------------------- ### Create Plan Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a new subscription plan. Requires plan details such as amount, name, repetition unit, and trial days. ```javascript 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) { // ... }); ``` -------------------------------- ### List Plans with Search Parameters (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Lists available plans, allowing for filtering by creation date, limit, and offset. Supports date range queries for 'creation' field. ```javascript var searchParams = { 'creation': 'yyyy-mm-dd', 'limit': 10, 'offset': 1 }; openpay.plans.list(searchParams, function (error, body, response) { // ... }); ``` -------------------------------- ### Get Merchant Info Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves the merchant account information, including ID and balance. ```APIDOC ## Get Merchant Info ### Description Retrieves the merchant account information. ### Method GET ### Endpoint `/v1/merchant` (This is an inferred endpoint based on SDK usage) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **id** (string) - The merchant's unique identifier. - **balance** (number) - The current balance of the merchant account. #### Response Example ```json { "id": "merchant_id_12345", "balance": 1500.75 } ``` ``` -------------------------------- ### Initialize Openpay Client in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Demonstrates how to initialize the Openpay client in a Node.js application. It requires merchant ID, private key, and optionally a production flag. The instantiated object is used to access various Openpay API resources. ```javascript var Openpay = require('openpay'); var openpay = new Openpay(' your merchant id ', ' your private key ', [ isProduction ]); openpay.< resource_name >.< method_name >( ... ) ``` -------------------------------- ### Get Charge Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves the details of a specific charge transaction using its unique ID. ```APIDOC ## GET /charges/{chargeId} ### Description Retrieves details of a specific charge transaction. ### Method GET ### Endpoint `/charges/{chargeId}` ### Parameters #### Path Parameters - **chargeId** (string) - Required - The ID of the charge to retrieve. ### Response #### Success Response (200) - **status** (string) - The current status of the charge. - **amount** (number) - The amount of the charge. - **creation_date** (string) - The date and time the charge was created. #### Response Example ```json { "status": "completed", "amount": 200.00, "creation_date": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### List Webhooks (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Lists all configured webhooks. No parameters are required. ```javascript openpay.webhooks.list( function (error, body, response) { // ... }); ``` -------------------------------- ### Get OpenPay Checkout Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details for a specific checkout using its ID. Requires the checkout ID as a parameter. ```javascript var checkoutId = 'Checkout ID'; openpay.checkouts.get( checkoutId, function (error, body, response) { // ... }); ``` -------------------------------- ### List Customers with Filtering and Pagination (JavaScript) Source: https://context7.com/open-pay/openpay-node/llms.txt Illustrates how to retrieve a list of customers, with options for filtering by creation date and controlling the number of results per page using offset and limit parameters. ```javascript var searchParams = { "creation[gte]": "2023-01-01", "creation[lte]": "2023-12-31", "offset": 0, "limit": 10 }; openpay.customers.list(searchParams, function(error, customers, response) { if (error) { console.error('Error listing customers:', error); return; } console.log('Total customers found:', customers.length); customers.forEach(function(customer) { console.log(customer.id, customer.name); }); }); ``` -------------------------------- ### Get a Card (Node.js) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves a specific card using its ID. This operation can be performed independently or in association with a customer. ```javascript var cardId = 'Card ID'; openpay.cards.get( cardId, function (error, body, response) { // ... }); ``` ```javascript var cardId = 'Card ID'; var customerId = 'Customer ID'; openpay.customers.cards.get( cardId, customerId, function (error, body, response) { // ... }); ``` -------------------------------- ### Create Plan Source: https://context7.com/open-pay/openpay-node/llms.txt Creates a new subscription plan for recurring billing. ```APIDOC ## Create Plan ### Description Creates a new subscription plan that can be used for recurring billing. Defines the amount, billing frequency, and retry logic. ### Method POST ### Endpoint /v1/plans ### Parameters #### Request Body - **amount** (number) - Required - The amount for the subscription. - **status_after_retry** (string) - Optional - The status to set after retries are exhausted (e.g., "CANCELLED"). - **retry_times** (integer) - Optional - The number of times to retry failed payments. - **name** (string) - Required - The name of the plan. - **repeat_unit** (string) - Required - The unit of repetition for the billing cycle (e.g., "day", "week", "month", "year"). - **trial_days** (integer) - Optional - The number of trial days for the subscription. - **repeat_every** (integer) - Required - The number of `repeat_unit` intervals between billing cycles. ### Request Example ```javascript var newPlan = { "amount": 150.00, "status_after_retry": "CANCELLED", "retry_times": 2, "name": "Premium Monthly", "repeat_unit": "month", "trial_days": 30, "repeat_every": 1 }; openpay.plans.create(newPlan, function(error, plan, response) {}); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created plan. - **name** (string) - The name of the plan. #### Response Example ```json { "id": "pln_abc123xyz", "name": "Premium Monthly" } ``` ``` -------------------------------- ### Get Charge With Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details of a specific charge associated with a customer. Requires both the customer ID and the charge ID. ```javascript var customerId = 'Customer ID'; var chargeId = 'Charge ID'; openpay.customers.charges.get( customerId, chargeId, function (error, body, response) { // ... }); ``` -------------------------------- ### List Subscription Plans with OpenPay Node.js Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves a list of all available subscription plans, with options for filtering and pagination. Accepts search parameters and returns a list of plans or an error. ```javascript var searchParams = { "creation[gte]": "2023-01-01", "limit": 50, "offset": 0 }; openpay.plans.list(searchParams, function(error, plans, response) { if (error) { console.error('Error listing plans:', error); return; } plans.forEach(function(plan) { console.log(plan.id, plan.name, plan.amount); }); }); ``` -------------------------------- ### Get Charge Without Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details of a specific charge using its ID. This method does not require customer information. ```javascript var chargeId = 'Charge ID'; openpay.charges.get( chargeId, function (error, body, response) { // ... }); ``` -------------------------------- ### Create a Subscription (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a new subscription for a customer. Requires the customer ID, subscription details including card information, plan ID, and optional trial end date or source ID. ```javascript 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) { // ... }); ``` -------------------------------- ### Get OpenPay Card with Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details for a specific card associated with a customer. Requires both the customer ID and the card ID as parameters. ```javascript var customerId = 'Customer ID'; var cardId = 'Card ID'; openpay.customers.cards.get( customerId, cardId, function (error, body, response) { // ... }); ``` -------------------------------- ### Get a Webhook (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves a specific webhook by its ID. Requires the webhook ID as input. Returns webhook details upon success. ```javascript var webhookId = 'Webhook ID'; openpay.webhooks.get( webhookId, function (error, body, response) { // ... }); ``` -------------------------------- ### Configure Openpay Client in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Shows different ways to configure the Openpay client, including setting merchant ID, private key, and production mode. It also demonstrates setting a timeout for API requests. ```javascript var Openpay = require('openpay'); var openpay = new Openpay('your merchant id', 'your private key', 'mx', false); openpay.setTimeout(30000); openpay.setMerchantId(' your merchant id '); openpay.setPrivateKey(' your private key '); openpay.setProductionReady(true) ``` -------------------------------- ### Create a Webhook (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a new webhook endpoint. Requires a URL, authentication credentials (user, password), and a list of event types to subscribe to. ```javascript 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) { // ... }); ``` -------------------------------- ### Plans API Source: https://github.com/open-pay/openpay-node/blob/master/README.md APIs for creating and updating subscription plans. ```APIDOC ## POST /plans ### Description Creates a new subscription plan. ### Method POST ### Endpoint /plans ### Parameters #### Request Body - **amount** (number) - Required - The plan amount. - **status_after_retry** (string) - Optional - The status after retries. Allowed values: UNPAID, CANCELLED. - **retry_times** (number) - Optional - The number of retry attempts. - **name** (string) - Required - The name of the plan. - **repeat_unit** (string) - Required - The unit of repetition (e.g., 'month'). - **trial_days** (string) - Optional - The number of trial days. - **repeat_every** (string) - Optional - The interval for repetition. ### Request Example ```json { "amount": 150, "status_after_retry": "CANCELLED", "retry_times": 2, "name": "Curso de ingles", "repeat_unit": "month", "trial_days": "30", "repeat_every": "1" } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created plan. #### Response Example ```json { "id": "plan_exampleid" } ``` ``` ```APIDOC ## PUT /plans/{planId} ### Description Updates an existing subscription plan. ### Method PUT ### Endpoint /plans/{planId} ### Parameters #### Path Parameters - **planId** (string) - Required - The ID of the plan to update. #### Request Body - **name** (string) - Optional - The new name of the plan. - **trial_days** (number) - Optional - The new number of trial days. ### Request Example ```json { "name": "New name", "trial_days": 1 } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the updated plan. #### Response Example ```json { "id": "plan_exampleid" } ``` ``` -------------------------------- ### Get Openpay Token by ID Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves an existing token using its unique ID. This function is useful for verifying token details or for use in subsequent payment operations. ```javascript var tokenId = 'Token ID'; openpay.tokens.get( tokenId, function (error, body, response) { // ... }); ``` -------------------------------- ### Get OpenPay Card without Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Retrieves details for a specific card using its ID, without requiring an associated customer ID. Requires the card ID as a parameter. ```javascript var cardId = 'Card ID'; openpay.cards.get( cardId, function (error, body, response) { // ... }); ``` -------------------------------- ### Create Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a new customer profile. Requires customer details such as name, email, phone number, and optionally an address. ```javascript var newCustomer = { 'external_id' : '', "name": "Pedro Diego", "last_name": "Alatorre Martínez", "email": "pedro.alatorre@comercio.com", "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) { // ... }); ``` -------------------------------- ### Get Plan Details with OpenPay Node.js Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves the details of a specific subscription plan using its ID. Requires the plan ID as input and returns plan information or an error. ```javascript var planId = 'plan_abc123'; openpay.plans.get(planId, function(error, plan, response) { if (error) { console.error('Error fetching plan:', error); return; } console.log('Plan:', plan.name, 'Amount:', plan.amount); }); ``` -------------------------------- ### Get Token Details with OpenPay Node.js Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves details associated with a previously created payment token. Requires the token ID and returns information about the card linked to the token or an error. ```javascript var tokenId = 'tok_abc123xyz'; openpay.tokens.get(tokenId, function(error, token, response) { if (error) { console.error('Error fetching token:', error); return; } console.log('Token card brand:', token.card.brand); }); ``` -------------------------------- ### Create Payout Source: https://context7.com/open-pay/openpay-node/llms.txt Initiates a payout to a registered bank account. ```APIDOC ## Create Payout ### Description Initiates a payout to a bank account that has been previously registered for the merchant. ### Method POST ### Endpoint /v1/payouts ### Parameters #### Request Body - **method** (string) - Required - The payout method (e.g., "bank_account"). - **bank_account** (object) - Required - Details of the bank account. - **clabe** (string) - Required - The CLABE of the bank account. - **holder_name** (string) - Required - The name of the account holder. - **amount** (number) - Required - The amount to be paid out. - **description** (string) - Optional - A description for the payout. ### Request Example ```javascript var payout = { "method": "bank_account", "bank_account": { "clabe": "012298026516924616", "holder_name": "John Doe" }, "amount": 1050.50, "description": "Monthly payment" }; openpay.payouts.create(payout, function(error, payout, response) {}); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the payout. - **status** (string) - The current status of the payout. #### Response Example ```json { "id": "po_abc123", "status": "PENDING" } ``` ``` -------------------------------- ### List Subscriptions with Search Parameters (JavaScript) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Lists subscriptions, allowing for filtering by creation date, limit, and offset. Supports date range queries for the 'creation' field. ```javascript var searchParams = { 'creation': 'yyyy-mm-dd', 'limit': 10, 'offset': 1 }; openpay.customers.subscriptions.list( searchParams, function (error, body, response) { // ... }); ``` -------------------------------- ### Update Existing Customer Information (JavaScript) Source: https://context7.com/open-pay/openpay-node/llms.txt Provides an example of updating an existing customer's details by their ID. The function requires the customer ID and an object containing the fields to be updated. ```javascript var customerId = 'cust_abc123'; var updateData = { "name": "John", "last_name": "Smith", "email": "john.smith@example.com", "phone_number": "5544332211" }; openpay.customers.update(customerId, updateData, function(error, customer, response) { if (error) { console.error('Error updating customer:', error); return; } console.log('Customer updated:', customer); }); ``` -------------------------------- ### Get Subscription Details with OpenPay Node.js Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves the details of a specific customer subscription. Requires both the customer ID and subscription ID. Returns subscription status and next charge date, or an error. ```javascript var customerId = 'cust_abc123'; var subscriptionId = 'sub_xyz789'; openpay.customers.subscriptions.get(customerId, subscriptionId, function(error, subscription, response) { if (error) { console.error('Error fetching subscription:', error); return; } console.log('Subscription status:', subscription.status); console.log('Next charge date:', subscription.charge_date); }); ``` -------------------------------- ### Plans API Source: https://context7.com/open-pay/openpay-node/llms.txt APIs for retrieving, updating, listing, and deleting subscription plans. ```APIDOC ## Get Plan ### Description Retrieves details for a specific subscription plan. ### Method GET ### Endpoint `/plans/{planId}` ### Parameters #### Path Parameters - **planId** (string) - Required - The ID of the plan to retrieve. ### Request Example ```javascript var planId = 'plan_abc123'; openpay.plans.get(planId, function(error, plan, response) { ... }); ``` ### Response #### Success Response (200) - **plan** (object) - Contains the details of the retrieved plan. #### Response Example ```json { "id": "plan_abc123", "name": "Basic Monthly", "amount": 1000, "currency": "MXN", "interval_unit": "month", "interval_count": 1, "trial_days": 7 } ``` ## Update Plan ### Description Updates an existing subscription plan's properties. ### Method PUT ### Endpoint `/plans/{planId}` ### Parameters #### Path Parameters - **planId** (string) - Required - The ID of the plan to update. #### Request Body - **name** (string) - Optional - The new name for the plan. - **trial_days** (integer) - Optional - The new number of trial days for the plan. ### Request Example ```javascript var planId = 'plan_abc123'; var updateData = { "name": "Premium Monthly v2", "trial_days": 14 }; openpay.plans.update(planId, updateData, function(error, plan, response) { ... }); ``` ### Response #### Success Response (200) - **plan** (object) - Contains the updated details of the plan. #### Response Example ```json { "id": "plan_abc123", "name": "Premium Monthly v2", "amount": 1000, "currency": "MXN", "interval_unit": "month", "interval_count": 1, "trial_days": 14 } ``` ## List Plans ### Description Retrieves a list of all subscription plans, with optional filtering and pagination. ### Method GET ### Endpoint `/plans` ### Parameters #### Query Parameters - **creation[gte]** (string) - Optional - Filter plans created on or after this date (YYYY-MM-DD). - **limit** (integer) - Optional - The maximum number of plans to return (default 10). - **offset** (integer) - Optional - The number of plans to skip (default 0). ### Request Example ```javascript var searchParams = { "creation[gte]": "2023-01-01", "limit": 50, "offset": 0 }; openpay.plans.list(searchParams, function(error, plans, response) { ... }); ``` ### Response #### Success Response (200) - **plans** (array) - An array of plan objects. #### Response Example ```json [ { "id": "plan_abc123", "name": "Basic Monthly", "amount": 1000, "currency": "MXN" }, { "id": "plan_def456", "name": "Premium Monthly", "amount": 2000, "currency": "MXN" } ] ``` ## Delete Plan ### Description Removes a subscription plan. This action is irreversible. ### Method DELETE ### Endpoint `/plans/{planId}` ### Parameters #### Path Parameters - **planId** (string) - Required - The ID of the plan to delete. ### Request Example ```javascript var planId = 'plan_abc123'; openpay.plans.delete(planId, function(error, body, response) { ... }); ``` ### Response #### Success Response (200) - **body** (object) - Confirmation of deletion. #### Response Example ```json { "message": "Plan deleted successfully" } ``` ``` -------------------------------- ### Create Bank Account Source: https://context7.com/open-pay/openpay-node/llms.txt Registers a bank account for a customer. ```APIDOC ## Create Bank Account ### Description Registers a bank account for a specific customer, enabling payouts to this account. ### Method POST ### Endpoint /v1/customers/{customer_id}/bankaccounts ### Parameters #### Path Parameters - **customer_id** (string) - Required - The ID of the customer to associate the bank account with. #### Request Body - **clabe** (string) - Required - The CLABE of the bank account. - **holder_name** (string) - Required - The name of the account holder. - **alias** (string) - Optional - An alias for the bank account. ### Request Example ```javascript var customerId = 'cust_abc123'; var bankAccount = { "clabe": "111111111111111111", "holder_name": "Juan Hernandez", "alias": "Primary Account" }; openpay.customers.bankaccounts.create(customerId, bankAccount, function(error, account, response) {}); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created bank account. #### Response Example ```json { "id": "bank_xyz789" } ``` ``` -------------------------------- ### Get Charge Details (Node.js) Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves detailed information about a specific charge transaction using its ID. This is useful for checking the status, amount, and other attributes of a past transaction. Requires the charge ID. ```javascript var chargeId = 'tr_abc123xyz'; openpay.charges.get(chargeId, function(error, charge, response) { if (error) { console.error('Error fetching charge:', error); return; } console.log('Charge status:', charge.status); console.log('Amount:', charge.amount); console.log('Created at:', charge.creation_date); }); ``` -------------------------------- ### Create a New Customer Record (JavaScript) Source: https://context7.com/open-pay/openpay-node/llms.txt Shows how to create a new customer in Openpay by providing their contact and address details. The function expects a customer object as input and returns the created customer's ID upon success. ```javascript var newCustomer = { "name": "John", "last_name": "Doe", "email": "johndoe@example.com", "phone_number": "44209087654", "address": { "city": "Queretaro", "state": "Queretaro", "line1": "Calle Morelos no 10", "line2": "col. san pablo", "postal_code": "76000", "country_code": "MX" } }; openpay.customers.create(newCustomer, function(error, customer, response) { if (error) { console.error('Error creating customer:', error); return; } console.log('Customer created:', customer.id); // Response: { id: 'cust_abc123', name: 'John', ... } }); ``` -------------------------------- ### Create Store Charge Source: https://context7.com/open-pay/openpay-node/llms.txt Generates a payment reference for charges to be paid in cash at participating convenience stores. Includes customer details and payment information. ```APIDOC ## POST /charges ### Description Creates a charge reference for cash payment at convenience stores. ### Method POST ### Endpoint `/charges` ### Parameters #### Request Body - **method** (string) - Required - Payment method, must be 'store'. - **amount** (number) - Required - The charge amount. - **description** (string) - Optional - A description for the charge. - **order_id** (string) - Optional - Your internal order ID. - **customer** (object) - Optional - Customer details: - **name** (string) - Required if customer object is present. - **last_name** (string) - Required if customer object is present. - **phone_number** (string) - Optional. - **email** (string) - Optional. ### Request Example ```json { "method": "store", "amount": 500.00, "description": "Order payment #12345", "order_id": "oid-12345", "customer": { "name": "Cliente Mexico", "last_name": "Vazquez Juarez", "phone_number": "4448936475", "email": "cliente@empresa.mx" } } ``` ### Response #### Success Response (200) - **payment_method** (object) - Details about the payment method: - **reference** (string) - The payment reference number. - **barcode_url** (string) - URL to the payment barcode. #### Response Example ```json { "payment_method": { "reference": "REF123456789", "barcode_url": "https://example.com/barcode/REF123456789" } } ``` ``` -------------------------------- ### Create OpenPay Checkout with Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a new checkout for a specified customer. Requires customer ID and checkout details including amount, currency, description, redirect URL, order ID, and email sending preference. ```javascript 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) { // ... }); ``` -------------------------------- ### Get Merchant Account Information Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves the merchant account information using the Openpay Node.js SDK. This function does not require any specific input parameters. It returns the merchant's ID and balance upon successful retrieval. ```javascript openpay.merchant.get(function(error, merchant, response) { if (error) { console.error('Error fetching merchant info:', error); return; } console.log('Merchant ID:', merchant.id); console.log('Balance:', merchant.balance); }); ``` -------------------------------- ### Get Payout Details (JavaScript) Source: https://context7.com/open-pay/openpay-node/llms.txt Retrieves detailed information about a specific payout using its unique ID. This is useful for checking the status and details of a past or pending payout. The `openpay.payouts.get` method is employed, and the payout status and amount are logged. ```javascript var payoutId = 'po_abc123'; openpay.payouts.get(payoutId, function(error, payout, response) { if (error) { console.error('Error fetching payout:', error); return; } console.log('Payout status:', payout.status); console.log('Amount:', payout.amount); }); ``` -------------------------------- ### Create Subscription Plan (JavaScript) Source: https://context7.com/open-pay/openpay-node/llms.txt Creates a new subscription plan for recurring billing. This involves defining the plan's amount, name, repetition interval, trial period, and retry settings. The `openpay.plans.create` method is used, and the created plan's ID and name are logged. ```javascript var newPlan = { "amount": 150.00, "status_after_retry": "CANCELLED", "retry_times": 2, "name": "Premium Monthly", "repeat_unit": "month", "trial_days": 30, "repeat_every": 1 }; openpay.plans.create(newPlan, function(error, plan, response) { if (error) { console.error('Error creating plan:', error); return; } console.log('Plan created:', plan.id); console.log('Plan name:', plan.name); }); ``` -------------------------------- ### Create Customer Bank Account in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Shows how to create a bank account associated with a customer in Openpay using the Node.js library. It requires the customer ID and bank account details like CLABE, holder name, and an alias. ```javascript var customerId = 'customer ID'; var newBankAccount = { "clabe": "111111111111111111", "holder_name": "Juan H", "alias": "Alias" }; openpay.customers.bankaccounts.create( customerId, newBankAccount, function (error, body, response) { // ... }); ``` -------------------------------- ### Stores API Source: https://github.com/open-pay/openpay-node/blob/master/README.md APIs for managing store locations. ```APIDOC ## GET /stores ### Description Lists stores based on location parameters. ### Method GET ### Endpoint /stores ### Parameters #### Query Parameters - **latitud** (number) - Required - The latitude of the location. - **longitud** (number) - Required - The longitude of the location. - **kilometers** (number) - Required - The radius in kilometers to search for stores. - **amount** (number) - Optional - Filter stores by a minimum amount. ### Request Example ```json { "latitud": 4.65589142889691, "longitud": -74.11335673251888, "kilometers": 10, "amount": 1 } ``` ### Response #### Success Response (200) - **stores** (array) - A list of store objects. #### Response Example (Response structure depends on the store details) ``` -------------------------------- ### Create Card for Customer in Node.js Source: https://github.com/open-pay/openpay-node/blob/master/README.md Demonstrates how to create a card associated with an existing customer using the Openpay Node.js library. This method requires the customer ID and the card details. ```javascript 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) { // ... }); ``` -------------------------------- ### Customers API Source: https://github.com/open-pay/openpay-node/blob/master/README.md APIs for creating, retrieving, updating, deleting, and listing customers. ```APIDOC ## POST /customers ### Description Creates a new customer. ### Method POST ### Endpoint /customers ### Parameters #### Request Body - **external_id** (string) - Optional - An external ID for the customer. - **name** (string) - Required - The customer's first name. - **last_name** (string) - Required - The customer's last name. - **email** (string) - Required - The customer's email address. - **phone_number** (string) - Required - The customer's phone number. - **customer_address** (object) - Optional - The customer's address. - **department** (string) - Required - **city** (string) - Required - **additional** (string) - Required ### Request Example ```json { "external_id" : "", "name": "Pedro Diego", "last_name": "Alatorre Martínez", "email": "pedro.alatorre@comercio.com", "phone_number" : "5744484951", "customer_address": { "department":"Medellín", "city":"Antioquía", "additional":"Avenida 7f bis # 138-58 Apartamento 942" } } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created customer. #### Response Example ```json { "id": "cus_exampleid" } ``` ``` ```APIDOC ## PUT /customers/{customerId} ### Description Updates an existing customer. ### Method PUT ### Endpoint /customers/{customerId} ### Parameters #### Path Parameters - **customerId** (string) - Required - The ID of the customer to update. #### Request Body - **name** (string) - Optional - The customer's first name. - **last_name** (string) - Optional - The customer's last name. - **email** (string) - Optional - The customer's email address. - **phone_number** (string) - Optional - The customer's phone number. - **customer_address** (object) - Optional - The customer's address. - **department** (string) - Required - **city** (string) - Required - **additional** (string) - Required ### Request Example ```json { "name": "Pedro Diego", "last_name": "Alatorre Martínez", "email": "pedro.alatorre@comercio.com", "phone_number": "5744484951", "customer_address": { "department": "Medellín", "city": "Antioquía", "additional": "Avenida 7f bis # 138-58 Apartamento 942" } } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the updated customer. #### Response Example ```json { "id": "cus_exampleid" } ``` ``` ```APIDOC ## GET /customers/{customerId} ### Description Retrieves details of a specific customer. ### Method GET ### Endpoint /customers/{customerId} ### Parameters #### Path Parameters - **customerId** (string) - Required - The ID of the customer to retrieve. ### Response #### Success Response (200) - **id** (string) - The ID of the customer. - **name** (string) - The customer's first name. - **email** (string) - The customer's email address. #### Response Example ```json { "id": "cus_exampleid", "name": "Pedro Diego", "email": "pedro.alatorre@comercio.com" } ``` ``` ```APIDOC ## DELETE /customers/{customerId} ### Description Deletes a customer. ### Method DELETE ### Endpoint /customers/{customerId} ### Parameters #### Path Parameters - **customerId** (string) - Required - The ID of the customer to delete. ### Response #### Success Response (200) - **id** (string) - The ID of the deleted customer. - **deleted** (boolean) - Indicates if the customer was deleted. #### Response Example ```json { "id": "cus_exampleid", "deleted": true } ``` ``` ```APIDOC ## GET /customers ### Description Lists customers, optionally filtered by various parameters. ### Method GET ### Endpoint /customers ### Parameters #### Query Parameters - **external_id** (string) - Optional - Filter by external ID. - **creation** (string) - Optional - Filter by creation date (e.g., 'yyyy-mm-dd'). - **creation[gte]** (string) - Optional - Filter customers created after the given date. - **creation[lte]** (string) - Optional - Filter customers created before the given date. - **offset** (number) - Optional - The number of customers to skip. - **limit** (number) - Optional - The maximum number of customers to return. ### Request Example ```json { "external_id": "External ID", "creation": "yyyy-mm-dd", "offset": 1, "limit": 1 } ``` ### Response #### Success Response (200) - **list** (array) - An array of customer objects. #### Response Example ```json { "list": [ { "id": "cus_exampleid", "name": "Pedro Diego", "email": "pedro.alatorre@comercio.com" } ] } ``` ``` -------------------------------- ### Create a Store Charge (Node.js) Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a charge using the 'store' method, associated with a customer. Requires a device session ID, which can be null. ```javascript 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) { // ... }); ``` -------------------------------- ### Create OpenPay Customer Source: https://github.com/open-pay/openpay-node/blob/master/README.md Creates a new customer with their personal and address information. Requires a customer object containing name, last name, email, phone number, and a detailed address object. ```javascript var newCustomer = { "name": "Juan", "last_name": "Perez", "email": "juan.perez.@email.com", "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) { // ... }); ```