PHP code example of alphagov / pay-integration-php

1. Go to this page and download the library: Download alphagov/pay-integration-php 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/ */

    

alphagov / pay-integration-php example snippets


$client = new \Alphagov\Pay\Client([
    'apiKey'        => '{your api key}',
    'httpClient'    => new \Http\Adapter\Guzzle6\Client
]);

'baseUrl' => '{api base url}'

createPayment( $amount, $reference, $description, UriInterface $returnUrl )

try {

    $response = $client->createPayment(
        10 * 100, // £10
        'id-123',
        'Payment for x, y and z.',
        new \GuzzleHttp\Psr7\Uri('https://www.example.service.gov.uk/pay/response')
    );

} catch (PayException $e){}

getPayment( $payment )

try {

    $response = $client->getPayment( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}

cancelPayment( $payment )

try {

    $response = $client->cancelPayment( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}

refundPayment( $payment, $amount, $refundAmountAvailable = null )

try {

    $response = $client->refundPayment( 
    	'hu20sqlact5260q2nanm0q8u93', 
        10 * 100, // £10
        50 * 100  // £50
    );

} catch (PayException $e){}

getPaymentRefunds( $payment )

try {

    $response = $client->getPaymentRefunds( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}

getPaymentRefund( $payment, $refund )

try {

    $response = $client->getPaymentRefunds( 
      'hu20sqlact5260q2nanm0q8u93', 
      'j2cg5v7et0424d7shtrt7r0mj'
    );

} catch (PayException $e){}

getPaymentEvents( $payment )

try {

    $response = $client->getPaymentEvents( 'hu20sqlact5260q2nanm0q8u93' );

} catch (PayException $e){}

searchPayments( array $filters = array() )

try {

    $response = $client->searchPayments([
    	'from_date' => new \DateTime('2015-08-14T12:35:00Z'),
        'page' => '2',
        'display_size' => '50'
    ]);

} catch (NotifyException $e){}

$response->payment_id
$response->created_date
// etc...

$response->getPaymentPageUrl();

$response->isFinished()

$response->isSuccess()

$response->isCreated()
$response->isStarted()
$response->isSubmitted()
$response->isFailed()
$response->isCancelled()
$response->isError()

$response->refund_id
$response->status
$response->amount
// etc...

$response->state
$response->updated
// etc...
sh
composer