PHP code example of vladshut / ecurring-api

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

    

vladshut / ecurring-api example snippets


use VladShut\eCurring\eCurringClientFactory;
use VladShut\eCurring\Resource\Customer;
use VladShut\eCurring\Resource\Transaction\PaymentMethod;

$client = eCurringClientFactory::create('<ApiKey>');

$customer = Customer::new(
    'Luke',
    'Skywalker',
    PaymentMethod::directDebit(),
    'L Skywalker',
    'NL17ABNA1171403585'
);

$customer = $client->createCustomer($customer);

use VladShut\eCurring\eCurringClientFactory;
use VladShut\eCurring\Resource\Subscription;
use VladShut\eCurring\Resource\Subscription\Mandate;

$client = eCurringClientFactory::create('<ApiKey>');

$customer = $client->getCustomer(1);
$subscriptionPlan = $client->getSubscriptionPlan(2);


/**
 * Mandate is Optional, if you dont provide it eCurring wil create a
 * mandate for you and the customer can accept the mandate via eCurring
 * see https://docs.ecurring.com/subscriptions/create
 */
$mandate = new Mandate(
    'MDT-000001',
    true,
    new DateTimeImmutable('2018-10-16')
);

$subscription = Subscription::new(
    $customer,
    $subscriptionPlan,
    $mandate
);

$subscription = $client->createSubscription($subscription);

use VladShut\eCurring\eCurringClientFactory;
use VladShut\eCurring\Resource\Transaction;
use Money\Money;

$client = eCurringClientFactory::create('<ApiKey>');

$subscription = $client->getSubscription(1);

$transaction = Transaction::new(
    $subscription,
    Money::EUR(1000),
    new DateTimeImmutable('2018-11-20')
);

$transaction = $client->createTransaction($transaction);

use VladShut\eCurring\eCurringClientFactory;
use VladShut\eCurring\Resource\Curser\Pagination;

$client = eCurringClientFactory::create('<ApiKey>');

$pagination =  new Pagination(2); //-- [optional] Lets start pagination on page 2
$customers = $client->getCustomers($pagination);

$customers->disableAutoload(); //-- just iterate over one page

foreach ($customers as $customer) {
    // Do something with the customer
}