hugojose39 / omnipay-cielo-teste
Cielo 支付处理库的驱动程序
v0.0.6
2024-02-02 16:48 UTC
Requires
- omnipay/common: ^3.0
Requires (Dev)
- omnipay/tests: ^4.1
README
本节文档旨在开发库、测试和可能的问题。如果您只关注使用库,请单击此处 CieloTest。
下载源代码的 zip 文件,或者如果您已安装 Git,请使用 git clone 命令。选择最适合您需求的选项 - HTTPS、SSH、GitHub CLI。以下是为开发环境配置的设置。
使用的技术
- PHP
- Composer
- GIT
- Omnipay Common
- Omnipay Tests
开始
要开始使用库进行开发,您需要配置以下内容
- PHP: 确保您的系统已安装 PHP 并可用。您可以通过运行以下命令来检查 PHP 是否已安装
$ php --version
- Composer: 确保您的系统已安装 Composer 并可用。您可以通过运行以下命令来检查 Composer 是否已安装
$ composer --version
克隆项目
选择以下选项之一或下载 zip 格式的项目
$ HTTPS - git clone https://github.com/hugojose39/omnipay-cielo-teste.git $ SSH - git clone git@github.com:hugojose39/omnipay-cielo-teste.git $ GitHub CLI - gh repo clone hugojose39/omnipay-cielo-teste
当项目在您的计算机上时,打开其文件夹并在终端中执行命令
- 以下命令使用 Composer 自动化安装项目的依赖项
$ ./build composer install
- 以下命令执行所有可用测试
$ ./build composer test
- 如果您想单独运行测试,复制相对路径并提供它,例如
$ ./build composer test tests/Message/PurchaseRequestTest.php
可能的问题
在配置和使用库的过程中,请注意以下可能的问题
- 尝试在没有预先安装 PHP 的情况下使用 Composer。
- 在没有预先安装 Git 的情况下克隆项目。
- 在项目目录外执行 Composer 命令。
- 在没有使用前缀 "./build" 的情况下执行 Composer 命令。
- 尝试使用错误的路径执行单个测试。
注意:所有类,包括测试,都有注释说明其功能。
按照这些步骤,您将正确安装库代码,依赖项和测试将适当地执行。
如果在配置过程中出现问题,请检查所有依赖项是否正确安装,以及是否正确遵循了所有步骤。
现在您已经了解了库背后的代码,您可以在 Packagist 上查看它:omnipay-cielo-teste
最后,您可以根据以下步骤在 Laravel 项目中使用它。
Omnipay: Cielo
PHP 5.3+ 的 Omnipay 支付网关库的 Cielo 支持
Omnipay 是一个独立的支付网关库,用于处理 PHP 5.3+ 的结构化支付。本包实现了 Omnipay 的 Cielo 支持。
安装
通过 Composer
$ composer require hugojose39/omnipay-cielo-teste
基本用法
本包提供以下网关
有关使用说明,请参阅 Omnipay 主仓库。
使用信用卡进行授权交易的示例
// Crie um gateway para o Cielo Gateway // (rotas para GatewayFactory::create) $gateway = Omnipay::create('CieloTest'); // Inicialize o gateway $gateway->initialize([ 'merchantId' => 'MyMerchantId', 'merchantKey' => 'MyMerchantKey', ]); // Crie um objeto de cartão // Ele será usado nos testes $card = [ 'CardNumber' =>'4024007197692931', 'Holder' =>'Teste Holder', 'ExpirationDate' =>'12/2030', 'SecurityCode' =>'123', 'Brand' =>'Visa' ]; // Crie um objeto de cliente // Ele será usado nos testes $customer = [ 'Name' => 'Comprador Teste Cartão de crédito', 'Identity' => '1234567890', 'Address' => [ 'Street' => 'Avenida Marechal Câmara', 'Number' => '160', 'Complement' => 'Sala 934', 'ZipCode' => '22750012', 'District' => 'Centro', 'City' => 'Rio de Janeiro', 'State' => 'RJ', 'Country' => 'BRA' ], ]; // Faça uma transação autorizada no gateway $transaction = $gateway->authorize([ 'merchant_order_id'=> '123456', 'amount' => '10.00', 'soft_descriptor' => 'test', 'payment_method' => 'CreditCard', 'installments' => 5, 'card' => $card, 'customer' => $customer ]); $response = $transaction->send(); if ($response->isSuccessful()) { echo "Transação autorizada com sucesso!\n"; $saleId = $response->getTransactionReference(); $customerData = $response->getCustomerReference(); $cardData = $response->getCardReference(); } else { return $response->getMessage(); }
使用银行汇票进行授权交易的示例
// Crie um gateway para o Cielo Gateway // (rotas para GatewayFactory::create) $gateway = Omnipay::create('CieloTest'); // Inicialize o gateway $gateway->initialize([ 'merchantId' => 'MyMerchantId', 'merchantKey' => 'MyMerchantKey', ]); // Crie um objeto de cliente // Ele será usado nos testes $customer = [ 'Name' => 'Comprador Teste Boleto', 'Identity' => '1234567890', 'Address' => [ 'Street' => 'Avenida Marechal Câmara', 'Number' => '160', 'Complement' => 'Sala 934', 'ZipCode' => '22750012', 'District' => 'Centro', 'City' => 'Rio de Janeiro', 'State' => 'RJ', 'Country' => 'BRA' ], ]; // Faça uma transação autorizada no gateway $transaction = $gateway->authorize([ 'merchant_order_id'=> '123456', 'amount' => '10.00', 'provider' => 'Bradesco', 'payment_method' => 'Boleto', 'customer' => $customer ]); $response = $transaction->send(); if ($response->isSuccessful()) { echo "Transação autorizada com sucesso!\n"; $saleId = $response->getTransactionReference(); $customerData = $response->getCustomerReference(); $boletoData = $response->getBoleto(); } else { return $response->getMessage(); }
使用信用卡进行交易的示例
// Crie um gateway para o Cielo Gateway // (rotas para GatewayFactory::create) $gateway = Omnipay::create('CieloTest'); // Inicialize o gateway $gateway->initialize([ 'merchantId' => 'MyMerchantId', 'merchantKey' => 'MyMerchantKey', ]); // Crie um objeto de cartão // Ele será usado nos testes $card = [ 'CardNumber' =>'4024007197692931', 'Holder' =>'Teste Holder', 'ExpirationDate' =>'12/2030', 'SecurityCode' =>'123', 'Brand' =>'Visa' ]; // Crie um objeto de cliente // Ele será usado nos testes $customer = [ 'Name' => 'Comprador Teste Cartão de crédito', 'Identity' => '1234567890', 'Address' => [ 'Street' => 'Avenida Marechal Câmara', 'Number' => '160', 'Complement' => 'Sala 934', 'ZipCode' => '22750012', 'District' => 'Centro', 'City' => 'Rio de Janeiro', 'State' => 'RJ', 'Country' => 'BRA' ], ]; // Faça uma transação no gateway $transaction = $gateway->purchase([ 'merchant_order_id'=> '123456', 'amount' => '10.00', 'soft_descriptor' => 'test', 'payment_method' => 'CreditCard', 'installments' => 5, 'card' => $card, 'customer' => $customer ]); $response = $transaction->send(); if ($response->isSuccessful()) { echo "Transação efetuada com sucesso!\n"; $saleId = $response->getTransactionReference(); $customerData = $response->getCustomerReference(); $cardData = $response->getCardReference(); } else { return $response->getMessage(); }
使用银行汇票进行交易的示例
// Crie um gateway para o Cielo Gateway // (rotas para GatewayFactory::create) $gateway = Omnipay::create('CieloTest'); // Inicialize o gateway $gateway->initialize([ 'merchantId' => 'MyMerchantId', 'merchantKey' => 'MyMerchantKey', ]); // Crie um objeto de cliente // Ele será usado nos testes $customer = [ 'Name' => 'Comprador Teste Boleto', 'Identity' => '1234567890', 'Address' => [ 'Street' => 'Avenida Marechal Câmara', 'Number' => '160', 'Complement' => 'Sala 934', 'ZipCode' => '22750012', 'District' => 'Centro', 'City' => 'Rio de Janeiro', 'State' => 'RJ', 'Country' => 'BRA' ], ]; // Faça uma transação autorizada no gateway $transaction = $gateway->purchase([ 'merchant_order_id'=> '123456', 'amount' => '10.00', 'provider' => 'Bradesco', 'payment_method' => 'Boleto', 'customer' => $customer ]); $response = $transaction->send(); if ($response->isSuccessful()) { echo "Transação efetuada com sucesso!\n"; $saleId = $response->getTransactionReference(); $customerData = $response->getCustomerReference(); $boletoData = $response->getBoleto(); } else { return $response->getMessage(); }
交易捕获示例
// Crie um gateway para o Cielo Gateway // (rotas para GatewayFactory::create) $gateway = Omnipay::create('CieloTest'); // Inicialize o gateway $gateway->initialize([ 'merchantId' => 'MyMerchantId', 'merchantKey' => 'MyMerchantKey', ]); // Capture uma transação no gateway $transaction = $gateway->capture([ 'amount' => '10.00', 'transactionReference' => '123456', ]); $response = $transaction->send(); if ($response->isSuccessful()) { echo "Transação capturada com sucesso!\n"; $saleId = $response->getTransactionReference(); } else { return $response->getMessage(); }
信用卡令牌化示例
// Crie um gateway para o Cielo Gateway // (rotas para GatewayFactory::create) $gateway = Omnipay::create('CieloTest'); // Inicialize o gateway $gateway->initialize([ 'merchantId' => 'MyMerchantId', 'merchantKey' => 'MyMerchantKey', ]); // Capture uma transação no gateway $transaction = $gateway->createTokenCard([ 'card' => [ 'CustomerName' => 'Comprador Teste Cielo', 'CardNumber' => '4024007197692931', 'Holder' => 'Comprador T Cielo', 'ExpirationDate' => '12/2030', 'Brand' => 'Visa', ], ]); $response = $transaction->send(); if ($response->isSuccessful()) { echo "Token criado com sucesso!\n"; $cardData = $response->getCardReference(); } else { return $response->getMessage(); }
测试模式
要使用Cielo API的不同模式,例如测试或生产,重要的是要知道每个环境都有不同的端点。在初始化网关时,您可以通过将testMode参数设置为true来配置测试模式。这允许您连接到测试端点,确保交易在一个受控的环境中发生,以便于开发和调试。
许可证
本项目采用MIT许可证。