bancardgateway/laravel-bancard 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bancardgateway/laravel-bancard

Composer 安装命令:

composer require bancardgateway/laravel-bancard

包简介

README 文档

README

Installation

Install via composer

composer require bancardgateway/laravel-bancard

Publish config and migrations

php artisan vendor:publish --provider="bancardgateway\Bancard\BancardServiceProvider"

This is the contents of the file which will be published at 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', ''), 
];

Run migrations

php artisan migrate

Usage

The methods listed below return an instance of the class Illuminate\Http\Client\Response.

According to Laravel Documentation these are some of the methods you can use to inspect the response.

// 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();

Single Buy

Start the payment process.

use bancardgateway\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'));

Through the singleBuy method an eloquent model called SingleBuy is created. You can retrieve the record using the process_id value.

use Deviam\Bancard\Models\SingleBuy;

$order = SingleBuy::where('process_id', '')->first();

Cards New

Start the registration process of a card.

use bancardgateway\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'));

Through the newCard method an eloquent model called Card is created. You can retrieve all the cards from an user with the user_id value;

use Deviam\Bancard\Models\Card;

$cards = Card::where('user_id', '')->get();

Users Cards

Operation that allow you to list the cards registered from an user.

use bancardgateway\Bancard\Bancard;

$response = Bancard::listCards(966389);
if ($response->failed()) {
	// Do something here.
}
$data = $response->json();
$cards = $data['cards'];

Delete

Operation that allow you to delete a registered card.

use bancardgateway\Bancard\Bancard;

$response = Bancard::deleteCard(966389, 'c8996fb92427ae41e4649b934ca495991b7852b855');
if ($response->failed()) {
	// Do something here.
}
$data = $response->json();
$status = $data['status'];

Charge

Operation that allow you to make a payment with a token.

use bancardgateway\Bancard\Bancard;

$response = Bancard::tokenCharge('Ejemplo de pago', 10330.00, 'c8996fb92427ae41e4649b934ca495991b7852b855');
if ($response->failed()) {
	// Do something here.
}
$data = $response->json();
$confirmation = $data['confirmation'];

Through the tokenCharge method two eloquent models are created. These models are SingleBuy and Confirmation. You can retrieve each record with the shop_process_id value that comes in the response.

use bancardgateway\Bancard\Models\{SingleBuy, Confirmation};

$order = SingleBuy::where('shop_process_id', '')->first();
$confirmation = Confirmation::where('shop_process_id', '')->first();

Single Buy Rollback

Operation that allow you to cancel the payment.

use bancardgateway\Bancard\Bancard;

$response = Bancard::rollback('12313');
if ($response->failed()) {
	// Do something here.
}
$data = $response->json();
$status = $data['status'];

Through the rollback method an eloquent model called Rollback is created. You can retrieve the record using the shop_process_id value.

use bancardgateway\Bancard\Models\Rollback;

$record = Rollback::where('shop_process_id', '')->first();

Single Buy Get Confirmation

Operation that allow you to know if a payment was confirmed or not.

use bancardgateway\Bancard\Bancard;

$response = Bancard::confirmation('12313');
if ($response->failed()) {
	// Do something here.
}
$data = $response->json();
$confirmation = $data['confirmation'];

Through the confirmation method an eloquent model called Confirmation is created. You can retrieve the record using the shop_process_id value.

use bancardgateway\Bancard\Models\Confirmation;

$record = Confirmation::where('shop_process_id', '')->first();

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 135
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-19