PHP code example of cmpayments / payments-sdk-php

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

    

cmpayments / payments-sdk-php example snippets



use CMPayments\PaymentSdk\Credentials;
use CMPayments\PaymentSdk\Gateway;

$gateway = new Gateway(new Credentials('your-api-key', 'your-api-secret'));


use CMPayments\PaymentSdk\Requests\IdealIssuerListRequest;

$issuers = $gateway->execute(new IdealIssuerListRequest());

foreach ($issuers as $name => $id) {
    // $name is now 'ABN AMRO Bank', 'Rabobank', 'ING', etc.
    // $id is now 'ABNANL2A', 'RABONL2U', 'INGBNL2A', etc.
}


use CMPayments\PaymentSdk\Entities\Charge;
use CMPayments\PaymentSdk\Entities\IdealPayment;
use CMPayments\PaymentSdk\Requests\CreateChargeRequest;
use Money\Money;

//  Create both a charge and a payment object
$payment = new IdealPayment(Money::EUR(500), 'RABONL2U', 'your-unique-purchase-id', 'A description of the transaction');
$charge = new Charge(Money::EUR(500), [$payment]);

$response = $gateway->execute(new CreateChargeRequest($charge));

//  The id of the charge is available as $response->charge_id, the id of the payment in $response->payments[0]->payment_id
//  These ids are in the form of ch- (or charge) or pt- (for payment), followed by a uuid v4.
//  To have the user complete the payment, redirect them to $response->payments[0]->payment_details->authentication_url


use CMPayments\PaymentSdk\Requests\ViewChargeRequest;
use CMPayments\PaymentSdk\Requests\ViewPaymentRequest;

$response = $gateway->execute(
    new ViewChargeRequest('ch-fd0e1e2d-f994-4afc-a0b6-f7e76550fc31')
);
$response = $gateway->execute(
    new ViewPaymentRequest('pt-297bba0f-5fae-4ec2-8c0f-dfbc0f62f6b0')
);


use \CMPayments\PaymentSdk\MoneyConverter;
$converter = new MoneyConverter();

$money = $converter->fromAmountAndCurrency(5.00, 'EUR');

$amount = $converter->toFloat($money);
composer