REST API Advanced uses examples

Adapt Khipu to your more specific needs

Send a charge email

We will show you what’s needed before you start

Merchant integrators

How to create a charging account to receive payments

Refund a payment not rendered

Understanding the different security aspects

Create a Charge and distribute it using your URL

Learn how to make a payment

Charge with authentication

The user personal ID is used

Distribute charge URL

The charge you created can be used wherever you want

Delete a payment

In some occasions it’s necessary to delete a generated charge

1.- Send a charge email

You can make Khipu automatically send an email with the charge generated, only a couple fields must be filled. Only a couple fields must be filled:

  • payer_name: The name of the person that must pay.
  • payer_email: The email of the payer.
  • send_email: if “true” Khipu will send the payment request by email.

It’s important to note a few things:

  • If “send_email” is “true”, both (payer_name and payer_email) are required.
  • The content of the “body” field is not sent in the email. It will be displayed in the payment page.
  • If, in addition to sending “true” in the “send_email” field, you also send “true” in the “send_reminders” field, besides the initial collection email, two other reminder emails will be sent (one week apart), if the charge has not been paid or eliminated.
Sample code:

 

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
$configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $opts = array(
        "payer_name" => "John Connor",
        "payer_email" => "jconnor@the-future.com",
        "send_email" => true,
        "send_reminders" => true,
    );
    $response = $payments->paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , $opts
    );

    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, 'secret-key');
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);

Map<String, Object> options = new HashMap<>();
options.put("sendEmail", true);
options.put("sendReminders", true);
options.put("payerEmail", "juan.pagador@correo.com");
options.put("payerName", "Juan Pagador");

PaymentsCreateResponse response = paymentsApi.paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , "MTI-100" //Identificador de la transacción en el comercio
        , options
);

System.out.println(response);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new

response = client.payments_post('Skynet', 'CLP', 1000, {
    payer_name: 'John Connor',
    payer_email: 'jconnor@the-future.com',
    send_email: true,
    send_reminders: true,
})
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();
try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , sendEmail: true
                        , sendReminders: true
                        , payerEmail: "juan.pagador@correo.com"
                        , payerName: "Juan Pagador");
    System.Console.WriteLine(response);
}
catch (ApiException e)
{
    Console.WriteLine(e);
}

2.- Create a charge and distribute it using your URL

 

You can have Khipu create a link of the charge you generate to be used wherever you like. Only a couple fields must be filled:

  • payer_name: The name of the person that must pay.
  • payer_email: The email of the payer.
  • send_email: “false”. (Use true if you want a Khipu email to be sent with the charge).
  • body: text to be displayed in the payment page.

It’s important to note a few things:

The content of the “body” field is not sent in the email. Is only displayed in the payment page. If send_email is “true”, you can send true in the “send_reminders” parameter. When doing so, Khipu will send 2 payment reminders. One a week after the charge and the other one a week later.

Sample code:
<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
$configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $opts = array(
        "payer_name" => "John Connor",
        "payer_email" => "jconnor@the-future.com",
        "send_email" => false,
        "send_reminders" => fale,
    );
    $response = $payments->paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , $opts
    );

    $paymentUrl = $response->getPaymentUrl(); // URL de cobro

    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, 'secret-key');
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);

Map<String, Object> options = new HashMap<>();
options.put("sendEmail", false);
options.put("sendReminders", false);
options.put("payerEmail", "juan.pagador@correo.com");
options.put("payerName", "Juan Pagador");

PaymentsCreateResponse response = paymentsApi.paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , "MTI-100" //Identificador de la transacción en el comercio
        , options
);

String paymentUrl = response.getPaymentUrl(); // URL de cobro

System.out.println(response);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new

response = client.payments_post('Skynet', 'CLP', 1000, {
    payer_name: 'John Connor',
    payer_email: 'jconnor@the-future.com',
    send_email: false,
    send_reminders: false,
})

