承接 jack-walter-smith/bepaid-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jack-walter-smith/bepaid-laravel

Composer 安装命令:

composer require jack-walter-smith/bepaid-laravel

包简介

A wrapper of https://github.com/begateway/begateway-api-php for Laravel

README 文档

README

bepaid-laravel

Build Status Codecov branch

A wrapper of BeGateway for Laravel (unofficial)

Documentation

Requirements

PHP >=7.1

Laravel >= 5.7

Installation

  • Add to composer json
{
  "repositories": [
    {
      "type": "vcs",
      "url": "git@github.com:Jack-Walter-Smith/begateway-api-php.git",
      "no-api": true
    }
  ],
  "require": {
    "jack-walter-smith/bepaid-laravel": "^1.0"
  }
}
  • Run composer update

  • Publish config

php artisan vendor:publish --provider="JackWalterSmith\BePaidLaravel\Providers\BePaidServiceProvider"

Usage

Basics

All you need to do is to create a new DTO and fill out original object with provided values.

Here is a simple example:

<?php

namespace App\Services;

use JackWalterSmith\BePaidLaravel\Refund;

class PaymentService 
{
    /** @var Refund */
    private $refund;

    public function __construct(Refund $refund) {
        $this->refund = $refund;
    }

    public function refund()
    {
        // Create new DTO
        $refundDto = new \JackWalterSmith\BePaidLaravel\Dtos\RefundDto([
            'reason' => 'Purchase returns',
            'parent_uid' => 'payment_uid',
            'money' => [
                'amount' => 333.33,
            ],
        ]);
        
        $response = $this->refund
            ->fill($refundDto)
            ->submit();
        
        // OR even shorter
        // $response = $this->refund->submit($refundDto);

        // ... process the $response
    }
}

The table bellow illustrates which object in BeGateway equals to object in BePaid Laravel. All of these objects in BePaid Laravel package, that listed below, have public field $operation, which gives you access to original object. This is in case if package features are not enough to reach goal. You can check original package to see all available methods.

BeGateway BePaid Laravel Facade DTO
AuthorizationOperation Authorization Authorization AuthorizationDto
CardToken CardToken CardToken CardTokenDto
PaymentOperation Payment Payment PaymentDto
GetPaymentToken PaymentToken PaymentToken PaymentTokenDto
Product Product Product ProductDto
QueryByPaymentToken Query Query QueryByPaymentTokenDto
QueryByTrackingId Query Query QueryByTrackingIdDto
QueryByUid Query Query QueryByUidDto
RefundOperation Refund Refund RefundDto
CreditOperation Credit Credit CreditDto
CaptureOperation ChildTransaction ChildTransaction CaptureDto
VoidOperation ChildTransaction ChildTransaction VoidDto

A few words about Query and ChildTransaction objects. They are also have $operation public field, but there are nuances. It depends on which DTO you will pass to fill() or submit() method. So let's say you want to query for transaction by uid, in this case you'll create a new QueryByUidDto([...]), then $operation field becomes instance of \BeGateway\QueryByUid.

Subscribe to events

BePaid Laravel provides preconfigured routes that can be used in requests. Below is the list of it:

Method Path Name Middleware Event
POST /bepaid/notifications bepaid.notifications bepaid.inject_basic_auth bepaid.event.notification.success | bepaid.event.notification.fail
GET /bepaid/success bepaid.success - bepaid.event.success
GET /bepaid/decline bepaid.decline - bepaid.event.fail
GET /bepaid/fail bepaid.fail - bepaid.event.return
GET /bapaid/cancel bepaid.cancel - bepaid.event.cancel
GET /bepaid/return bepaid.return - bepaid.event.decline

The most important is notifications. BePaid Laravel already validates if the incoming request was sent by BePaid. In success validation scenario it will fire bepaid.event.notification.success and bepaid.event.notification.fail if something went wrong.

How to handle all this stuff?

BePaid Laravel ships with abstract class BePaidSubscriber which you need to extend.

Create and register a new Event Subscriber:

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        //
    ];

    /**
     * The subscriber classes to register.
     *
     * @var array
     */
    protected $subscribe = [
        'App\Listeners\PaymentNotificationEventSubscriber',
    ];
}

Now just extend BePaidSubscriber and define all required methods. That's it.

<?php

namespace App\Listeners;

use JackWalterSmith\BePaidLaravel\Contracts\BePaidSubscriber;
use Illuminate\Http\Request;

class PaymentNotificationEventSubscriber extends BePaidSubscriber
{
    public function onNotificationSuccess(Request $request)
    {
        // ... process the request
    }

    public function onNotificationFail(Request $request)
    {
        // ... process the request
    }

    public function onSuccess(Request $request)
    {
        // ... process the request
    }

    public function onFail(Request $request)
    {
        // ... process the request
    }

    public function onReturn(Request $request)
    {
        // ... process the request
    }

    public function onCancel(Request $request)
    {
        // ... process the request
    }

    public function onDecline(Request $request)
    {
        // ... process the request
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固