laravel payment
3.0.0
? Laravel용 Omnipay 서비스 제공자.
$ composer require overtrue/laravel-payment -v
작곡가를 업데이트한 후 laravel 버전 < 5.5를 사용하는 경우 서비스 공급자를 등록해야 합니다.
// config/app.php
' providers ' => [
//...
Overtrue LaravelPayment ServiceProvider::class,
],
그리고 구성 파일을 게시합니다.
$ php artisan vendor:publish --provider=Overtrue \ LaravelPayment \ ServiceProvider
파사드 모드를 사용하려면 사용하려는 파사드 이름을 등록하면 됩니다. 예를 들어 LaravelPayment
:
// config/app.php
' aliases ' => [
' LaravelPayment ' => Overtrue LaravelPayment Facade::class, // This is default in laravel 5.5
],
// config/payments.php
// The default gateway name which configured in `gateways` section.
' default_gateway ' => ' paypal ' ,
// The default options for every gateways.
' default_options ' => [
' test_mode ' => true ,
// ...
],
/*
* The gateways, you can config option by camel case or snake_case name.
*
* the option name is followed from gateway class, for example:
*
* $gateway->setMchId('overtrue');
*
* you can configured as:
* 'mch_id' => 'overtrue',
* or:
* 'mchId' => 'overtrue',
*/
' gateways ' => [
' paypal ' => [
' driver ' => ' PayPal_Express ' ,
' options ' => [
' username ' => env ( ' PAYPAL_USERNAME ' ),
' password ' => env ( ' PAYPAL_PASSWORD ' ),
' signature ' => env ( ' PAYPAL_SIGNATURE ' ),
' test_mode ' => env ( ' PAYPAL_TEST_MODE ' ),
],
],
// other gateways
],
사용하려는 게이트웨이를 설치해야 합니다: omnipay#pay-gateways
게이트웨이 인스턴스:
LaravelPayment:: gateway ( ' GATEWAY NAME ' ); // GATEWAY NAME is key name of `gateways` configuration.
LaravelPayment:: gateway ( ' alipay ' );
LaravelPayment:: gateway ( ' paypal ' );
기본 게이트웨이 사용:
LaravelPayment:: purchase (...);
예:
$ formData = [
' number ' => ' 4242424242424242 ' ,
' expiryMonth ' => ' 6 ' ,
' expiryYear ' => ' 2030 ' ,
' cvv ' => ' 123 '
];
$ response = LaravelPayment::purchase([
' amount ' => ' 10.00 ' ,
' currency ' => ' USD ' ,
' card ' => $ formData ,
))-> send ();
if ( $ response -> isRedirect ()) {
// redirect to offsite payment gateway
$ response -> redirect ();
} elseif ( $ response -> isSuccessful ()) {
// payment was successful: update database
print_r ( $ response );
} else {
// payment failed: display message to customer
echo $ response -> getMessage ();
}
Omnipay에 대한 자세한 사용 방법은 Omnipay 공식 홈페이지를 참조하세요.
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩 확장包实战教程 - 从入门到发布》
MIT