laravel payment
3.0.0
? Penyedia Layanan Omnipay untuk Laravel.
$ composer require overtrue/laravel-payment -v
Setelah composer diperbarui, jika Anda menggunakan laravel versi <5.5, Anda perlu mendaftarkan penyedia layanan:
// config/app.php
' providers ' => [
//...
Overtrue LaravelPayment ServiceProvider::class,
],
Dan publikasikan file konfigurasi:
$ php artisan vendor:publish --provider=Overtrue \ LaravelPayment \ ServiceProvider
jika anda ingin menggunakan mode fasad, anda dapat mendaftarkan nama fasad apa yang ingin anda gunakan, misalnya 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
],
Anda perlu menginstal gateway yang ingin Anda gunakan: omnipay#pembayaran-gateways
Contoh gerbang:
LaravelPayment:: gateway ( ' GATEWAY NAME ' ); // GATEWAY NAME is key name of `gateways` configuration.
LaravelPayment:: gateway ( ' alipay ' );
LaravelPayment:: gateway ( ' paypal ' );
Menggunakan gerbang default:
LaravelPayment:: purchase (...);
Contoh:
$ 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 ();
}
Untuk penggunaan lebih lanjut tentang Omnipay, silakan merujuk ke Halaman Beranda Resmi Omnipay
想知道如何从零开始构建 PHP 扩展包?
PHP 扩展包实战教程 -从入门到发布》
MIT