paymentUrl = response[:'payment_url'] # URL de cobro
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();
try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , sendEmail: true
                        , sendReminders: true
                        , payerEmail: "juan.pagador@correo.com"
                        , payerName: "Juan Pagador");

    paymentUrl = response.paymentUrl; // URL de cobro

    System.Console.WriteLine(response);
}
catch (ApiException e)
{
    Console.WriteLine(e);
}

3.- Create a charge with expiration date

Many times, a charge should only be valid up to a certain date, for example, paying for a ticket to an event (after the event it doesn’t make much sense to pay it). For this we can specify a maximum payment date or expiration date. After this date the payment can’t be paid.

The maximum date for a payment is sent in the “expires_date” parameter. This date has some conditions:

  • It must be greater than the day the charge is generated and less than that moment plus 10 years.
  • • If the call is done directly using the POST method, the date must be in the ISO 8601 format.

Even if the expiration date is not sent, the payment will be generated with a date. In the case of an email request (when “send_email” is “true”) it will be 60 days from the moment of creation. If it is not a charge request, then the term will be one day.

Let’s see the following code to create a payment using the expiration date:

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $expires_date = new DateTime();
    $expires_date->setDate(2019, 4, 4);

    $opts = array(
        "expires_date" => $expires_date
    );

    $response = $payments->paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , $opts
    );

    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);
Calendar calendar = Calendar.getInstance();
calendar.set(2019,Calendar.APRIL,4);

Map<String, Object> options = new HashMap<>();
options.put("expiresDate", calendar.getTime());

PaymentsCreateResponse response = paymentsApi.paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , options
);

System.out.println(response);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new

response = client.payments_post('Ejemplo con fecha de expiración', 'CLP', 1000, {
    expires_date: DateTime.new(2016, 4, 4)
})

print response
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

try
{
    DateTime dt = DateTime.Now;
    dt = dt.AddDays(5);
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , expiresDate: dt);
    System.Console.WriteLine(response);
}
catch (ApiException e)
{
    Console.WriteLine(e);
}

4.- Send merchant info for conciliation purposes

Khipu charges have a variable called “custom”, where information of any kind can be stored. This information can be recovered at any time, for example when we receive the web service notification from Khipu.

Let’s see an example in which we create a charge using XML that has the content of the shopping cart of an online store:

 

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {

    $xml = "
<items>
  <item>
    <name>Compra 1</name>
  </item>
  <item>
    <name>Compra 2</name>
  </item>
</items>
";

    $opts = array(
        "custom" => $xml
    );

    $response = $payments->paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , $opts
    );
    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);

String xml = "<items>n" +
        "   <item>n" +
        "       <name>Compra 1</name>n" +
        "   </item>n" +
        "   <item>n" +
        "       <name>Compra 2</name>n" +
        "   </item>n" +
        "</items>";

PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);

Map<String, Object> options = new HashMap<>();
options.put("custom", xml);

PaymentsCreateResponse response = paymentsApi.paymentsPost("Compra de prueba de la API" //Motivo de la compra
        , "CLP" //Moneda
        , 100.0 //Monto
        , options
);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

xml = '
<items>
  <item>
    <name>Compra 1</name>
  </item>
  <item>
    <name>Compra 2</name>
  </item>
</items>
'

client = Khipu::PaymentsApi.new
response = client.payments_post('Prueba de cobro', 'CLP', 1000, {custom: xml})
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

string xml = "<items><item><name>Compra 1</name></item><item><name>Compra 2</name></item></items>";

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , custom: xml);
    System.Console.WriteLine(response);
}
catch (ApiException e)
{
    Console.WriteLine(e);
}

 

We will be able to retrieve the XML information using the “notification_token” that Khipu sends us when reconciling the payment.

5.- Delete a payment before the payer finishes

In certain occasions it is necessary to delete a charge that has been generated, for example, if we run out of stock or if we found a problem to deliver the product/service. To delete a charge, it must not have been paid or marked as paid.

