mitchdav / st-george-ipg-laravel
Laravel 服务提供程序,用于 St.George IPG 库。
Requires
- illuminate/console: ^5.4
- illuminate/support: ^5.4
- mitchdav/st-george-ipg: ^1.0
- nesbot/carbon: ^1.22
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2023-08-24 13:00:52 UTC
README
St.George Internet Payment Gateway 的 Laravel 服务提供程序。
请参阅 mitchdav/st-george-ipg 包的 README 文件以了解基础包的安装。
安装
composer require mitchdav/st-george-ipg-laravel
一旦安装了库,请将以下服务提供程序添加到您的 config/app.php
文件中
StGeorgeIPG\Laravel\Provider::class,
如有需要,您还可以添加外观
'IPG' => StGeorgeIPG\Laravel\Facades\IPG::class,
您可以使用以下命令导出配置文件
php artisan vendor:publish --provider="StGeorgeIPG\Laravel\Provider"
配置
您首先需要在您的 .env
文件中定义以下环境变量
IPG_CLIENT_ID=
根据您是否设置了认证令牌(对于 WebService 提供程序是必需的,但对于 Extension 提供程序,只有在商户管理控制台中已设置的情况下才是必需的)
IPG_AUTHENTICATION_TOKEN=
您可以将系统设置为使用测试模式,以便所有交易都发送到 St.George IPG 测试服务器
IPG_TEST=TRUE
如果您使用的是 Extension 提供程序,则需要定义您的证书密码,以及可选的证书路径、日志文件和调试设置
IPG_CERTIFICATE_PASSWORD=
IPG_CERTIFICATE_PATH=
IPG_LOG_FILE=
IPG_DEBUG=TRUE
IPG_CERTIFICATE_PATH
和 IPG_LOG_FILE
都设置为合适的默认值,因此您可以保留这些为空,如果您愿意的话。
最后,检查或编辑 config/ipg.php
文件,该文件读取环境变量并为包填充配置。
<?php return [ /** * The provider to use to connect to St.George IPG. */ 'provider' => \StGeorgeIPG\Providers\WebService::class, /** * The client ID, issued by St.George. */ 'clientId' => env('IPG_CLIENT_ID'), /** * The authentication token, created in the St.George Merchant Administration Console. * * This is required for the WebService provider, and optional for the Extension provider. */ 'authenticationToken' => env('IPG_AUTHENTICATION_TOKEN'), /** * Whether to connect to the live or test environment. */ 'test' => env('IPG_TEST', FALSE), /** * Extension-specific configuration. */ 'extension' => [ /** * The certificate password, issued by St.George. */ 'certificatePassword' => env('IPG_CERTIFICATE_PASSWORD'), /** * The path to the certificate file that was issued by St.George. */ 'certificatePath' => env('IPG_CERTIFICATE_PATH', resource_path('webpay/cert.cert')), /** * Whether to debug the requests and responses. */ 'debug' => env('IPG_DEBUG', FALSE), /** * The log file path if debugging is enabled. */ 'logFile' => env('IPG_LOG_FILE', storage_path('logs/webpay/' . date('Y-m-d') . '.log')), ], ];
如果您想使用 Extension 提供程序,请将 provider
值更改为 \StGeorgeIPG\Providers\Extension::class
。
使用方法
该包提供了一种 客户端 和 外观,它们都使用 config/ipg.php
文件中的值进行配置。
然后您可以使用客户端与 mitchdav/st-george-ipg 包相同的方式进行。
向客户收费(购买)
use Carbon\Carbon; use StGeorgeIPG\Exceptions\ResponseCodes\Exception; use StGeorgeIPG\Laravel\IPG; //use StGeorgeIPG\Laravel\Facades\IPG; // Or this $oneYearAhead = (new Carbon())->addYear(); $amount = 10.00; // In dollars $cardNumber = '4111111111111111'; $month = $oneYearAhead->month; $year = $oneYearAhead->year; $purchaseRequest = IPG::purchase($amount, $cardNumber, $month, $year); try { $purchaseResponse = IPG::execute($purchaseRequest); echo 'The charge was successful.' . "\n"; } catch (Exception $ex) { echo 'The charge was unsuccessful.' . "\n"; echo $ex->getMessage() . "\n"; var_dump($purchaseRequest); var_dump($ex->getResponse()); }
其他
请参阅 mitchdav/st-george-ipg 包的使用指南。
命令
ipg:test-purchase {provider?} {cert?}
此命令允许您通过执行测试购买来测试您与 St.George IPG 服务器的连接。命令将指示提供程序使用测试服务器(无论您的配置如何),因此在生产环境中使用是安全的。
php artisan ipg:test-purchase
- 您可以选择告诉命令使用特定的提供程序,通过提供完整的类名。
- 如果使用扩展提供程序,您还可以选择性地传入连接时使用的证书文件。
ipg:update-certificate {path?} {url?} {--skip-test}
此命令允许您更新扩展提供程序用于连接到St.George IPG服务器的cert.cert
证书文件。该命令将下载最新证书,测试它,如果成功,它将保存到配置的或提供的路径。
php artisan ipg:update-certificate
- 您可以选择性地设置保存证书的路径,默认值为
config/ipg.php
文件中的值。 - 您可以选择性地指定下载证书的URL,默认为
https://www.ipg.stgeorge.com.au/downloads/cert.zip
。 - 您可以选择性地强制命令跳过测试以确保保存最新的证书,尽管这不被推荐。
测试
当前库尚未正式测试,但它已知与Laravel 5.4项目兼容。我计划很快实施测试,但如果您发现任何问题,请提交问题,我将尽快回复您。