PHP code example of lunar / payments-api-sdk

1. Go to this page and download the library: Download lunar/payments-api-sdk 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/ */

    

lunar / payments-api-sdk example snippets


$lunar = new \Lunar\Lunar($private_secret_key);
 
$payment_intent_id = $lunar->payments()->create( $args ); 
 
// fetch a payment intent
$result = $lunar->payments()->fetch($payment_intent_id);
 
// capture a transaction
$payments = $lunar->payments();
$transaction  = $payments->capture($transaction_id, [
    'amount'   => [
        'decimal'=> '10',
        'currency' => 'EUR'
    ]
]);


// void a transaction
$payments = $lunar->payments();
$transaction  = $payments->cancel($transaction_id, [
    'amount'   => [
        'decimal'=> '10',
        'currency' => 'EUR'
    ]
]);


// refund a transaction
$payments = $lunar->payments();
$transaction  = $payments->refund($transaction_id, [
    'amount'   => [
        'decimal'=> '10',
        'currency' => 'EUR'
    ]
]);


$lunar = new \Lunar\Lunar($private_secret_key);
try {
    $payments = $lunar->transactions();
    $payments->capture($transaction_id, [
          'amount'   => [
            'decimal'=> '10',
            'currency' => 'EUR'
        ]
    ]);
} catch (\Lunar\Exception\NotFound $e) {
    // The transaction was not found
} catch (\Lunar\Exception\InvalidRequest $e) {
    // Bad (invalid) request - see $e->getJsonBody() for the error
} catch (\Lunar\Exception\Forbidden $e) {
    // You are correctly authenticated but do not have access.
} catch (\Lunar\Exception\Unauthorized $e) {
    // You need to provide credentials (an app's API key)
} catch (\Lunar\Exception\Conflict $e) {
    // Everything you submitted was fine at the time of validation, but something changed in the meantime and came into conflict with this (e.g. double-capture).
} catch (\Lunar\Exception\ApiConnection $e) {
    // Network error on connecting via cURL
} catch (\Lunar\Exception\ApiException $e) {
    // Unknown api error
}