netpaymx / netpay-php
NetPay PHP 库
2.0.1.2
2021-06-21 21:57 UTC
Requires
- php: >=5.4.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- php-coveralls/php-coveralls: 1.*
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2.0
- symfony/process: ~2.8
This package is auto-updated.
Last update: 2024-09-22 21:30:19 UTC
README
您可以在 https://manager.netpay.com.mx 上注册 NetPay 账户。
最低要求
PHP 5.4.0 及以上版本。
手动安装
如果您不想使用 Composer,您可以下载 最新版本。然后,为了使用绑定,包括 init.php
文件。
require_once('/path/to/netpay-php/init.php');
入门指南
令牌化: https://docs.netpay.com.mx/reference/sin-guardar-tarjeta#1-tokenizar-tarjeta-2
示例代码
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' => 'accept@netpay.com.mx', '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; }
文档
请参阅 https://docs.netpay.com.mx/reference/sin-guardar-tarjeta#31-pago-2 以获取最新文档。
自定义请求超时
注意:我们不建议降低非只读调用(例如创建收费)的超时时间,因为即使您在本地超时,NetPay 端的请求仍然可以完成。
文件 lib/NetPayConfig.php
//-- General settings const CURLOPT_TIMEOUT = 40; //Timeout in seconds
文件 lib/NetPay/Api/Curl.php
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, strlen($fields_string)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_ENCODING, "gzip, deflate"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::$CURLOPT_TIMEOUT); curl_setopt($ch, CURLOPT_TIMEOUT, Config::$CURLOPT_TIMEOUT);