NetPay PHP SDK

Los pasos para integrar los productos de Checkout Hosted o Checkout Custom con el SDK de NetPay, se detallan a continuación:

1. Requerimientos.

  • PHP 5.4.0 o superior.

2. Instalación.

  • Descarga la última versión disponible del SDK para PHP del siguiente enlace https://github.com/netpaymx/netpay-php/releases, solo en caso de no requerir composer.
  • Para usar bindings, incluir el archivo "init.php", independientemente del poducto a integrar.

3. Uso.

3.1. Hosted Checkout.

<?php
require_once('../../init.php');

use \NetPay\NetPayConfig;

define('TEST_MODE', true);
define('PRIVATE_KEY', 'sk_netpay_lyNzonHFhwqoMHXfMFmOILqgZjAAjUVOjisfSkikPkrDA');

NetPayConfig::init(TEST_MODE);

try {
    $billing = array(
        'billing_city' => 'Panuco',
        'billing_country' => 'MX',
        'billing_first_name' => 'Jhon',
        'billing_last_name' => 'Doe',
        'billing_email' => '[email protected]',
        'billing_phone' => '8461234567',
        'billing_postcode' => '93994',
        'billing_state' => 'Veracruz',
        'billing_address_1' => 'Zona Centro 123',
        'billing_address_2' => 'Col Centro',
        'reference' => '12345',
    );
    $shipping = array( //opcional, este atrbuto puede ser omitido para productos virtuales.
        'shipping_city' => 'city',
        'shipping_country' => 'MX',
        'shipping_first_name' => 'Name',
        'shipping_last_name' => 'Last',
        'shipping_phone' => '0987654321',
        'shipping_postcode' => '66478',
        'shipping_state' => 'state',
        'shipping_address_1' => 'address1',
        'shipping_address_2' => 'address2',
        'shipping_method' => 'flat',
    );
    $lineItems[] = array(
        'name' => 'CELAZU128GB',
        'amount' => '7500.00',
        'quantity' => '1',
        'currency' => 'MXN',
    );
    $data = array(
        'successUrl' => 'http://example.com/success',
        'cancelUrl' => 'http://example.com/cancel',
        'customerEmail' => '[email protected]',
        'customerName' => 'Felipe Castillo Rendon',
        'paymentMethodTypes' => ["card","cep"],
        'merchantRefCode' => '13217327321',
        'lineItems' => $lineItems,
        "billing" => \NetPay\NetPayBill::format($billing),
        "shipping" => \NetPay\NetPayShip::format($shipping),
        'linkType' => 'NETPAY_CHECKOUT'
    );
    $hosted = \NetPay\Api\NetPayHostedCheckout::post(PRIVATE_KEY, $data);
    echo '<pre>'.json_encode($hosted, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES).'</pre>';
} catch (Exception $e) {
    $description = $e->getMessage();
    echo $description;
}
?>

3.2. Custom Checkout.

🚧

Recuerda que para generar el token...

Debes cargar el formulario predeterminado de NetPay, o bien, construir tu propio formulario utilizando las herramientas que otorga nuestro CDN. Para más información, por favor visite https://docs.netpay.com.mx/reference/1-tokenizar-tarjeta-con-o-sin-formulario-propio

<?php
require_once('../../init.php');

use \NetPay\NetPayConfig;

define('TEST_MODE', true);
define('PRIVATE_KEY', 'sk_netpay_lyNzonHFhwqoMHXfMFmOILqgZjAAjUVOjisfSkikPkrDA');

NetPayConfig::init(TEST_MODE);

try {
    $installments = 3; //null=no MSI, 3=3 MSI, 6=6 MSI, 9=9 MSI, 12=12 MSI, 18=18 MSI
    $billing = array(
        'billing_city' => 'Panuco',
        'billing_country' => 'MX',
        'billing_first_name' => 'Jhon',
        'billing_last_name' => 'Doe',
        'billing_email' => '[email protected]',
        'billing_phone' => '8461234567',
        'billing_postcode' => '93994',
        'billing_state' => 'Veracruz',
        'billing_address_1' => 'Zona Centro 123',
        'billing_address_2' => 'Col Centro',
        'reference' => '12345',
    );
    $shipping = array( //optional, for virtual products it must be empty
        'shipping_city' => 'city',
        'shipping_country' => 'MX',
        'shipping_first_name' => 'Name',
        'shipping_last_name' => 'Last',
        'shipping_phone' => '0987654321',
        'shipping_postcode' => '66478',
        'shipping_state' => 'state',
        'shipping_address_1' => 'address1',
        'shipping_address_2' => 'address2',
        'shipping_method' => 'flat',
    );
    $data = array(
        'description' => 'Cobro de colegiatura',
        'source' => 'token_AyRPMSxsOpIsEaoYywLQEQyrccUVrRLzoaPNrsic',
        'amount' => 300,
        "billing" => \NetPay\NetPayBill::format($billing),
        "shipping" => \NetPay\NetPayShip::format($shipping),
        'redirect3dsUri' => 'https://netpay.mx'
    );

    $checkout = \NetPay\Api\NetPayCheckout::post(PRIVATE_KEY, $data, $installments);
    print_r($checkout);
} catch (Exception $e) {
    $description = $e->getMessage();
    echo $description;
}
?>