To delete a generated charge, we only need its identifier. Let’s see a sample code:

 

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $response = $payments->paymentsPost('Prueba de cobro', 'CLP', 1000);
    $response = $payments->paymentsIdDelete($response->getPaymentId());
    print_r($response);

} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);
PaymentsCreateResponse response = paymentsApi.paymentsPost("Prueba de cobro", "CLP", 1000d);

System.out.println(paymentsApi.paymentsIdDelete(response.getPaymentId()));
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new
response = client.payments_post('Prueba de cobro', 'CLP', 1000, {})
print client.payments_id_delete(response.payment_id)
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0);

    System.Console.WriteLine(response);

    SuccessResponse deleteResponse = a.PaymentsIdDelete(response.PaymentId);
}
catch (ApiException e)
{
    Console.WriteLine(e);
}

6.- Merchant integrators

An integrator is a collector on Khipu that can create collectors for its customers and collect for them using Khipu. For example, an integrator could be a company that provides online store services to several merchants, each merchant creates an online store in that service and using the same service creates a charging account in Khipu and collects payments online. The Khipu service allows the end merchants to charge for their products and the merchant integrator to charge a fee for its service.

We will call the “child” charging account to each regular charging account associated with the integrator charging account. This is very important when sending credentials on each call.

Creating a “child” charging account

These accounts are created using a special call. This call will return the credentials of a new charging account. We must save these credentials to be able to generate charges on behalf of the new account.

In this call we must send the following data:

  • E-mail and name of the owner of the account. If the email already exists in Khipu the existing user will be used. If not, a new user will be created, and the account will be associated to it.
  • Country of the account: The country where the account will operate.
  • Billing data: Data needed to issue a ticket or invoice.
  • Contact information: Information so that Khipu can contact the administrator of the charging account

It is very important to consider that this account is not ready to charge. The creation process sends an e-mail so that the owner of the account (the e-mail owner) can complete the payment process. Once this process is completed the account will begin to operate.

It is also very important to remember that the call to create a charging account must be made with the credentials of the parent account. The calls to generate the charges must be made with the credentials of the child accounts.

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret($secret);
$configuration->setReceiverId($receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$receivers = new KhipuClientReceiversApi(new KhipuApiClient($configuration));

try {
    $response = $receivers->receiversPost('Pablo'
        , 'Pereira'
        , 'pablo@micomercio.com'
        , 'CL'
        , '123456789'
        , 'Varios'
        , 'Mi comercio'
        , '+565555555'
        , 'Mi dirección'
        , 'Mi ciudad'
        , 'Mi región'
        , 'Juan Perez'
        , 'encargado de contacto'
        ,  'contacto@micomercio.com'
        , '+566666666');
    print_r($response);

} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, secret);
ReceiversApi receiversApi = new ReceiversApi();
receiversApi.setApiClient(apiClient);

ReceiversCreateResponse response =  receiversApi.receiversPost(
        "Pablo"
        , "Pereira"
        , "pablo@micomercio.com"
        , "CL"
        , "123456789"
        , "Varios"
        , "Mi comercio"
        , "+565555555"
        , "Mi dirección"
        , "Mi ciudad"
        , "Mi región"
        , "Juan Perez"
        , "encargado de contacto"
        , "contacto@micomercio.com"
        , "+566666666");

System.out.println(response);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = secret
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  #c.debugging = true
end

client = Khipu::ReceiversApi.new

response = client.receivers_post('Pablo',
                                 'Pereira',
                                 'pablo@micomercio.com',
                                 'CL', '123456789',
                                 'Varios',
                                 'Mi comercio',
                                 '+565555555',
                                 'Mi dirección',
                                 'Mi ciudad',
                                 'Mi región',
                                 'Juan Perez',
                                 'encargado de contacto',
                                 'contacto@micomercio.com',
                                 '+566666666')

 

