vikaswalia/laravel-gopay
Composer 安装命令:
composer require vikaswalia/laravel-gopay
包简介
GoPay SDK for Laravel
README 文档
README
Requirements
The GoPay SDK for Laravel package requires PHP 8.0+, Laravel 8+.
Installation
Step 1: Install package
Add the package in your composer.json by executing the command:
composer require vikaswalia/laravel-gopay
This command installs the package into the vendor/ directory.
Step 2: Configuration
You can initialise config file by running command:
php artisan vendor:publish --provider="Vikaswalia\LaravelGoPay\Providers\GoPayServiceProvider" --tag="config"
Next, you can see newly created file located in config folder - gopay.php.
By default, the config file looks like this
<?php return [ 'goid' => env('GOPAY_ID'), 'clientId' => env('GOPAY_CLIENT_ID'), 'clientSecret' => env('GOPAY_CLIENT_SECRET'), 'defaultScope' => env('GOPAY_DEFAULT_SCOPE', 'ALL'), 'gatewayUrl' => env('GOPAY_PRODUCTION_ENV', true) ? 'https://gate.gopay.cz/' : 'https://gw.sandbox.gopay.com/', 'languages' => [ 'en' => 'ENGLISH', 'sk' => 'SLOVAK', 'cs' => 'CZECH' ], 'timeout' => 30 ];
Basic variables can be set in .env file.
Features
Languages
You can set up payment gateway interface language when you creating new payment.
Via GoPay Definition
\GoPaySDK::lang(GoPay\Definition\Languages::CZECH)
Via Language Code
\GoPaySDK::lang('cs')
Via String
\GoPaySDK::lang('CZECH')
Scopes
Via GoPay Definition
\GoPaySDK::scope(GoPay\Definition\TokenScope::CREATE_PAYMENT)
Via String
\GoPay::scope('CREATE_PAYMENT')
Events
| Name | Class |
|---|---|
| PaymentCreated | VikasWalia\LaravelGoPaySDK\Events\PaymentCreated |
Event::listen(\Vikaswalia\LaravelGoPay\Events\PaymentCreated::class, function ($event) { dd($event->payment); });
Usage/Examples
Facade GoPaySDK
For example you can use facade GoPaySDK in a Controller to create standard payment:
<?php namespace App\Http\Controllers\Support\Orders; use App\Http\Controllers\Controller; use App\Http\Requests\Orders\StoreOrderRequest; use GoPaySDK; use GoPay\Definition\Payment\Currency; use GoPay\Definition\Payment\PaymentInstrument; class OrdersController extends Controller { public function storeOrder(StoreOrderRequest $request, Order $order): RedirectResponse { // your code GoPaySDk::log(function($request, $response){ \Log::info("{$request->method} {$request->url} -> {$response->statusCode}"); }); // You can use https://doc.gopay.com/#payment-creation $response = GoPaySDK::lang(strtoupper($order->locale))->scope('CREATE_PAYMENT')->createPayment([ 'payer' => [ 'default_payment_instrument' => PaymentInstrument::PAYMENT_CARD, 'allowed_payment_instruments' => [PaymentInstrument::PAYMENT_CARD], 'contact' => [ 'first_name' => $order->customer_name, 'last_name' => $order->customer_surname, 'email' => $order->customer_email, 'phone_number' => $order->customer_telephone, 'city' => $order->customer_city, 'street' => $order->customer_street, 'postal_code' => $order->customer_postal_code, 'country_code' => $order->customer_state_code, ], ], 'amount' => $order->total_price, // Total price (float, two decimal places, without separator - fe. 19900 will be 199,00) 'currency' => Currency::CZECH_CROWNS, 'order_number' => $order->id, 'order_description' => 'Test', 'items' => [ // Only example, you have to do yourself [ 'name' => 'test', 'amount' => 19900 ], ], 'additional_params' => [ array( 'name' => 'invoicenumber', 'value' => $order->invoice_number ) ], 'callback' => [ 'return_url' => route('orders.show', $order), 'notification_url' => route('gopayNotification') ] ]); //dd($response); if ($response->hasSucceed()) { // Logic when the response is successful // For example you can redirect users after some logic to process payment return redirect()->to($response->json['gw_url'], 301); } // rest of your code } }
Check Payment State
Here's a simple example of how you can get a payment status and how you can assign the status to an order.
List of possible payment states
use GoPaySDK; use App\Enums\Orders\OrderStatus; // your code $response = GoPaySDK::getStatus($order->gopay_payment_id); if(isset($response->json['state'])){ $status = match($response->json['state']) { 'CREATED' => OrderStatus::Waiting, 'PAID' => OrderStatus::Paid, 'CANCELED' => OrderStatus::Canceled, 'TIMEOUTED' => OrderStatus::Timeouted, 'REFUNDED' => OrderStatus::Refunded, default => $response->json['state'] }; $order->update([ 'status' => $status, ]); } // rest of your code
License
Copyright (c) Vikas Walia. MIT Licensed, see LICENSE for details.
vikaswalia/laravel-gopay 适用场景与选型建议
vikaswalia/laravel-gopay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「gopay」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vikaswalia/laravel-gopay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vikaswalia/laravel-gopay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vikaswalia/laravel-gopay 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GoPay gateway for Omnipay payment processing library
GoPay gateway for Omnipay payment processing library
GoPay gateway for Omnipay payment processing library
GoPay's PHP SDK for Payments REST API - json flag
GoPay Inline Payment Gateway
GoPay gateway for Omnipay payment processing library
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-07