PHP code example of think.studio / laravel-gocardless-payment

1. Go to this page and download the library: Download think.studio/laravel-gocardless-payment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

think.studio / laravel-gocardless-payment example snippets



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();
    });
}

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);

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);
dotenv
GOCARDLESS_ACCESS_TOKEN="sandbox_XxxxXXXxxxxXXXXxx-xXxxxXXx_XX-xxxX"
GOCARDLESS_WEBHOOK_ENDPOINT_SECRET="XXXXxxxxXXXXXxxxXXXXxxxXXXXxx"