定制 think.studio/laravel-gocardless-payment 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

think.studio/laravel-gocardless-payment

最新稳定版本:1.0.0

Composer 安装命令:

composer require think.studio/laravel-gocardless-payment

包简介

GoCardless payment implementation for laravel

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Highly targeted package created for specific usage case and not support/maintain all options of GoCardless. Package is based on official php package

Installation

composer require think.studio/laravel-gocardless-payment

Optionally you can publish the config file with:

php artisan vendor:publish --provider="GoCardlessPayment\ServiceProvider" --tag="config"
# If you want override default migrations
php artisan vendor:publish --provider="GoCardlessPayment\ServiceProvider" --tag="migrations"

Place required credentials:

GOCARDLESS_ACCESS_TOKEN="sandbox_XxxxXXXxxxxXXXXxx-xXxxxXXx_XX-xxxX"
GOCARDLESS_WEBHOOK_ENDPOINT_SECRET="XXXXxxxxXXXXXxxxXXXXxxxXXXXxx"

Customize default configuration

Amends in any app service provider

public function register()
{
    // Do not run default migrations
    \GoCardlessPayment\GoCardlessPayment::ignoreMigrations();
    // Do not use default routes provided by package
    \GoCardlessPayment\GoCardlessPayment::ignoreRoutes();
    
    // Override repository to get local customer
    $this->app->singleton(LocalCustomerRepository::class, function (Application $app) {
        return new MyCustomLocalCustomerRepository();
    });
    
    // Override Api functionality
    $this->app->bind(Api::class, function (Application $app) {
        return new CustomApi();
    });
}

Usage

Note: to use api requests your server IP should be in country covered by GoCardless service, in other case api requests will fail (you can try use VPN for local test/development)

Create mandate checkout url

As first step server should generate mandate url and redirect user to this url.

use GoCardlessPayment\MandateCheckout\BillingRequest;
use GoCardlessPayment\MandateCheckout\BillingRequestFlow;
use GoCardlessPayment\MandateCheckout\MandateCheckoutPage;
use GoCardlessPayment\MandateCheckout\MandateRequest;
use GoCardlessPayment\MandateCheckout\Metadata;
use GoCardlessPayment\MandateCheckout\ReturnUrls;

/** @var \GoCardlessPayment\Contracts\GoCardlessCustomer $user */
$user = getCurrentUser();

$url = MandateCheckoutPage::make(
            BillingRequest::make()
                ->mandateRequest(
                    MandateRequest::make()
                        ->scheme('bacs')
                        ->verifyWhenAvailable()
                ),
            BillingRequestFlow::make()
                ->returnUrls(ReturnUrls::make(route('example.route')))
        )->useCustomer($user)->requestCheckoutUrl();

return Redirect::to($url);

Or fully managed request:

use GoCardlessPayment\MandateCheckout\BillingRequest;
use GoCardlessPayment\MandateCheckout\BillingRequestFlow;
use GoCardlessPayment\MandateCheckout\MandateCheckoutPage;
use GoCardlessPayment\MandateCheckout\MandateRequest;
use GoCardlessPayment\MandateCheckout\Metadata;
use GoCardlessPayment\MandateCheckout\ReturnUrls;

$url = MandateCheckoutPage::make(
            BillingRequest::make()
                ->mandateRequest(
                    MandateRequest::make()
                        ->scheme('bacs')
                        ->verifyWhenAvailable()
                )->metadata(
                    Metadata::make()
                        ->add('crm_user', $user->getKey())
                )->links(Links::make()->addCustomer($user->gocardlessKey())),
            BillingRequestFlow::make()
                ->prefilledCustomer(
                    PrefilledCustomer::make()
                        ->givenName($user->first_name)
                        ->familyName($user->last_name)
                        ->email($user->email)
                        ->postalCode($user->postalcode)
                        ->addressLine1($user->street)
                        ->addressLine2($user->locality)
                        ->city($user->town)
                        ->region($user->county)
                        ->countryCode($user->country_code)
                )
                ->returnUrls(ReturnUrls::make(route('example.route')))
        )->requestCheckoutUrl();

return Redirect::to($url);

Webhook installation

Receive webhook about created mandate and store it in database.

Local server webhooks

Firstly install cli on your laptop.

Then you can run listener with forwarding to your local site. Example:

gc listen --forward http://localhost/gocardless/webhook
# Or to jus preview webhooks content without real processing by app you can use "simple" listen method:
# gc listen

Cli commands

Import mandates

Note: if local storage not contains related to mandate "customer" import will be skipped.

php artisan gocardless-payment:import:mandate MD123FOOBAR

Credits

  • Think Studio

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-28