Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Creating a Direct order

Alexander Vizhanov edited this page Apr 27, 2017 · 4 revisions
// Create a gateway for the WorldPay Gateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('\\lembdev\\WorldPay\\Gateway');

// Initialise the gateway
$gateway->initialize([
    'serviceKey' => 'MyServiceKey',
    'clientKey'  => 'MyClientKey',
]);

$cc = new CreditCard([
    'name'        => 'EXAMPLE CUSTOMER',
    'number'      => '4444 3333 2222 1111',
    'expiryMonth' => 2,
    'expiryYear'  => 2025,
    'cvv'         => '123',
    'address1'    => 'Street name',
    'address2'    => 'optional address',
    'city'        => 'Some City',
    'postcode'    => '79016',
    'state'       => 'Some State',
    'country'     => 'USA',
    'phone'       => '+12010001155',
]);

$tokenTransaction = $gateway->createCard([
    'card'     => $cc,
    'reusable' => true,
]);

$tokenResponse = $tokenTransaction->send();
if (!$tokenResponse->isSuccessful()) {
    throw new ErrorException($tokenResponse->getMessage());
}
$token = $tokenResponse->getToken();

// Do a purchase transaction on the gateway
$transaction = $gateway->purchase([
    'amount'      => '10.00',
    'currency'    => 'USD',
    'description' => 'Order description',
    'token'       => $token
]);

$response = $transaction->send();
if ($response->isSuccessful()) {
    $orderCode = $response->getOrderCode();

    echo "Purchase transaction was successful!\n";
    echo "Order code = {$orderCode}\n";
} else {
    echo $response->getMessage();
}
Clone this wiki locally