Creating a charge with a commission for the merchant integrator is like creating a normal charge, with only two minor details:

  • A “integrator_fee” parameter with the amount to be received by the integrator must be sent. This amount can’t be greater than the original amount minus Khipu’s commission.
  • The credentials that are used for the call must be the credentials of the “child” account. This is because the charge must remain in the name of this account.

The following is a sample code:

 

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $opts = array(
        "integrator_fee" => 10
    );
    $response = $payments->paymentsPost('Prueba de cobro', 'CLP', 1000, $opts);
    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);

Map<String, Object> options = new HashMap<>();
options.put("integratorFee", 10d);

PaymentsCreateResponse response = paymentsApi.paymentsPost("Prueba de cobro", "CLP", 1000d, options);

System.out.println(response);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new
response = client.payments_post('Prueba de cobro', 'CLP', 1000, {integrator_fee: 10})
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , integratorFee: 10.0);

    System.Console.WriteLine(response);

}
catch (ApiException e)
{
    Console.WriteLine(e);
}

In this example we create a 1000 charge. Of those 1000, 10 will be given to the integrator of the “child”.

7.- Modify the user owner of a charge

 
Each charge in Khipu has a “responsible_user” assoaciated which is the owner of the charge. He/she receives copy of the payment voucher and the weekly reminders. If you are using the Khipu interface, the responsible user is always the one who creates the payment. If more than one person has access to the merchant’s charging account, you can specify the owner of each charge created using the API.

To specify a user as the owner of a charge, the user must be able to collect using the merchant’s account.

Let’s look at the following sample code:

 

<?php
$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $opts = array(
        "responsible_user_email" => "jconnor@the-future.com"
    );
    $response = $payments->paymentsPost('Prueba de cobro', 'CLP', 1000, $opts);
    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);

PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);

Map<String, Object> options = new HashMap<>();
options.put("responsibleUserEmail", "jconnor@the-future.com");

PaymentsCreateResponse response = paymentsApi.paymentsPost("Prueba de cobro", "CLP", 1000d, options);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new
response = client.payments_post('Prueba de cobro', 'CLP', 1000, {responsible_user_email: 'jconnor@the-future.com'})
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , responsibleUserEmail: : "jconnor@the-future.com");

    System.Console.WriteLine(response);

}
catch (ApiException e)
{
    Console.WriteLine(e);
}

8.- Charge with authentication

 
It is possible to create charges that can only be paid using a bank account that belongs to a particular individual or company. This is done specifying the user’s personal identifier. For example, a bank account in Chile is associated with a RUT number. If a particular RUT is specified for a charge, it can only be paid using an account associated with that RUT.

Let’s see an example:

 

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $opts = array(
      "fixed_payer_personal_identifier" => "12.345.678-9"
    );
    $response = $payments->paymentsPost('Prueba de cobro', 'CLP', 1000, $opts);
    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);

Map<String, Object> options = new HashMap<>();
options.put("fixedPayerPersonalIdentifier", "12.345.678-9");

PaymentsCreateResponse response = paymentsApi.paymentsPost("Prueba de cobro", "CLP", 1000d, options);
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new
response = client.payments_post('Prueba de cobro', 'CLP', 1000, {fixed_payer_personal_identifier: '12.345.678-9'})
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Compra de prueba de la API", "CLP", 100.0
                        , fixedPayerPersonalIdentifier: "12.345.678-9");

    System.Console.WriteLine(response);

}
catch (ApiException e)
{
    Console.WriteLine(e);
}

9.- Refund a payment not rendered

 
In the time interval between the payment being made and that Khipu hasn’t released the funds to the merchant, it is possible to refund the payment, the customer will receive an email explaining that the merchant has not been able to complete the transaction and that the funds will be returned to your bank account.

Let’s see an example:

 

<?php
require __DIR__ . '/vendor/autoload.php';

$configuration = new KhipuConfiguration();
$configuration->setSecret('secret-key');
$configuration->setReceiverId(receiver_id);
$configuration->setPlatform('demo-client', '2.0');
# $configuration->setDebug(true);

