csweb/bin-pagamentos

0.5.1 2020-10-08 00:50 UTC

This package is auto-updated.

Last update: 2024-09-08 09:39:15 UTC


README

测试

为了进行一些测试,需要使用数字证书。对于这个包,已经生成了几个自签名的证书,位于tests/fixtures/certs

证书private_key.pem的密码非常简单:123456

这些证书的有效期为4年。如果您想生成其他证书,请按照以下步骤操作:

# generate private key and enter pass phrase
openssl genrsa -des3 -out private_key.pem 2048

# create certificate signing request, enter "*.example.com" as a "Common Name", leave "challenge password" blank
openssl req -new -sha256 -key private_key.pem -out server.csr

# generate self-signed certificate for 1 year
openssl req -x509 -sha256 -days 365 -key private_key.pem -in server.csr -out server.pem

# validate the certificate
openssl req -in server.csr -text -noout | grep -i "Signature.*SHA256" && echo "All is well" || echo "This certificate doesn't work in 2017! You must update OpenSSL to generate a widely-compatible certificate"

创建新销售

要创建一个新销售,请按照以下步骤操作:

<?php

require_once __DIR__ . './vendor/autoload.php';

use CSWeb\BIN\Environment;
use CSWeb\BIN\Transactions\Sale;
use CSWeb\BIN\Bin;

$payload = [
    'CreditCardTxType' => [
        'Type' => 'sale'
    ],
    'CreditCardData'   => [
        'CardNumber'    => 411111111111,
        'ExpMonth'      => 12,
        'ExpYear'       => 30,
        'CardCodeValue' => 123
    ],
    'Payment' => [
        'NumberOfInstallments' => 1, // Opcional
        'ChargeTotal'          => 10.0,
        'Currency'             => 986 // REAL formato ISO
    ],
    'TransactionDetails' => [
        'OrderId',
        'TDate'
    ],
    'cardFunction' => 'credit'
];

$sale = new Sale($payload, 'v1');
$env  = new Environment('username', 'password', 'path/to/cert', 'path/to/key', 'ssl_key');

$bin = new Bin($env);

$response = $bin->send($sale);

取消销售

要取消销售,请执行以下操作:

<?php

require_once __DIR__ . './vendor/autoload.php';

use CSWeb\BIN\Environment;
use CSWeb\BIN\Transactions\RevokeSale;
use CSWeb\BIN\Bin;

$payload = [
    'CreditCardTxType'   => [
        'Type' => 'void'
    ],
    'TransactionDetails' => [
        'OrderId' => 1,
        'TDate'   => 1190244932
    ]
];

$sale = new RevokeSale($payload, 'v1');
$env  = new Environment('username', 'password', 'path/to/cert', 'path/to/key', 'ssl_key');

$bin = new Bin($env);

$response = $bin->send($sale);