mancoide / laravel-bancard
该项目旨在简化bancard API集成
dev-main
2024-06-08 22:12 UTC
Requires
- php: ^8.1
- illuminate/http: ^8.0|^9.0|^10.0
This package is not auto-updated.
Last update: 2024-09-29 21:39:08 UTC
README
安装
通过composer安装
composer require composer require mancoide/laravel-bancard:dev-main
发布配置和迁移文件
php artisan vendor:publish --provider="Mancoide\Bancard\BancardServiceProvider" --tag="bancard-configs" php artisan vendor:publish --provider="Mancoide\Bancard\BancardServiceProvider" --tag="bancard-migrations"
以下是将在config/bancard.php中发布的文件内容
return [ /* |-------------------------------------------------------------------------- | Bancard Keys |-------------------------------------------------------------------------- | | The Bancard public key and private key give you access to Bancard's | API. | */ 'public' => env('BANCARD_PUBLIC_KEY', ''), 'private' => env('BANCARD_PRIVATE_KEY', ''), /* |-------------------------------------------------------------------------- | Bancard Environment |-------------------------------------------------------------------------- | | This value determines if your application is using the | staging environment from Bancard's API. | */ 'staging' => (bool) env('BANCARD_STAGING', true), /* |-------------------------------------------------------------------------- | Bancard URL |-------------------------------------------------------------------------- */ // The return URL for the Single Buy Operation 'single_buy_return_url' => env('BANCARD_SINGLE_BUY_RETURN_URL', ''), // The cancel URL for the Single Buy Operation 'single_buy_cancel_url' => env('BANCARD_SINGLE_BUY_CANCEL_URL', ''), // The return URL for the New Card Operation 'new_card_return_url' => env('BANCARD_NEW_CARD_RETURN_URL', ''), ];
运行迁移
php artisan migrate
用法
以下列出的方法返回类Illuminate\Http\Client\Response的实例。
根据Laravel 文档,这些是您可以用来检查响应的一些方法。
// Get the body of the response. $response->body() : string; // Get the JSON decoded body of the response as an array or scalar value. $response->json() : array|mixed; // Determine if the status code is >= 200 and < 300... $response->successful(); // Determine if the status code is >= 400... $response->failed();
单次购买
开始支付流程。
use Mancoide\Bancard\Bancard; $response = Bancard::singleBuy('Ejemplo de pago', 10330.00); if ($response->failed()) { // Do something here. } $data = $response->json(); $processId = $data['process_id']; $scriptUrl = Bancard::scriptUrl(); return view('your_view_here', compact('processId', 'scriptUrl'));
通过singleBuy方法创建了一个名为SingleBuy的Eloquent模型。您可以使用process_id值检索记录。
use Mancoide\Bancard\Models\SingleBuy; $order = SingleBuy::where('process_id', '')->first();
新卡
开始注册新卡的流程。
use Mancoide\Bancard\Bancard; $response = Bancard::newCard(966389, '09********', 'user@example.com'); if ($response->failed()) { // Do something here. } $data = $response->json(); $processId = $data['process_id']; $scriptUrl = Bancard::scriptUrl(); return view('your_view_here', compact('processId', 'scriptUrl'));
通过newCard方法创建了一个名为Card的Eloquent模型。您可以使用user_id值检索用户的全部卡片;
use Mancoide\Bancard\Models\Card; $cards = Card::where('user_id', '')->get();
用户卡片
允许您列出用户注册的卡片。
use Mancoide\Bancard\Bancard; $response = Bancard::listCards(966389); if ($response->failed()) { // Do something here. } $data = $response->json(); $cards = $data['cards'];
删除
允许您删除已注册的卡。
use Mancoide\Bancard\Bancard; $response = Bancard::deleteCard(966389, 'c8996fb92427ae41e4649b934ca495991b7852b855'); if ($response->failed()) { // Do something here. } $data = $response->json(); $status = $data['status'];
收费
允许您使用令牌进行支付的操作。
use Mancoide\Bancard\Bancard; $response = Bancard::tokenCharge('Ejemplo de pago', 10330.00, 'c8996fb92427ae41e4649b934ca495991b7852b855'); if ($response->failed()) { // Do something here. } $data = $response->json(); $confirmation = $data['confirmation'];
通过tokenCharge方法创建了两个Eloquent模型。这些模型是SingleBuy和Confirmation。您可以使用响应中返回的shop_process_id值检索每个记录。
use Mancoide\Bancard\Models\{SingleBuy, Confirmation}; $order = SingleBuy::where('shop_process_id', '')->first(); $confirmation = Confirmation::where('shop_process_id', '')->first();
单次购买回滚
允许您取消支付的操作。
use Mancoide\Bancard\Bancard; $response = Bancard::rollback('12313'); if ($response->failed()) { // Do something here. } $data = $response->json(); $status = $data['status'];
通过rollback方法创建了一个名为Rollback的Eloquent模型。您可以使用shop_process_id值检索记录。
use Mancoide\Bancard\Models\Rollback; $record = Rollback::where('shop_process_id', '')->first();
单次购买获取确认
允许您知道支付是否已确认的操作。
use Mancoide\Bancard\Bancard; $response = Bancard::confirmation('12313'); if ($response->failed()) { // Do something here. } $data = $response->json(); $confirmation = $data['confirmation'];
通过confirmation方法创建了一个名为Confirmation的Eloquent模型。您可以使用shop_process_id值检索记录。
use Mancoide\Bancard\Models\Confirmation; $record = Confirmation::where('shop_process_id', '')->first();
贡献者
许可
MIT许可证(MIT)。有关更多信息,请参阅许可文件。