$client = new KhipuApiClient($configuration);
$payments = new KhipuClientPaymentsApi($client);

try {
    $payments->paymentsIdRefundsPost("id-del-pago");
    print_r($response);
} catch (KhipuApiException $e) {
    echo print_r($e->getResponseBody(), TRUE);
}
ApiClient apiClient = new ApiClient();
apiClient.setKhipuCredentials(receiverId, "secret-key");
apiClient.setPlatform("demo-client", "2.0");
// apiClient.setDebugging(true);
PaymentsApi paymentsApi = new PaymentsApi();
paymentsApi.setApiClient(apiClient);
paymentsApi.paymentsIdRefundsPost("id-del-pago");
require 'khipu-api-client'

Khipu.configure do |c|
  c.secret = 'secret-key'
  c.receiver_id = receiver_id
  c.platform = 'demo-client'
  c.platform_version = '2.0'
  # c.debugging = true
end

client = Khipu::PaymentsApi.new
response = client.payments_id_refunds_post('id-del-pago'})
Configuration.ReceiverId = obtener-al-crear-una-cuenta-de-cobro;
Configuration.Secret = "obtener-al-crear-una-cuenta-de-cobro";
PaymentsApi a = new PaymentsApi();

try
{
    SuccessResponse response = a.PaymentsIdRefundsPost("id-del-pago");

    System.Console.WriteLine(response);

}
catch (ApiException e)
{
    Console.WriteLine(e);
}

10.- Receiving and validating rendition notification via web service

Khipu allows you to receive notifications in your web site automatically with the detail of each rendition made to the current account associated with the charging account.

Settings:

To receive notifications, you must first log into your Khipu account and go to “Account Options”. In the Instant Rendition Notification, you must add the URL where your web site will “listen” the notifications and define the notification API version you will be using.

Example in PHP

Rendition notifications are made using a JOSE JWS standard message and gzip envelope.

The rendition notification messages are signed with the following certificate.

Download the public certificate

If you are using a development charge account, you must use the Khipu development certificate.

Download the public key certificate (development)

In this example the Namshi/Jose library is used:

<?php
require_once 'vendor/autoload.php';

use NamshiJOSEJWS;

$jws_text=gzdecode($HTTP_RAW_POST_DATA);

$jws=JWS::load($jws_text);

// Leemos el certificado con la clave publica
$filename = 'khipu_signer.pem';
$fp = fopen($filename, "r");
$cert = fread($fp, filesize($filename));
fclose($fp);
$pubkey = openssl_get_publickey($cert);

$payload = $jws->getPayload();

if ($jws->isValid($public_key)) {
/*
   Si la firma del mensaje es valida se puede procesar el mensaje
*/

    $report=$payload['report'];
    $fecha_desde=$report['startDate']; // fecha de inicio de la rendición
    $fecha_hasta=$report['endDate']; //fecha de termino de la rendición
    $report_items=$report['items']; //pagos incluidos en la rendición
    foreach($report_items as $item){
       $customer=$item['customer']; //datos del pagador
       local_process($item['paymentDate'],       //fecha del pago
                     $item['paymentSubject'],    //asunto del pago
                     $item['khOperationCodeUID'],//código único de operación khipu
                     $item['merchantTxID'],      //id de transacción informado por el comercio
                     $item['customer']['customerName'], //nombre del pagador
                     $item['customer']['customerUID'],  //rut del pagador
                     $item['customer']['customerEmail'],//correo electrónico del pagador
                     $item['customer']['customerBankName'], //nombre del banco origen
                     $item['feeScheme'], //esquema de comisión
                     $item['txAmount'],  //monto de la transacción
                     $item['khipuFee']); //comisión khipu
    }
}

Chile Address: Las Urbinas 53 oficina 132, Providencia, Santiago, Chile. Postal code 7510093

Argentina Address: Besares 1029, Chacras de Coria, Mendoza, Argentina. Postal code 5505.