lukasz-adamski/laravel-przelewy24 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lukasz-adamski/laravel-przelewy24

Composer 安装命令:

composer require lukasz-adamski/laravel-przelewy24

包简介

Przelewy24 payments processor service provider for Laravel framework.

README 文档

README

Laravel package which provides Przelewy24 payment processor support.

Installation

  1. Install composer package using command:
composer require lukasz-adamski/laravel-przelewy24
  1. Add Service Provider in config/app.php:
Adams\Przelewy24\Przelewy24ServiceProvider::class,
  1. Add Facade in config/app.php:
'Przelewy24' => Adams\Przelewy24\Facades\Facade::class,
  1. Publish configuration file to your project:
php artisan vendor:publish --provider="Adams\Przelewy24\Przelewy24ServiceProvider"
  1. If you have package_routes setting enabled you need to except /webhook/przelewy24 route from CSRF verification in app/Http/Middleware/VerifyCsrfToken.php:
/**
 * The URIs that should be excluded from CSRF verification.
 *
 * @var array
 */
protected $except = [
    '/webhook/przelewy24'
];

Environment

You can setup these environment variables to configure Przelewy24 API access:

  • PRZELEWY24_MODE - Current API mode, by default this value is set to sandbox to test implementation. On production you need to set this value to live,
  • PRZELEWY24_MERCHANT_ID - Your merchant identifier received from payment provider,
  • PRZELEWY24_POS_ID - Shop identifier to process payments. If you don't want to process incoming payments to given shop enter here merchant identifier and payments will not be classified to any shop,
  • PRZELEWY24_CRC - Random string received from payment provider to sign API requests.

Testing

To run predefined test set use:

php vendor/bin/phpunit

Usage

Below you have example controller implementation:

<?php

namespace App\Http\Controllers;

use Przelewy24;
use Adams\Przelewy24\Transaction;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str;

class ExampleController extends Controller
{
    /**
     * Redirect user to payment provider.
     *
     * @return Response
     */
    public function pay()
    {
        $payload = new Transaction();
        $payload->setSessionId(Str::random(30));
        $payload->setAmount($item->price * 100);
        $payload->setDescription('My item description');
        $payload->setEmail('customer@example.com');
        $payload->setUrlReturn(url('/'));

        return Przelewy24::redirect($payload);
    }
}

Events

When transaction receiver from this package is enabled (package_routes setting) you can listen for predefined events dispatched by default webhook controller:

  • \Adams\Przelewy24\Events\TransactionReceived::class - transaction was successfully received (signature is valid). If you don't use automatic verification you need to do it manually to charge prepaid money,
  • \Adams\Przelewy24\Events\TransactionVerified::class - transaction was successfully received and verified via provider's API. After dispatching this event, prepaid money is already added to your account.

Example

  1. Below you can see example code of TransactionVerified event listener created by php artisan make:listener ReceivePayment:
<?php

namespace App\Listeners;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Adams\Przelewy24\Events\TransactionVerified;

class ReceivePayment
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param TransactionVerified $event
     * @return void
     */
    public function handle(TransactionVerified $event)
    {
        //
    }
}
  1. You also need to register new listener in app/Providers/EventServiceProvider.php file.
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    \Adams\Przelewy24\Events\TransactionVerified::class => [
        \App\Listeners\ReceivePayment::class,
    ],
];

统计信息

  • 总下载量: 182
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固