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

Creating a token

Alexander Vizhanov edited this page Apr 27, 2017 · 3 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',
]);


// Create a credit card object
$newCard = new CreditCard([
    'name'        => 'EXAMPLE CUSTOMER',
    'number'      => '4444 3333 2222 1111',
    'expiryMonth' => 2,
    'expiryYear'  => 2025,
    'cvv'         => '123',
    'issueNumber' => 1, // optional
    'startMonth'  => 2, // optional
    'startYear'   => 2013, // optional
]);

// Do a create card transaction on the gateway
$response = $gateway->createCard([
    'card'     => $newCard,
    'reusable' => true,
])->send();

if ($response->isSuccessful()) {
    echo "Gateway createCard was successful.\n";

    $cardToken = $response->getToken();
    echo "Credit Card token = {$cardToken}\n";

    $cardDetails = $response->getCard();
} else {
    echo $response->getMessage();
}
Clone this wiki locally