teepluss / gateway
此包已被弃用且不再维护。未建议替代包。
Laravel网关是支付网关适配器。
2.0.2
2017-02-24 08:07 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- illuminate/support: >=5.0.1
This package is not auto-updated.
Last update: 2022-02-01 12:38:46 UTC
README
对于Laravel 4,请使用 v1.x分支!
网关支持PayPal、Paysbuy、Bangkok Bank、Kasikorn Bank、True Money等支付网关适配器。
安装
要获取Gateway的最新版本,只需在您的composer.json
文件中添加它。
"teepluss/gateway": "dev-master"
然后,您需要运行composer install
来下载它并更新自动加载器。
网关安装后,您需要将服务提供程序与应用程序注册。打开app/config/app.php
并找到providers
键。
'providers' => [
...
Teepluss\Gateway\GatewayServiceProvider::class,
)
网关还提供了一个外观(facade),它提供了用于创建集合的静态语法。您可以在app/config/app.php
文件的aliases
键中注册外观。
'aliases' => [
...
'Gateway' => Teepluss\Gateway\Facades\Gateway::class,
]
用法
生成支付表单。
$adapter = Gateway::driver('Paypal'); $adapter->setSandboxMode(true); $adapter->setSuccessUrl('http://www.domain/foreground/success') ->setCancelUrl('http://www.domain/foreground/cancel') ->setBackendUrl('http://www.domain/background/invoice/00001'); $adapter->setMerchantAccount('demo@gmail.com'); $adapter->setLanguage('TH') ->setCurrency('THB'); $adapter->setInvoice(00001) ->setPurpose('Buy a beer.') ->setAmount(100); $adapter->setRemark('Short note'); $generated = $adapter->render(); var_dump($generated);
您也可以使用初始化。
$adapter = Gateway::driver('Paypal')->initialize(array( 'sandboxMode' => true, 'successUrl' => 'http://www.domain/foreground/success', 'cancelUrl' => 'http://www.domain/foreground/cancel', 'backendUrl' => 'http://www.domain/background/invoice/00001', 'merchantAccount' => 'seller@domain.to', 'language' => 'TH', 'currency' => 'THB', 'invoice' => uniqid(), 'purpose' => 'Buy a beer.', 'amount' => 100, 'remark' => 'Short note' )); $generated = $adapter->render(); var_dump($generated);
如何设置TrueMoneyApi和PaysbuyApi
// True Money $gateway = Gateway::driver('TrueMoneyApi'); $gateway->setMerchantAccount('appId:shopCode:secret:bearer'); // Paysbuy $gateway = Gateway::driver('PaysbuyApi'); $gateway->setMerchantAccount('merchantId:username:secureCode'); // Paysbuy having non-apu version. $gateway = Gateway::driver('Paysbuy'); $gateway->setMerchantAccount('email');
检查前台进程。
$adapter = Gateway::driver('Paypal'); $adapter->setSandboxMode(true); $adapter->setMerchantAccount('seller@domain.to'); $adapter->setInvoice(00001); $result = $adapter->getFrontendResult(); var_dump($result);
检查后台进程(IPN)。
$adapter = Gateway::driver('Paypal'); $adapter->setSandboxMode(true); $adapter->setMerchantAccount('demo@gmail.com'); $adapter->setInvoice(00001); $result = $adapter->getBackendResult(); var_dump($result);
扩展核心。
use Teepluss\Gateway\Drivers\DriverAbstract; use Teepluss\Gateway\Drivers\DriverInterface; class Strip extends DriverAbstract imlements DriverInterface { //.... } use Teepluss\Gateway\Repository; Gateway::extend('Stripe', function() { return new Repository(new Strip); });
TrueMoneyApi适配器需要更多数据才能使其工作!
$gateway = Gateway::driver('TrueMoneyApi'); $gateway->setMerchantAccount('appId:shopCode:secret:bearer'); $gateway->setSandboxMode(true); $gateway->setSuccessUrl(URL::to('demo/thankyou')) ->setCancelUrl(URL::to('demo/thankyou')) ->setBackendUrl(URL::to('demo/background')); $gateway->setLanguage('TH') ->setCurrency('THB'); $gateway->setInvoice(uniqid()) ->setPurpose('sale'); $gateway->payer(array( 'installment' => null, 'fundingInstrument' => null, 'payerInfo' => array( 'email' => 'tee@gmail.com', 'firstName' => 'Tee', 'lastName' => 'Plus', 'payerId' => '11', 'phone' => '9999999' ), 'paymentMethod' => 'creditcard' )); $gateway->address(array( 'cityDistrict' => 'Patumwan', 'companyName' => 'eCommerce Solution', 'companyTaxId' => '3334567', 'country' => 'Thailand', 'email' => 'me@email.com', 'forename' => 'Tee', 'line1' => 'Ratchadapisak Rd.', 'line2' => 'OX', 'phone' => '0888773390', 'postalCode' => '10310', 'stateProvince' => 'Bangkok', 'surname' => 'Pluss', )); $gateway->payment(array( 'ref1' => 1, 'ref2' => 2, 'ref3' => 3 )); $gateway->product()->add(array( 'shopCode' => null, 'itemId' => 1, 'service' => 'bill', 'productId' => 'p1', 'detail' => 'd1', 'price' => 5000, 'ref1' => '1', 'ref2' => '2', 'ref3' => '3', )); $gateway->product()->add(array( 'shopCode' => null, 'itemId' => 2, 'service' => 'bill', 'productId' => 'p1', 'detail' => 'd1', 'price' => 300, 'ref1' => '1', 'ref2' => '2', 'ref3' => '3', )); echo $gateway->includeSubmitButton()->render();
对于旧版本的TrueMoney,我们调用TruePaymentApi。
$gateway = Gateway::driver('TruePaymentApi'); $gateway->setAppId('AppId') ->setShopId('ShopId') ->setPassword('Password') ->setPrivateKey('PrivateKey') ->setRC4Key('RC4Key'); // $gateway->setMerchantAccount('appId:ShopId:Password:PrivateKey:RC4Key'); $gateway->setSandboxMode(true); $gateway->setSuccessUrl(URL::to('demo/thankyou')) ->setCancelUrl(URL::to('demo/thankyou')) ->setBackendUrl(URL::to('demo/background')); $gateway->setLanguage('TH') ->setCurrency('THB'); $gateway->setRemark('Something'); $gateway->setInvoice(uniqid()); $gateway->payer(array( 'ssoId' => '4620762', 'trueId' => 'teepluss@gmail.com', 'fullName' => 'Test Dev2', 'address' => 'RS ห้วยขวาง ห้วยขวาง', 'district' => 'ห้วยขวาง', 'province' => 'กรุงเทพมหานคร', 'zip' => '11115', 'country' => 'Thailand', 'mphone' => '0890000001', 'citizenId' => '4100799036048' )); $gateway->billing(array( 'fullname' => 'Teepluss', 'address' => '33/1 Pattanakarn', 'district' => 'Pattanakarn', 'province' => 'Bangkok', 'zip' => '10220', 'country' => 'Thailand' )); $gateway->product()->add(array( 'pid' => 18051, 'productId' => 'ME161', 'topic' => 'Winnie Jewelry : ต่างหูสแควร์ไดมอนด์ (ME162)', 'quantity' => 1, 'totalPrice' => 10, 'shopIdRef' => 'inherit', 'marginPrice' => 0 )); $gateway->product()->add(array( 'pid' => 18052, 'productId' => 'ME162', 'topic' => 'Winnie Jewelry : ต่างหูสแควร์ไดมอนด์ (ME162)', 'quantity' => 3, 'totalPrice' => 10, 'shopIdRef' => 'inherit', 'marginPrice' => 0 )); echo $gateway->includeSubmitBtn()->render();
支持或联系
如果您有任何问题,请联系 teepluss@gmail.com