Skip to content
Last updated

Sending a collection email

You can make Khipu automatically send an email with the payment you generate. All you need to do is fill in a couple of fields:

  • payer_name: It's the name of the person who needs to pay.
  • payer_email: It's the payer's email address.
  • send_email: If you send "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) will be mandatory.
  • The content of the body field is not sent in the email. It's only displayed on the payment page.
  • If, in addition to sending true in the send_email field, you also send true in the send_reminders field, in addition to the initial collection email, two reminder emails will be sent with a one-week separation between each one, as long as the collection has not been paid or deleted at the time of managing the reminder.

Example 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);
}

Create a collection and distribute it using its URL

You can make Khipu create a link for the payment you generate to be used wherever you want. All you need to do is fill in a couple of fields:

  • payer_name: It's the name of the person who needs to pay.
  • payer_email: It's the payer's email address.
  • send_email: false. (Use true if you also want to send an email from Khipu with the payment.)
  • body: Text that will be displayed on the payment page

It's important to note a few things:

  • The content of the body field is not sent in the email.
  • It's only displayed on the payment page.
  • If "send_email" is true, you can also send true in the send_reminders parameter. By doing this, Khipu will send 2 payment reminders. One a week after the collection, and another the second week after.
<?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);
}

Create a payment with expiration date

Often, a collection should only be valid until a particular date, for example, paying for an event ticket (after the event, it makes no sense to pay for it). For this purpose, we can specify a maximum payment date or expiration date. After this date, the payment cannot be canceled.

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

  • It must be greater than the current date and time when the collection is generated and must be less than that time plus 10 years.
  • If the call is made directly using the POST method, the date must be in ISO 8601 format.
  • Even if the expiration date is not sent, the payment will be generated with one. In the case of an email request (when send_email is true), it's 60 days from the creation moment. If it's not a collection request, then the deadline is one day.

Let's see the following code to create a payment using an 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);
}

Sending merchant information for use in reconciliation

Collections in Khipu have a variable called custom in which you can store information of any type. This information can be retrieved at any time, for example, when we receive the notification via web service from Khipu.

Let's see an example in which we create a collection with an XML containing the content of the shopping cart of a 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>Sample 1</name>
  </item>
  <item>
    <name>Sample 2</name>
  </item>
</items>
";

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

    $response = $payments->paymentsPost("Compra de prueba de la API" 
        , "CLP"
        , 100.0 
        , $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>Sample 1</name>n" +
        "   </item>n" +
        "   <item>n" +
        "       <name>Sample 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("Sample use of the API" 
        , "CLP"
        , 100.0 
        , 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('c payment', '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>Sample 1</name></item><item><name>Sample 2</name></item></items>";

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Sample use of the API", "CLP", 100.0
                        , custom: xml);
    System.Console.WriteLine(response);
}
catch (ApiException e)
{
    Console.WriteLine(e);
}

We can then retrieve information from XML using the notification_token sent by Khipu when reconciling the payment.

Delete a payment before the payer completes it

Sometimes it's necessary to delete a collection that has been generated, for example, if we run out of stock or encounter any issues in delivering the product/service. To delete a generated collection, it must not have been paid or marked as paid.

To delete a generated payment, we only need its identifier. Let's see an example 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('Sample payment', '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("Sample payment", "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('Sample payment', 'CLP', 1000, {})
print client.payments_id_delete(response.payment_id)
Configuration.ReceiverId = your-receiver-id;
Configuration.Secret = "your-secret";
PaymentsApi a = new PaymentsApi();

try
{
    PaymentsCreateResponse response = a.PaymentsPost("Sample payment", "CLP", 100.0);

    System.Console.WriteLine(response);

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

Integrator Merchants

An integrator is a collector in Khipu who has the ability to create collectors for their clients and collect payments on behalf of 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, using the same service to create a Khipu collection account and collect payments online. Khipu's service allows the final merchant to collect payment for their products and the integrator to collect a commission.

We will call each normal collection account associated with an integrator's collection account a child collection account. This is very important when you need to send credentials in each call.

Creating a child collection account for an integrator

Child accounts are created using a special call. This call will return the credentials of a new collection account. We must save these credentials to be able to generate collections on behalf of this new account.

In this call, we must provide the following data:

  • Owner's email and name for the account. If the email exists in Khipu, the existing user will be used. If not, a new user will be created and the account will be associated with them.
  • Country for the account: The country where the account will operate.
  • Billing information: Information to issue an invoice or receipt.
  • Contact information: Information for Khipu to contact the account administrator.

It's very important to know that this account is not ready to collect payments. The creation process sends an email to the indicated email address so that the account owner (the email owner) can verify their bank account. Only once this process is completed can the account start operating.

Remember
The call to create a collection account must be made with the credentials of the parent account. Calls to generate collections 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 an integrator fee is identical to creating a normal charge but with two details:

The integrator_fee parameter must be sent with the amount the integrator will receive. This amount cannot exceed the original amount minus Khipu's commission.

The credentials used for the call must be the credentials of the child account. This is because the charge must be made in the name of this account.

The following is an example 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 charge for 1000. Out of those 1000, 10 will be delivered to the integrator of the child account.

Modifying the Owner User of a Charge

Every charge in Khipu is associated with a "responsible user" who is the owner of the charge. They receive copies of payment receipts and weekly reminders. If the Khipu web interface is used, the responsible user is always the one who creates the charge. If more than one person has access to the merchant's collection account, you can specify using the API who the owner of each charge created is.

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

Let's see the following example 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);
}

Payment with authentication

It is possible to create payments that can only be paid using a bank account belonging to a specific person. This is done by specifying the personal identifier of the user. For example, a bank account in Chile is associated with a RUT (Unique Taxpayer Identification Number). If a specific RUT is specified for a payment, it can only be paid using an account associated with that RUT.

<?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);
}

Refunding a payment that has not been settled

t is possible to refund the charge until 1:00 am the following business day. The customer will receive an email explaining that the merchant was unable to complete the transaction and that the funds will be returned to the customer's bank account.

<?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);
}

Receiving and validating reconciliation notification via web service

Khipu enables automatic notifications on your website with the detail of each reconciliation made to the current account associated with your collection account.

Configuration:

To receive notifications, first, you must log in to your Khipu account and go to "Account Options." In the Instant Reconciliation Notification section, you must add the URL where your website will listen to notifications and define the version of the notification API you want to use.

PHP Example

Reconciliation notifications are sent using a message in standard JOSE JWS, and gzipped envelope.

The messages of the reconciliation notifications are signed with the following certificate.

Download public key certificate

If you are using a development collection account, you should use the Khipu development certificate.

Download public key certificate (development)

This example uses the Namshi/Jose library:

<?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
    }
}