承接 darkghosthunter/larabanker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

darkghosthunter/larabanker

Composer 安装命令:

composer require darkghosthunter/larabanker

包简介

Transbank SDK for Laravel

README 文档

README

Paul Felberbauer - Unsplash (UL) #-idNOBU5k_80

Latest Stable Version License Coverage Status Laravel Octane Compatible

Larabanker - Transbank for Laravel

This package connects the non-official Transbank SDK into your Laravel Application.

Requirements

  • PHP >= 8.0
  • Laravel 8.x

Check older releases for older Laravel versions.

Installation

Call composer and require it into your application.

composer require darkghosthunter/larabanker

Documentation

This package mimics the Transbank SDK, so you should check the documentation of these services in Transbank Developer's site (in spanish).

Quickstart

To start using Transbank services, you can use the included Webpay, WebpayMall and Oneclick facades and the redirect() method, which use minimum parameters and returns a ready-made GET redirect to Transbank.

use DarkGhostHunter\Larabanker\Facades\Webpay;

return Webpay::redirect('buy-order#1230', 1000);

Alternatively, you can still have total control to create transactions using the facades.

use DarkGhostHunter\Larabanker\Facades\Webpay;

$response = Webpay::create('buyOrder#1230', 1000, route('payment'));

return redirect()->away($response, 303);

Since API 1.2, Transbank services support GET redirects. There is no longer need to use views with Javascript redirection.

Redirects are made using default route names that centralizes the payment endpoint.

Dealing with POST and Session destruction

Laravel sets cookies as SameSite: lax by default. This means that the session is destroyed when a payment fails or is aborted. This happens because Transbank redirects using a POST method to your application without cookies, forcing Laravel to recreate a new empty session.

To avoid this, you should use the same path to receive the response from Transbank, but using a different controller for GET or POST. Larabanker conveniently uses one route name for each of Transbank services redirection points, which will be hit once the payment process ends.

Service URL Name Your hypothetical route
Webpay Return URL transbank.webpay http://yourappurl.com/transbank/webpay
Webpay Mall Return URL transbank.webpayMall http://yourappurl.com/transbank/webpayMall
Oneclick Mall Response URL transbank.oneclickMall http://yourappurl.com/transbank/oneclickMall

You're free to change these Route names in the config file. Be sure to add your controllers for these routes to process the incoming response from Transbank.

In this example, we will disable the web middleware to avoid creating a new session, and return a view with a generic failure message.

use \DarkGhostHunter\Larabanker\Facades\Webpay;
use \Illuminate\Support\Facades\Route;

Route::get('transbank/webpay', function (Request $request) {
    $transaction = Webpay::commit($request->input('token_ws'));

    return view('payment.processed')->with('transaction', $transaction);
})->name('transbank.webpay');

Route::post('transaction/webpay, function (Request $request) {
    return view('payment.failed');
})->withoutMiddleware('web');

Configuration

While Larabanker is made to use conveniently without setting too much, you can go deeper by publishing the configuration file:

php artisan vendor:publish --provider="DarkGhostHunter\Larabanker\ServiceProvider"

You will receive the larabanker.php config file with the following contents:

<?php

return [
    'environment' => env('TRANSBANK_ENV', 'integration'),
    'credentials' => [
        // ...
    ],
    'redirects' => [
        'webpay'       => 'transbank.webpay',
        'webpayMall'   => 'transbank.webpayMall',
        'oneclickMall' => 'transbank.oneclickMall',
    ],
    'protect' => env('TRANSBANK_PROTECT', false),
    'cache' => null,
    'cache_prefix' => env('TRANSBANK_PROTECT_PREFIX', 'transbank|token')
];

Don't worry, we will explain each important part one by one.

Environment & Credentials

<?php

return [
    'environment' => env('TRANSBANK_ENV', 'integration'),
    'credentials' => [
        'webpay' => [
            'key' => env('WEBPAY_KEY'),
            'secret' => env('WEBPAY_SECRET'),
        ],
        'webpayMall' => [
            'key' => env('WEBPAY_MALL_KEY'),
            'secret' => env('WEBPAY_MALL_SECRET'),
        ],
        'oneclickMall' => [
            'key' => env('ONECLICK_MALL_KEY'),
            'secret' => env('ONECLICK_MALL_SECRET'),
        ],
    ],
];

By default, the package uses the integration environment, which makes fake transactions.

To use the production environment, which will make all transactions real, set the environment as production explicitly:

TRANSBANK_ENV=production

Additionally, you must add your Transbank credentials for your services, which will be issued directly to you, for the service(s) you have contracted. You can do it easily in your .env file.

WEBPAY_KEY=5000000001
WEBPAY_SECRET=dKVhq1WGt_XapIYirTXNyUKoWTDFfxaEV63-O5jcsdw

Redirection

<?php

return [
    'redirects_base' => env('APP_URL'),
    'redirects' => [
        'webpay'       => 'transbank.webpay',
        'webpayMall'   => 'transbank.webpayMall',
        'oneclickMall' => 'transbank.oneclickMall',
    ],
];

Only when using the Webpay, WebpayMall and OneclickMall facades, you will be able to skip issuing the $returnUrl or $responseUrl values to the transaction creation, letting Larabanker to use the defaults issued in your config file.

use DarkGhostHunter\Larabanker\Facades\Webpay;

$response = Webpay::create('myOrder#16548', 1000);

Endpoint Protection

return [
    'protect' => env('TRANSBANK_PROTECT', false),
    'cache' => null,
    'cache_prefix' => env('TRANSBANK_PROTECT_PREFIX', 'transbank|token')
];

Disabled by default, this package offers a brute-force attack protection middleware, larabank.protect, for return URL. These return URLs are your application endpoints that Transbank services will redirect the user to using a GET or POST request.

If it's disabled, the middleware won't verify the token.

use \Illuminate\Support\Facades\Route;
use \App\Http\Controllers\WebpayController;

Route::post('/transbank/webpay', [WebpayController::class, 'receivePayment'])
     ->middleware('larabank.protect');

It uses the cache to save the transaction token for 5 minutes, so if the token is no longer valid, the whole response is aborted. You can change the cache store and prefix with cache and cache_prefix, respectively.

This works for receiving the redirection from Transbank on Webpay, Webpay Mall and Oneclick Mall services.

License

This package is open-sourced software licensed under the MIT license.

Redcompra, Webpay, Onepay, Patpass and tbk are trademarks of Transbank S.A.

This package is not developed, approved, supported nor endorsed by Transbank S.A., nor by a natural person or company linked directly or indirectly by Transbank S.A.

darkghosthunter/larabanker 适用场景与选型建议

darkghosthunter/larabanker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「webpay」 「transbank」 「oneclick」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 darkghosthunter/larabanker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 darkghosthunter/larabanker 我们能提供哪些服务?
定制开发 / 二次开发

基于 darkghosthunter/larabanker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-05