paygreen/paygreen-php

PayGreen PHP SDK

1.0.9 2022-01-19 13:59 UTC

This package is auto-updated.

Last update: 2022-01-19 15:24:11 UTC


README

Installation

composer require paygreen/paygreen-php

Requirements

Getting Started

use Http\Client\Curl\Client;
use Paygreen\Sdk\Payment\V2\PaymentClient;

$environment = new Environment('YOUR_PUBLIC_KEY', 'YOUR_PRIVATE_KEY', 'SANDBOX', 2);

$client = new PaymentClient(new Client(), $environment);

$customer = new Paygreen\Sdk\Payment\V2\Model\Customer();
$customer->setId('my-customer-id');
$customer->setEmail('john.doe@customer.fr');
// ... and setStreetLineOne, setLastname

$shippingAddress = new Paygreen\Sdk\Payment\V2\Model\Address();
$shippingAddress->setCity('London');
// ... and setStreetLineOne, setCountryCode, setPostcode

$billingAddress = new Paygreen\Sdk\Payment\V2\Model\Address();
$billingAddress->setCity('London');
// ... and setStreetLineOne, setCountryCode, setPostcode

$order = new Paygreen\Sdk\Payment\V2\Model\Order();
$order->setCustomer($customer);
$order->setBillingAddress($billingAddress);
$order->setShippingAddress($shippingAddress);
$order->setReference('my-order-reference');
$order->setAmount(2650);
$order->setCurrency('EUR');

$paymentOrder = new Paygreen\Sdk\Payment\V2\Model\PaymentOrder();
$paymentOrder->setType('CASH');
$paymentOrder->setOrder($order);
$paymentOrder->setNotifiedUrl('https://localhost/notify');

try {
    $response = $paymentClient->createCashPayment($paymentOrder);
} catch (Paygreen\Sdk\Core\Exception\ConstraintViolationException $exception) {
    // Here you can catch constraint validation errors.
}

Documentation

See the docs.

Testing

Start docker stack:

docker-compose up -d

Run tests:

docker-compose exec php vendor/bin/phpunit tests