alvee/worldpay 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alvee/worldpay

Composer 安装命令:

composer require alvee/worldpay

包简介

WorldPay's PHP SDK for REST APIs

README 文档

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

统计信息

  • 总下载量: 8.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-16