remzikocak / laravel-vallet
Laravel的未官方Vallet支付网关集成。
2.0.0
2024-03-10 11:29 UTC
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.2
- illuminate/support: ^10.0|^11.0
- illuminate/translation: ^10.0|^11.0
Requires (Dev)
- laravel/pint: v1.13
- mockery/mockery: ^1.5
- orchestra/testbench: ^8.0
- pestphp/pest: ^1.22
- phpunit/phpunit: ^9.5.24
README
Laravel 10的Vallet集成
此包帮助您将Vallet支付网关集成到您的Laravel应用程序中。
这是一个非官方的第三方包。
安装
您可以通过composer安装此包
composer require remzikocak/laravel-vallet
配置
使用以下命令发布配置文件
php artisan vendor:publish --provider="RKocak\Vallet\ValletServiceProvider" --tag="config"
将以下变量添加到您的.env文件中,并填写您的凭证
VALLET_USERNAME= VALLET_PASSWORD= VALLET_SHOPCODE= VALLET_HASH= VALLET_CALLBACK_OK_URL= VALLET_CALLBACK_FAIL_URL=
VALLET_CALLBACK_OK_URL 和 VALLET_CALLBACK_FAIL_URL 是Vallet在支付完成或失败后重定向用户的URL。请确保您已在路由文件中为这些URL创建了路由。
使用方法
如何创建支付
use RKocak\Vallet\Facades\Vallet; use RKocak\Vallet\Buyer; use RKocak\Vallet\Enums\{Currency, Locale, ProductType}; use RKocak\Vallet\Exceptions\{RequestFailedException, InvalidArgumentException, BuyerNotSetException, LocaleNotSetException, CurrencyNotSetException}; class YourController { public function yourMethod() { // Create a new buyer object $buyer = new Buyer(); $buyer->setName('Remzi') ->setSurname('Kocak') ->setEmail('hey@remzikocak.com') ->setCity('Istanbul') ->setCountry('Turkey') ->setDistrict('Atasehir') ->setPhoneNumber('5555555555') ->setAddress('Atasehir, Istanbul') ->setIp('127.0.0.1'); // Create a new payment object $payment = Vallet::createPayment(); // Set Payment Details $payment->setBuyer($buyer) ->setLocale(Locale::Turkish) ->setCurrency(Currency::Try) ->setConversationId('123456789') ->setOrderId('123456789') ->setProductName('Test Product') ->setTotalPrice(100) ->setOrderPrice(100) ->setProductType(ProductType::Digital); // Add Products $payment->addProduct( Product::make() ->setName('Test Product') ->setPrice(13.50) ->setType(ProductType::Digital) ); try { // Send Payment Request $paymentLink = $payment->getLink(); // You can redirect user to '$paymentLink' or you can use it as a href in your button // Depending on your needs } catch (RequestFailedException|InvalidArgumentException|BuyerNotSetException|LocaleNotSetException|CurrencyNotSetException $e) { // Handle Exception } } }
检索支付详情
use RKocak\Vallet\Facades\Vallet; use RKocak\Vallet\Exceptions\{InvalidHashException, InvalidResponseException}; class YourController { public function yourMethod(){ try { // Retrieve Payment Details $response = Vallet::getResponse(); $response->validate(); if($response->isPaid()) { // Payment is paid $amount = $response->getAmount(); $orderId = $response->getOrderId(); $valletOrderId = $response->getValletOrderId(); // Update your order status, send email etc. } else { // Payment is not paid, is pending or is awaiting verification } } catch (InvalidHashException|InvalidResponseException $e) { // Handle Exception } } }
重要:您应该在数据库中存储$response->getValletOrderId()。您在退款时需要它。
退款支付
use RKocak\Vallet\Facades\Vallet; class YourController { public function yourMethod() { $refund = Vallet::createRefund(); try { // Set Refund Details $refund->setOrderId('123456789') ->setValletOrderId('123456789') ->setAmount(100); // Send Refund Request $response = $refund->process(); if($response->success()) { $refundId = $response->getRefundId(); } else { // Refund is not successful } } catch (InvalidArgumentException $e) { // Handle Exception } } }
重要:您应该在数据库中存储$response->getRefundId()。您将需要它与Vallet客服支持联系。
发布翻译文件
Laravel的Vallet集成包含英文、土耳其语和德语翻译。如果您想自定义它们,可以使用以下命令发布它们
php artisan vendor:publish --provider="RKocak\Vallet\ValletServiceProvider" --tag="lang"
测试
composer test
