alvee/worldpay

WorldPay's PHP SDK for REST APIs

dev-master 2017-03-21 13:07 UTC

This package is not auto-updated.

Last update: 2024-03-16 17:10:09 UTC


README

Laravel WorldPay Payment is a simple package that helps you to process WorldPay direct credit card payments, create orders and get orders with your Laravel 5 projects.

Install

Install this package through Composer. To your composer.json file, add:

"require": {
    "alvee/worldpay": "@dev"
}
$ composer update

Or

$ composer require alvee/worldpay:@dev

Then add the service provider in config/app.php:

Alvee\WorldPay\WorldPayServiceProvider::class,

Finally Publish the package configuration by running this CMD

php artisan vendor:publish

Configuration

Now go to config/worldpay.php.

Set your SDK configuration.

server = sandbox or live

Account credentials from developer portal
[Test Account]
sandbox.service = T_C_8b253cda-26d5-4917-bc39-6224c07d63tc
sandbox.client = T_C_8b253cda-26d5-4917-bc39-6224c07d63tc

[Live Account]
live.service = T_C_8b253cda-26d5-4917-bc39-6224c07d63tc
live.client = T_C_8b253cda-26d5-4917-bc39-6224c07d63tc

Usage

Copy routes and paste in your route file

Route::get('/worldpay', function () {
    return view('vendor/alvee/worldpay');
});

Route::post('/charge', function (\Illuminate\Http\Request $request) {
    $token    = $request->input( 'token' );
    $total    = 50;
    $key      = config('worldpay.sandbox.client');
    $worldPay = new Alvee\WorldPay\lib\Worldpay($key);

    $billing_address = array(
        'address1'    => 'Address 1 here',
        'address2'    => 'Address 2 here',
        'address3'    => 'Address 3 here',
        'postalCode'  => 'postal code here',
        'city'        => 'city here',
        'state'       => 'state here',
        'countryCode' => 'GB',
    );

    try {
        $response = $worldPay->createOrder(array(
            'token'             => $token,
            'amount'            => (int)($total . "00"),
            'currencyCode'      => 'GBP',
            'name'              => "Name on Card",
            'billingAddress'    => $billing_address,
            'orderDescription'  => 'Order description',
            'customerOrderCode' => 'Order code'
        ));
        if ($response['paymentStatus'] === 'SUCCESS') {
            $worldpayOrderCode = $response['orderCode'];
            
           echo "<pre>";
           print_r($response);
        } else {
            // The card has been declined
            throw new \Alvee\WorldPay\lib\WorldpayException(print_r($response, true));
        }
    } catch (Alvee\WorldPay\lib\WorldpayException $e) {
        echo 'Error code: ' . $e->getCustomCode() . '
              HTTP status code:' . $e->getHttpStatusCode() . '
              Error description: ' . $e->getDescription() . '
              Error message: ' . $e->getMessage();

        // The card has been declined
    } catch (\Exception $e) {
        // The card has been declined
        echo 'Error message: ' . $e->getMessage();
    }
});

Change log

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email imran.sheikh834@gmail.com instead of using the issue tracker.

Credits