Payment API

All functions related to Payment API

Buyers

Get a buyer

$client->getBuyer('buy_0000');

List buyers

$client->listBuyer();

Create a buyer

$address = new \Paygreen\Sdk\Payment\V3\Model\Address();
$address->setStreetLineOne('54 Crown Street');
$address->setCity('London');
$address->setCountryCode('UK');
$address->setPostalCode('SW14 6ZG');

$buyer = new \Paygreen\Sdk\Payment\V3\Model\Buyer();
$buyer->setReference('my-customer-id');
$buyer->setEmail('[email protected]');
$buyer->setFirstName('John');
$buyer->setLastName('Doe');
$buyer->setBillingAddress($address);

$client->createBuyer($buyer);

Update a buyer

$buyer = new \Paygreen\Sdk\Payment\V3\Model\Buyer();
$buyer->setId('buy_0000');
$buyer->setFirstName('Blank');
$buyer->setLastName('Aux');

$client->updateBuyer($buyer);

Delete a buyer

$client->deleteBuyer('buy_0000');

Payment Orders

Create a payment order

$address = new \Paygreen\Sdk\Payment\V3\Model\Address();
$address->setStreetLineOne('1 rue de Paris');
$address->setCity('Paris');
$address->setCountryCode('FR');
$address->setPostalCode('75000');

$buyer = new \Paygreen\Sdk\Payment\V3\Model\Buyer();
$buyer->setReference('my-customer-id');
$buyer->setEmail('[email protected]');
$buyer->setFirstName('John');
$buyer->setLastName('Doe');
$buyer->setBillingAddress($address);

$paymentOrder = new \Paygreen\Sdk\Payment\V3\Model\PaymentOrder();
$paymentOrder->setReference('my-order-id');
$paymentOrder->setBuyer($buyer);
$paymentOrder->setAmount(100);
$paymentOrder->setAutoCapture(true);
$paymentOrder->setCurrency('eur');
$paymentOrder->setShippingAddress($address);
$paymentOrder->setDescription('A test payment');

$response = $client->createPaymentOrder($paymentOrder);

Create a payment order with a buyer id

$address = new \Paygreen\Sdk\Payment\V3\Model\Address();
$address->setStreetLineOne('1 rue de Paris');
$address->setCity('Paris');
$address->setCountryCode('FR');
$address->setPostalCode('75000');

$buyer = new \Paygreen\Sdk\Payment\V3\Model\Buyer();
$buyer->setId('buy_0000');

$paymentOrder = new \Paygreen\Sdk\Payment\V3\Model\PaymentOrder();
$paymentOrder->setReference('my-order-id');
$paymentOrder->setBuyer($buyer);
$paymentOrder->setAmount(100);
$paymentOrder->setAutoCapture(true);
$paymentOrder->setCurrency('eur');
$paymentOrder->setShippingAddress($address);
$paymentOrder->setDescription('A test payment');

$response = $client->createPaymentOrder($paymentOrder);

Create a payment order with an instrument id

You must have a reusable id instrument.
To create an instrument id, please refer to the PaygreenJS documentation in instrument mode.

$address = new \Paygreen\Sdk\Payment\V3\Model\Address();
$address->setStreetLineOne('1 rue de Paris');
$address->setCity('Paris');
$address->setCountryCode('FR');
$address->setPostalCode('75000');

$paymentOrder = new \Paygreen\Sdk\Payment\V3\Model\PaymentOrder();
$paymentOrder->setReference('my-order-id');
$paymentOrder->setInstrument('ins_0000');
$paymentOrder->setAmount(100);
$paymentOrder->setAutoCapture(true);
$paymentOrder->setCurrency('eur');
$paymentOrder->setShippingAddress($address);
$paymentOrder->setDescription('A test payment');
// For MIT : $paymentOrder->setMerchantInitiated(true);

$response = $client->createPaymentOrder($paymentOrder);

Capture a payment order

To capture a payment order you must have set auto_capture to false during creation.
Otherwise, the capture will be done automatically, and you don't need to use this route.

// Only if $paymentOrder->setAutoCapture(false);

$response = $client->capturePaymentOrder('po_0000');

Refund a payment order

$response = $client->refundPaymentOrder('po_0000');

Instruments

Get an instrument

$client->getInstrument('ins_0000');

List instruments

$client->listInstrument();

// You can also list instruments for a specific buyer
$client->listInstrument('buy_0000');

Create an instrument

$instrument = new \Paygreen\Sdk\Payment\V3\Model\Instrument();
$instrument->setToken('card_token');
$instrument->setType('bank_card');
$instrument->setWithAuthorization(true); // Set to false if your instrument does not need authorization
$instrument->setReference('custom_instrument_reference'); // Optional

$client->createInstrument($instrument);

Delete an instrument

$client->deleteInstrument('ins_0000');

Payment Configs

List payment configs

$client->listPaymentConfig('sh_0000');

Create a payment config

$paymentConfig = new \Paygreen\Sdk\Payment\V3\Model\PaymentConfig();
$paymentConfig->setPlatform('bank_card');
$paymentConfig->setSellingContractId('sel_0000');
$paymentConfig->setCurrency('eur');
$paymentConfig->setConfig(array('config1', 'config2')); // Optional

$client->createPaymentConfig($paymentConfig, 'sh_0000');

Transaction

List transactions

$client->listTransaction('sh_0000');

// First parameter : the Shop ID that initiated the Transaction. In a Marketplace mode, this is the Marketplace Shop ID.
// Second parameter : You can also specify the beneficiary Shop ID. In a Marketplace mode, this is the sub-entity ID.
$client->listTransaction(
    'sh_0000',
    'sh_0001' // Optional
);

Get transaction

$client->getTransaction('tra_0000');