tradeupgroup/gateway

Gateway的PHP SDK

dev-master 2019-10-09 19:25 UTC

This package is auto-updated.

Last update: 2024-09-10 07:06:39 UTC


README

支付方式

  • 信用卡
  • 借记卡
  • Paypal Plus
  • Paypal Express Checkout
  • Pagseguro
  • 银行汇票(Bradesco Shop Fácil和Itaú Shopline)
  • 银行电子转账(Itaú Shopline)

可用资源

  • 分期付款
  • 计划支付(周期性支付)
  • 反欺诈分析
  • 卡号token化

信用卡(示例)

 namespace Gateway\API;

    include_once "autoload.php";

    use Exception as Exception;

    try {
        $credential = new Credential("1", "d41d8cd12300b204e9800998ecf8427e", Environment::SANDBOX);
        $gateway = new Gateway($credential);

        ### CREATE A NEW TRANSACTION
        $transaction = new Transaction();

        // Set ORDER
        $transaction->Order()
            ->setReference("ss")
            ->setTotalAmount(1000);

        // Set PAYMENT
        $transaction->Payment()
            ->setAcquirer(Acquirers::CIELO_V3)
            ->setMethod(Methods::CREDIT_CARD_INTEREST_BY_ISSUER)
            ->setCurrency(Currency::BRAZIL_BRAZILIAN_REAL_BRL)
            ->setCountry("BRA")
            ->setNumberOfPayments(2)
            ->setSoftDescriptor("Bruno paz")
            ->Card()
                ->setBrand(Brand::VISA)
                ->setCardHolder("Bruno paz")
                ->setCardNumber("2223000148400010")
                ->setCardSecurityCode("123")
                ->setCardExpirationDate("202001");

        // SET CUSTOMER
        $transaction->Customer()
            ->setCustomerIdentity("999999999")
            ->setName("Bruno")
            ->setCpf("30212212212")
            ->setEmail("brunopaz@test.com");

        // SET FRAUD DATA OBJECT
        $transaction->FraudData()
            ->setName("Bruno Paz")
            ->setDocument("30683882828")
            ->setEmail("brunopaz@g.com")
            ->setAddress("Rua test")
            ->setAddress2("Apartamento 23")
            ->setAddressNumber("300")
            ->setPostalCode("08742350")
            ->setCity("São Paulo")
            ->setState("SP")
            ->setCountry("BRASIL")
            ->setPhonePrefix("11")
            ->setPhoneNumber("99999-9999")
            ->setDevice("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36")
            ->setCostumerIP("192.168.0.1")
            ->setItems([
                ["productName" => "Iphone X", "quantity" => 1, "price" => "20.00"],
                ["productName" => "Iphone XL", "quantity" => 12, "price" => "1220.00"]
            ]);

        // Set URL RETURN
        $transaction->setUrlReturn("http://127.0.0.1:8989/return.php");

        // PROCESS - ACTION
        #$response = $gateway->sale($transaction);
        $response = $gateway->authorize($transaction);

        // REDIRECT IF NECESSARY (Debit uses)
        if ($response->isRedirect()) {
            $response->redirect();
        }

        // RESULTED
        if ($response->isAuthorized()) { // Action Authorized
            print "<br>RESULTED: " . $response->getStatus();
        } else { // Action Unauthorized
            print "<br>RESULTED:" . $response->getStatus();
        }

        // CAPTURE
        if ($response->canCapture()) {
            $response = $gateway->Capture($response->getTransactionID());
            print "<br>CAPTURED: " . $response->getStatus();
        }
        // CANCELL
        if ($response->canCancel()) {
            $response = $gateway->Cancel($response->getTransactionID());
            print "<br>CANCELED: " . $response->getStatus();
        }

        // REPORT
        $response = $gateway->Report($response->getTransactionID());
        print "<br>REPORTING: " . $response->getStatus();

    } catch (Exception $e) {
        print_r($e->getMessage());
    }

访问凭证

$credential = new Credential("{MERCHANTID}", "{MERCHANTKEY}", Environment::SANDBOX);

身份验证

$gateway = new Gateway($credential);

可用环境

创建新的支付交易

$transaction = new Transaction();

通知一个订单

  • setReference用作订单的参考
  • setTotalAmount必须是分(centavos)
// Set ORDER
$transaction->Order()
            ->setReference("Pedido123")
            ->setTotalAmount(1000);

通知买家信息

  • setCustomerIdentity用作买家的参考(必须是唯一的)
$transaction->Customer()
    ->setCustomerIdentity("999999999")
    ->setName("Bruno")
    ->setCpf("30212212212")
    ->setEmail("bruno@brunopaz.com");

通知支付方式

  • setAcquirer定义要使用的运营商,请查看下表
  • setMethod定义要处理的支付方式,请查看下表
  • setNumberOfPayments定义分期付款(用于信用卡)
  • setSoftDescriptor是要显示在买家信用卡账单上的文本
// Set PAYMENT
$transaction->Payment()
    ->setAcquirer(Acquirers::CIELO_V3)
    ->setMethod(Methods::CREDIT_CARD_INTEREST_BY_ISSUER)
    ->setCurrency(Currency::BRAZIL_BRAZILIAN_REAL_BRL)
    ->setCountry("BRA")
    ->setNumberOfPayments(2)
    ->setSoftDescriptor("Bruno paz")
    ->Card()
            ->setBrand(Brand::VISA)
            ->setCardHolder("Bruno paz")
            ->setCardNumber("2223000148400010")
            ->setCardSecurityCode("123")
            ->setCardExpirationDate("202001");

通知返回URL

返回URL用于接收POST并完成支付操作后重定向用户

// Set URL RETURN
$transaction->setUrlReturn("http://127.0.0.1:8989/return.php");

金融操作类型

授权(预授权)

$response = $gateway->Authorize($transaction);

直接销售(授权)

$response = $gateway->Sale($transaction);

捕获

$response = $gateway->Capture("{TransactionID}");

取消(取消 | 无效)

$response = $gateway->sale("{TransactionID}");

银行转账

$response = $gateway->OnlineTransfer($transaction);

银行汇票(支付银行汇票)

$response = $gateway->Boleto($transaction);

Paypal

$response = $gateway->Paypal($transaction);

计划支付(周期性支付)

$response = $gateway->Rebill($transaction);

运营商代码

卡品牌代码

支付方式

其他支付方式示例