Manage billing statements with API
In this section, learn how to create and manage billing statements using PayRex API. Manage customers, create a billing statement, and send it.
Managing billing statements via API is best if you want to embed the workflow within your internal system or the platform you currently use. If you prefer to use our Dashboard to manage billing statements, please refer to the no-code section.
If you want to learn about the general overview of billing statements, you can refer to this link.
1. Set up the server-side
Install one of the server-side SDKs and initialize with your secret API key
Install the appropriate SDK depending on your programming language and import it. If we don't support yet the programming language you're using, you may skip this step and use your preferred REST client.
- Node via npm
- PHP via composer
- Python via pip
- Ruby via gem
npm install payrex-node
composer install payrex/payrex-php
pip install payrex-python
gem install payrex-ruby
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
const customer = await payrex.customers.create({
currency: 'PHP',
name: 'Juan Dela Cruz',
email: 'juandelacruz@gmail.com'
})
// Create a billing statement
const billingStatement = await payrex.billingStatements.create({
customer_id: customer.id,
payment_settings: {
payment_methods: ['gcash', 'card']
}
});
// some lines of code are removed...
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
$customer = $payrex->customers->create([
'currency' => 'PHP',
'name' => 'Juan Dela Cruz',
'email' => 'juan@gmail.com'
]);
// Create a billing statement
$billingStatement = $payrex->billingStatements->create([
'customer_id' => $customer->id,
'payment_settings' => [
'payment_methods' => ['gcash', 'card']
]
]);
// some lines of code are removed...
from payrex import Client as PayrexClient
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
{
'currency': 'PHP',
'name': 'Juan Dela Cruz',
'email': 'juan@gmail.com'
}
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
{
'customer_id': customer.id,
'payment_settings': {
'payment_methods': ['gcash', 'card']
}
}
)
# some lines of code are removed...
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
currency: "PHP",
name: "Juan Dela Cruz",
email: "juan@gmail.com"
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
customer_id: customer.id,
payment_settings: {
payment_methods: ["gcash", "card"]
}
)
# some lines of code are removed...
Create a customer resource or retrieve an existing one
A customer resource represents the customer that will pay the billing statement. If you haven't created a customer resource, create one and you can store its ID for future purchases. If a customer resource already exists, use its ID when creating a draft billing statement.
A customer resource represents the customer that will pay the billing statement. If you haven't created a customer resource, create one, and you can store its ID for future purchases. If a customer resource exists, use its ID when creating a draft billing statement.
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
// If a customer doesn't exist, create it first.
const customer = await payrex.customers.create({
currency: 'PHP',
name: 'Juan Dela Cruz',
email: 'juandelacruz@gmail.com'
})
// OR
// Retrieve the customer via ID if it already exists
const customer = await payrex.customers.retrieve('cus_xxxxx')
// OR
// Retrieve the customer via metadata or email
const customers = await payrex.customers.list({
email: 'juandelacruz@gmail.com'
})
// Create a billing statement
const billingStatement = await payrex.billingStatements.create({
customer_id: customer.id,
payment_settings: {
payment_methods: ['gcash', 'card']
}
});
// some lines of code are removed...
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
$customer = $payrex->customers->create([
'currency' => 'PHP',
'name' => 'Juan Dela Cruz',
'email' => 'juan@gmail.com'
]);
// OR
// Retrieve the customer via ID if it already exists
$customer = $payrex->customers->retrieve('cus_xxxxx');
// OR
// Retrieve the customer via metadata or email
$customers = $payrex->customers->list([
'email' => 'juandelacruz@gmail.com'
]);
// Create a billing statement
$billingStatement = $payrex->billingStatements->create([
'customer_id' => $customer->id,
'payment_settings' => [
'payment_methods' => ['gcash', 'card']
]
]);
// some lines of code are removed...
from payrex import Client as PayrexClient
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
{
'currency': 'PHP',
'name': 'Juan Dela Cruz',
'email': 'juan@gmail.com'
}
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
{
'email': 'juandelacruz@gmail.com'
}
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
{
'customer_id': customer.id,
'payment_settings': {
'payment_methods': ['gcash', 'card']
}
}
)
# some lines of code are removed...
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
currency: "PHP",
name: "Juan Dela Cruz",
email: "juan@gmail.com"
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
email: 'juandelacruz@gmail.com'
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
customer_id: customer.id,
payment_settings: {
payment_methods: ["gcash", "card"]
}
)
# some lines of code are removed...
Create a billing statement
Create a billing statement after a customer resource is created or retrieved. A billing statement has draft
status once created.
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
// If a customer doesn't exist, create it first.
const customer = await payrex.customers.create({
currency: 'PHP',
name: 'Juan Dela Cruz',
email: 'juandelacruz@gmail.com'
})
// OR
// Retrieve the customer via ID if it already exists
const customer = await payrex.customers.retrieve('cus_xxxxx')
// OR
// Retrieve the customer via metadata or email
const customers = await payrex.customers.list({
email: 'juandelacruz@gmail.com'
})
// Create a billing statement
const billingStatement = await payrex.billingStatements.create({
customer_id: customer.id,
payment_settings: {
payment_methods: ['gcash', 'card']
}
});
// some lines of code are removed...
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
$customer = $payrex->customers->create([
'currency' => 'PHP',
'name' => 'Juan Dela Cruz',
'email' => 'juan@gmail.com'
]);
// OR
// Retrieve the customer via ID if it already exists
$customer = $payrex->customers->retrieve('cus_xxxxx');
// OR
// Retrieve the customer via metadata or email
$customers = $payrex->customers->list([
'email' => 'juandelacruz@gmail.com'
]);
// Create a billing statement
$billingStatement = $payrex->billingStatements->create([
'customer_id' => $customer->id,
'payment_settings' => [
'payment_methods' => ['gcash', 'card']
]
]);
// some lines of code are removed...
from payrex import Client as PayrexClient
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
{
'currency': 'PHP',
'name': 'Juan Dela Cruz',
'email': 'juan@gmail.com'
}
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
{
'email': 'juandelacruz@gmail.com'
}
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
{
'customer_id': customer.id,
'payment_settings': {
'payment_methods': ['gcash', 'card']
}
}
)
# some lines of code are removed...
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
currency: "PHP",
name: "Juan Dela Cruz",
email: "juan@gmail.com"
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
email: 'juandelacruz@gmail.com'
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
customer_id: customer.id,
payment_settings: {
payment_methods: ["gcash", "card"]
}
)
# some lines of code are removed...
Complete the required details of a billing statement
After you create a draft
billing statement, you must update the required details before you can finalize it and send it to your customer.
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
// If a customer doesn't exist, create it first.
const customer = await payrex.customers.create({
currency: 'PHP',
name: 'Juan Dela Cruz',
email: 'juandelacruz@gmail.com'
})
// OR
// Retrieve the customer via ID if it already exists
const customer = await payrex.customers.retrieve('cus_xxxxx')
// OR
// Retrieve the customer via metadata or email
const customers = await payrex.customers.list({
email: 'juandelacruz@gmail.com'
})
// Create a billing statement
let billingStatement = await payrex.billingStatements.create({
customer_id: customer.id,
payment_settings: {
payment_methods: ['gcash', 'card']
}
});
billingStatement = await payrex.billingStatements.update(
billingStatement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
due_at: Math.floor((new Date()) / 1000)
}
)
// Create a single line item just to finalize the billing statement later.
await payrex.billingStatementLineItems.create(
{
billing_statement_id: billingStatement.id,
unit_price: 2000,
quantity: 1,
description: "My Product"
}
)
// some lines of code are removed...
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
$customer = $payrex->customers->create([
'currency' => 'PHP',
'name' => 'Juan Dela Cruz',
'email' => 'juan@gmail.com'
]);
// OR
// Retrieve the customer via ID if it already exists
$customer = $payrex->customers->retrieve('cus_xxxxx');
// OR
// Retrieve the customer via metadata or email
$customers = $payrex->customers->list([
'email' => 'juandelacruz@gmail.com'
]);
// Create a billing statement
$billingStatement = $payrex->billingStatements->create([
'customer_id' => $customer->id,
'payment_settings' => [
'payment_methods' => ['gcash', 'card']
]
]);
$billingStatement = $payrex->billingStatements->update(
$billingStatement->id,
[
// due_at is set to current epoch timestamp. You can set either past or future date
'due_at' => time()
]
);
// Create a single line item just to finalize the billing statement later.
$payrex->billingStatementLineItems->create(
[
'billing_statement_id' => $billingStatement->id,
'unit_price' => 2000,
'quantity' => 1,
'description' => "My Product"
]
);
// some lines of code are removed...
from payrex import Client as PayrexClient
import time
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
{
'currency': 'PHP',
'name': 'Juan Dela Cruz',
'email': 'juan@gmail.com'
}
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
{
'email': 'juandelacruz@gmail.com'
}
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
{
'customer_id': customer.id,
'payment_settings': {
'payment_methods': ['gcash', 'card']
}
}
)
billing_statement = payrex.billing_statements.update(
billing_statement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
'due_at': int(time.time())
}
)
// Create a single line item just to finalize the billing statement later.
payrex.billing_statement_line_items.create(
{
'billing_statement_id': billing_statement.id,
'unit_price': 2000,
'quantity': 1,
'description': "My Product"
}
)
# some lines of code are removed...
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
currency: "PHP",
name: "Juan Dela Cruz",
email: "juan@gmail.com"
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
email: 'juandelacruz@gmail.com'
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
customer_id: customer.id,
payment_settings: {
payment_methods: ["gcash", "card"]
}
)
billing_statement = payrex.billing_statements.update(
billing_statement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
due_at: Time.now.to_i
}
)
// Create a single line item just to finalize the billing statement later.
payrex.billing_statement_line_items.create(
{
billing_statement_id: billing_statement.id,
unit_price: 2000,
quantity: 1,
description: "My Product"
}
)
# some lines of code are removed...
Finalize a billing statement
Once the required details are filled out, you can finalize the billing statement. Once finalized, you cannot edit the details anymore, so make sure that the details are correct. If you need to edit the details, you must create a new billing statement.
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
// If a customer doesn't exist, create it first.
const customer = await payrex.customers.create({
currency: 'PHP',
name: 'Juan Dela Cruz',
email: 'juandelacruz@gmail.com'
})
// OR
// Retrieve the customer via ID if it already exists
const customer = await payrex.customers.retrieve('cus_xxxxx')
// OR
// Retrieve the customer via metadata or email
const customers = await payrex.customers.list({
email: 'juandelacruz@gmail.com'
})
// Create a billing statement
let billingStatement = await payrex.billingStatements.create({
customer_id: customer.id,
payment_settings: {
payment_methods: ['gcash', 'card']
}
});
billingStatement = await payrex.billingStatements.update(
billingStatement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
due_at: Math.floor((new Date()) / 1000)
}
)
// Create a single line item just to finalize the billing statement later.
await payrex.billingStatementLineItems.create(
{
unit_price: 2000,
quantity: 1,
description: "My Product"
}
)
billingStatement = await payrex.billingStatements.finalize(billingStatement.id)
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
$customer = $payrex->customers->create([
'currency' => 'PHP',
'name' => 'Juan Dela Cruz',
'email' => 'juan@gmail.com'
]);
// OR
// Retrieve the customer via ID if it already exists
$customer = $payrex->customers->retrieve('cus_xxxxx');
// OR
// Retrieve the customer via metadata or email
$customers = $payrex->customers->list([
'email' => 'juandelacruz@gmail.com'
]);
// Create a billing statement
$billingStatement = $payrex->billingStatements->create([
'customer_id' => $customer->id,
'payment_settings' => [
'payment_methods' => ['gcash', 'card']
]
]);
$billingStatement = $payrex->billingStatements->update(
$billingStatement->id,
[
// due_at is set to current epoch timestamp. You can set either past or future date
'due_at' => time()
]
);
// Create a single line item just to finalize the billing statement later.
$payrex->billingStatementLineItems->create(
[
'unit_price' => 2000,
'quantity' => 1,
'description' => "My Product"
]
);
$billingStatement = $payrex->billingStatements->finalize($billingStatement.id);
from payrex import Client as PayrexClient
import time
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
{
'currency': 'PHP',
'name': 'Juan Dela Cruz',
'email': 'juan@gmail.com'
}
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
{
'email': 'juandelacruz@gmail.com'
}
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
{
'customer_id': customer.id,
'payment_settings': {
'payment_methods': ['gcash', 'card']
}
}
)
billing_statement = payrex.billing_statements.update(
billing_statement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
'due_at': int(time.time())
}
)
# Create a single line item just to finalize the billing statement later.
payrex.billing_statement_line_items.create(
{
'unit_price': 2000,
'quantity': 1,
'description': "My Product"
}
)
billing_statement = payrex.billing_statements.finalize(billing_statement.id)
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
currency: "PHP",
name: "Juan Dela Cruz",
email: "juan@gmail.com"
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
email: 'juandelacruz@gmail.com'
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
customer_id: customer.id,
payment_settings: {
payment_methods: ["gcash", "card"]
}
)
billing_statement = payrex.billing_statements.update(
billing_statement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
due_at: Time.now.to_i
}
)
# Create a single line item just to finalize the billing statement later.
payrex.billing_statement_line_items.create(
{
unit_price: 2000,
quantity: 1,
description: "My Product"
}
)
billing_statement = payrex.billing_statements.finalize(billing_statement.id)
2. Send the billing statement to your customer
Once the billing statement is finalized, some details will be updated e.g. the billing statement's URL. You can now send the billing statement to your customer.
- Copy URL and send
- Via e-mail
The billing statement has a URL attribute where you can copy and send to your customer. You can send to any IMs such as Viber, messenger, etc.
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
// If a customer doesn't exist, create it first.
const customer = await payrex.customers.create({
currency: 'PHP',
name: 'Juan Dela Cruz',
email: 'juandelacruz@gmail.com'
})
// OR
// Retrieve the customer via ID if it already exists
const customer = await payrex.customers.retrieve('cus_xxxxx')
// OR
// Retrieve the customer via metadata or email
const customers = await payrex.customers.list({
email: 'juandelacruz@gmail.com'
})
// Create a billing statement
let billingStatement = await payrex.billingStatements.create({
customer_id: customer.id,
payment_settings: {
payment_methods: ['gcash', 'card']
}
});
billingStatement = await payrex.billingStatements.update(
billingStatement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
due_at: Math.floor((new Date()) / 1000)
}
)
// Create a single line item just to finalize the billing statement later.
await payrex.billingStatementLineItems.create(
{
unit_price: 2000,
quantity: 1,
description: "My Product"
}
)
billingStatement = await payrex.billingStatements.finalize(billingStatement.id)
await payrex.billingStatements.send(billingStatement.id)
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
// Create a customer. If you have an existing customer resource,
// you can use it instead of creating a new one.
$customer = $payrex->customers->create([
'currency' => 'PHP',
'name' => 'Juan Dela Cruz',
'email' => 'juan@gmail.com'
]);
// OR
// Retrieve the customer via ID if it already exists
$customer = $payrex->customers->retrieve('cus_xxxxx');
// OR
// Retrieve the customer via metadata or email
$customers = $payrex->customers->list([
'email' => 'juandelacruz@gmail.com'
]);
// Create a billing statement
$billingStatement = $payrex->billingStatements->create([
'customer_id' => $customer->id,
'payment_settings' => [
'payment_methods' => ['gcash', 'card']
]
]);
$billingStatement = $payrex->billingStatements->update(
$billingStatement->id,
[
// due_at is set to current epoch timestamp. You can set either past or future date
'due_at' => time()
]
);
// Create a single line item just to finalize the billing statement later.
$payrex->billingStatementLineItems->create(
[
'unit_price' => 2000,
'quantity' => 1,
'description' => "My Product"
]
);
$billingStatement = $payrex->billingStatements->finalize($billingStatement.id);
$billingStatement = $payrex->billingStatements->send($billingStatement.id);
from payrex import Client as PayrexClient
import time
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
{
'currency': 'PHP',
'name': 'Juan Dela Cruz',
'email': 'juan@gmail.com'
}
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
{
'email': 'juandelacruz@gmail.com'
}
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
{
'customer_id': customer.id,
'payment_settings': {
'payment_methods': ['gcash', 'card']
}
}
)
billing_statement = payrex.billing_statements.update(
billing_statement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
'due_at': int(time.time())
}
)
# Create a single line item just to finalize the billing statement later.
payrex.billing_statement_line_items.create(
{
'unit_price': 2000,
'quantity': 1,
'description': "My Product"
}
)
billing_statement = payrex.billing_statements.finalize(billing_statement.id)
payrex.billing_statements.send(billing_statement.id)
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
# Create a customer. If you have an existing customer resource,
# you can use it instead of creating a new one.
customer = payrex.customers.create(
currency: "PHP",
name: "Juan Dela Cruz",
email: "juan@gmail.com"
)
# OR
# Retrieve the customer via ID if it already exists
customer = payrex.customers.retrieve('cus_xxxxx')
# OR
# Retrieve the customer via metadata or email
customers = payrex.customers.list(
email: 'juandelacruz@gmail.com'
)
# Create a billing statement
billing_statement = payrex.billing_statements.create(
customer_id: customer.id,
payment_settings: {
payment_methods: ["gcash", "card"]
}
)
billing_statement = payrex.billing_statements.update(
billing_statement.id,
{
// due_at is set to current epoch timestamp. You can set either past or future date
due_at: Time.now.to_i
}
)
# Create a single line item just to finalize the billing statement later.
payrex.billing_statement_line_items.create(
{
unit_price: 2000,
quantity: 1,
description: "My Product"
}
)
billing_statement = payrex.billing_statements.finalize(billing_statement.id)
payrex.billing_statements.send(billing_statement.id)
3. Subscribe to your customer payments
The best way to monitor payments from your customers is through webhooks. You can create a webhook and subscribe to payment_intent.succeeded
event. A billing statement has a payment intent attribute you can reference from your webhook. If you don't know yet about payment intents, refer to this guide.
You can refer to this guide to know more about actions you can take after receiving a payment.
We will create billing_statement
related webhook events soon. In the meantime, you can refer to the payment_intent events to get notified about customer payments.
Voiding, marking as uncollectible and deleting billing statements [OPTIONAL]
You can call our APIs to automate voiding, marking as uncollectible, and deleting billing statements.
Voiding a billing statement
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
await payrex.billingStatements.void('<insert billing statement id>');
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
$billingStatement = $payrex->billingStatements->void('<insert billing statement id>');
from payrex import Client as PayrexClient
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
billing_statement = payrex.billing_statements.void('<insert billing statement id>')
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
billing_statement = payrex.billing_statements.void('<insert billing statement id>')
Mark uncollectible a billing statement
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
await payrex.billingStatements.markUncollectible('<insert billing statement id>');
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
$billingStatement = $payrex->billingStatements->markUncollectible('<insert billing statement id>');
from payrex import Client as PayrexClient
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
billing_statement = payrex.billing_statements.mark_uncollectible('<insert billing statement id>')
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
billing_statement = payrex.billing_statements.mark_uncollectible('<insert billing statement id>')
Delete a billing statement
- Node
- PHP
- Python
- Ruby
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
const payrexSecretApiKey = '';
const payrex = require('payrex-node')(payrexSecretApiKey);
await payrex.billingStatements.delete('<insert billing statement id>');
<?php
require_once '../vendor/autoload.php';
// Protect your PayRex Secret API key at all costs. One common approach
// to store it in an environment variable.
// Add your PayRex test secret API key.
$payrexSecretApiKey = '';
$payrex = new \Payrex\PayrexClient($payrexSecretApiKey);
$billingStatement = $payrex->billingStatements->delete('<insert billing statement id>');
from payrex import Client as PayrexClient
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ''
payrex = PayrexClient(payrex_secret_api_key)
billing_statement = payrex.billing_statements.delete('<insert billing statement id>')
require "payrex-ruby"
# Protect your PayRex Secret API key at all costs. One common approach
# to store it in an environment variable.
# Add your PayRex test secret API key.
payrex_secret_api_key = ""
payrex = Payrex::Client.new(payrex_secret_api_key)
billing_statement = payrex.billing_statements.delete('<insert billing statement id>')