stone-pagamentos/stone-ecommerce-php

Stone Pagamentos PHP 库

v1.3.5 2016-02-26 20:01 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:35 UTC


README

Latest Stable Version License Build Status

入门

简单的PHP SDK,便于与Stone支付解决方案集成

安装

安装此SDK有两种方式,以下章节将指导您进行手动安装和使用composer。

手动安装

require __DIR__ . '/stone-ecommerce-php/init.php';

Composer

$ composer require stone-pagamentos/stone-ecommerce-php

运行测试

要运行测试,您需要克隆此存储库

$ git clone git@github.com:stone-payments/stone-ecommerce-php.git
$ cd stone-ecommerce-php
$ composer install
$ vendor/bin/phpunit

使用示例

try
{
    // Carrega dependências
    require_once(dirname(__FILE__) . '/vendor/autoload.php');

    // Define a url utilizada
    \Gateway\ApiClient::setBaseUrl("https://transaction.stone.com.br");

    // Define a chave da loja
    \Gateway\ApiClient::setMerchantKey("merchant key");

    // Cria objeto requisição
    $createSaleRequest = new \Gateway\One\DataContract\Request\CreateSaleRequest();

    // Cria objeto do cartão de crédito
    $creditCard = \Gateway\One\Helper\CreditCardHelper::createCreditCard("5555 4444 3333 2222", "gateway", "12/2030", "999");

    // Define dados do pedido
    $createSaleRequest->addCreditCardTransaction()
        ->setPaymentMethodCode(\Gateway\One\DataContract\Enum\PaymentMethodEnum::SIMULATOR)
        ->setCreditCardOperation(\Gateway\One\DataContract\Enum\CreditCardOperationEnum::AUTH_AND_CAPTURE)
        ->setAmountInCents(150000)
        ->setCreditCard($creditCard);
        ;

    // Cria um objeto ApiClient
    $apiClient = new \Gateway\ApiClient();

    // Faz a chamada para criação
    $response = $apiClient->createSale($createSaleRequest);

    // Mapeia resposta
    $httpStatusCode = $response->isSuccess() ? 201 : 401;
    $response = array("message" => $response->getData()->CreditCardTransactionResultCollection[0]->AcquirerMessage);
}
catch (\Gateway\One\DataContract\Report\CreditCardError $error)
{
    $httpStatusCode = 400;
    $response = array("message" => $error->getMessage());
}
catch (\Gateway\One\DataContract\Report\ApiError $error)
{
    $httpStatusCode = $error->errorCollection->ErrorItemCollection[0]->ErrorCode;
    $response = array("message" => $error->errorCollection->ErrorItemCollection[0]->Description);
}
catch (\Exception $ex)
{
    $httpStatusCode = 500;
    $response = array("message" => "Ocorreu um erro inesperado.");
}
finally
{
    // Devolve resposta
    http_response_code($httpStatusCode);
    header('Content-Type: application/json');
    print json_encode($response);
}

模拟值

您可以使用这些值从API获取特定响应

授权

  • <= $ 1.050,00 -> 已授权
  • >= $ 1.050,01 && < $ 1.051,71 -> 超时
  • >= $ 1.500,00 -> 未授权

捕获

  • <= $ 1.050,00 -> 已捕获
  • >= $ 1.050,01 -> 未捕获

取消

  • <= $ 1.050,00 -> 已取消
  • >= $ 1.050,01 -> 未取消

退款

  • <= $ 1.050,00 -> 已退款
  • >= $ 1.050,01 -> 未退款

版本

有关所有版本的列表,请参阅版本页面

更多信息

有关更多信息,请参阅我们的wiki