2017 © Pedro Peláez
 

library yii2-paypal

Process with Paypal

image

kun391/yii2-paypal

Process with Paypal

  • Tuesday, February 2, 2016
  • by kun391
  • Repository
  • 1 Watchers
  • 14 Stars
  • 911 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 3 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

Process Payment with paypal for Yii2

Build Status Latest Stable Version Total Downloads Monthly Downloads Daily Downloads, (*1)

Requirements

  • PHP >= 5.4
  • php5-curl (System)

Installation

Add to the composer.json file following section:, (*2)

php composer.phar require --prefer-dist kun391/yii2-paypal:"*"

or, (*3)

"kun391/yii2-paypal":"dev-master"

Add to to you Yii2 config file this part with component settings:, (*4)

Create file config.php for RESTAPI and config.php for Classic API every where:, (*5)

  • ClassicAPI
/**
 * Information PAYPAL's enviroments for classic API
 * @var string
 */

// E.g:
// If enviroment is Development you should use mode = sandbox and endpoint = api.sandbox.paypal.com
// [
//     'acct1.UserName'  => 'nguyentruongthanh.dn-facilitator-1_api1.gmail.com',
//     'acct1.Password'  => 'GRHYUV2DJHNBFTAA',
//     'acct1.Signature' => 'APP9kKh6roKmPNKj6yBK5oSwdD39ADujX4sfPXjr.hGf1wjRi1THwoVq',
//     'mode'            => 'sandbox',
// ];

// E.g:
// If enviroment is live you should use mode = live
// [
//     'acct1.UserName'  => 'nguyentruongthanh.dn-facilitator-1_api1.gmail.com',
//     'acct1.Password'  => 'GRHYUV2DJHNBFTAA',
//     'acct1.Signature' => 'APP9kKh6roKmPNKj6yBK5oSwdD39ADujX4sfPXjr.hGf1wjRi1THwoVq',
//     'mode'            => 'live',
// ];

return  [
    'acct1.UserName'  => 'nguyentruongthanh.dn-facilitator-1_api1.gmail.com',
    'acct1.Password'  => 'GRHYUV2DJHNBFTAA',
    'acct1.Signature' => 'APP9kKh6roKmPNKj6yBK5oSwdD39ADujX4sfPXjr.hGf1wjRi1THwoVq',
    'mode'            => 'sandbox',
];

  • RestAPI
/**
 * Information PAYPAL's enviroments
 * @var string
 */

// E.g:
// If enviroment is Development you should use mode = sandbox and endpoint = api.sandbox.paypal.com
// $setting = [
//     'endpoint'       => 'api.sandbox.paypal.com',
//     'client_id'      => 'AV92BhCOYzF4Vejrbphu1ksMn4KYSlvbzCTcbLdOMixBvAS7sQZhOvMNkMoG',
//     'secret'         => 'EDdjYm7i8w2XZwWGyTqPfPDJim2dUV1hX_3dhY0fR-HulrENli6043rY_0GO1ro1gnkxVe3bMWNDikvq',
//     'business_owner' => 'nguyentruongthanh.dn-facilitator-1@gmail.com',
// ];

// E.g:
// If enviroment is live you should use mode = live and endpoint = api.paypal.com
// $setting = [
//     'endpoint'       => 'api.paypal.com',
//     'client_id'      => 'AV92BhCOYzF4Vejrbphu1ksMn4KYSlvbzCTcbLdOMixBvAS7sQZhOvMNkMoG',
//     'secret'         => 'EDdjYm7i8w2XZwWGyTqPfPDJim2dUV1hX_3dhY0fR-HulrENli6043rY_0GO1ro1gnkxVe3bMWNDikvq',
//     'business_owner' => 'nguyentruongthanh.dn-facilitator-1@gmail.com',
// ];

$setting = [
    'endpoint'       => 'api.sandbox.paypal.com',
    'client_id'      => 'AX9sEz0g3cCzD_heoGyedx7LKSuEx1Lx7H8aGXIrzQmDhqV-V5bV0sbVFc195mNKbE81OkAPZZi_7dfa',
    'secret'         => 'EDdjYm7i8w2XZwWGyTqPfPDJim2dUV1hX_3dhY0fR-HulrENli6043rY_0GO1ro1gnkxVe3bMWNDikvq',
    'business_owner' => 'nguyentruongthanh.dn-facilitator-1@gmail.com',
];

return \yii\helpers\ArrayHelper::merge(['config' => [
        'mode'                   => 'sandbox',
        'http.ConnectionTimeOut' => 60,
        'log.LogEnabled'         => false,
        'log.FileName'           => '@api/runtime/PayPal.log',
        'log.LogLevel'           => 'FINE',
    ]
], $setting);

Add to config to component of file main.php:, (*6)

...
'payPalClassic'    => [
    'class'        => 'kun391\paypal\ClassicAPI',
    'pathFileConfig' => '',
],
'payPalRest'               => [
    'class'        => 'kun391\paypal\RestAPI',
    'pathFileConfig' => '',
    'successUrl' => '' //full url action return url
    'cancelUrl' => '' //full url action return url
],
...

=========, (*7)

Usage

REST API, (*8)

  • Create a invoice with paypal
//define params for request 
$params = [
    'currency' => 'Usd', // only support currency same PayPal
    'email' => 'nguyentruongthanh.dn@gmail.com',
    'items' => [
        [
            'name' => 'Vinamilk',
            'quantity' => 2,
            'price' => 100
        ],
        [
            'name' => 'Pepsi',
            'quantity' => 3,
            'price' => 90
        ]
    ]
];

// information invoice response
$response = Yii::$app->payPalRest->createInvoice($params);
  • Get link checkout on PayPal
//define params for request 
$params = [
    'currency' => 'USD', // only support currency same PayPal
    'description' => 'Buy some item',
    'total_price' => 470,
    'email' => 'nguyentruongthanh.dn@gmail.com',
    'items' => [
        [
            'name' => 'Vinamilk',
            'quantity' => 2,
            'price' => 100
        ],
        [
            'name' => 'Pepsi',
            'quantity' => 3,
            'price' => 90
        ]
    ]
];

$response = Yii::$app->payPalRest->getLinkCheckOut($params);

CLASSIC API, (*9)

  • Get Information Account

Attribute matchCriteria you can specify either NAME or NONE. Default: None Attribute firstName and lastName (Required) if matchCriteria is name. $params = [ 'email' => 'nguyentruongthanh.dn@gmail.com', 'matchCriteria' => 'name', 'firstName' => 'Thanh', 'lastName' => 'Nguyen' ]; $response = Yii::$app->payPalClassic->getAccountInfo($params);
  • Send money (Mass Pay)

```php $params = [ 'email' => 'nguyentruongthanh.dn@gmail.com', 'balance' => 200, ];, (*10)

$response = Yii::$app->payPalClassic->sendMoney($params); ``, (*11)

The Versions

31/07 2015

dev-initial

dev-initial https://github.com/kun391/yii2-paypal

Process with Paypal

  Sources   Download

The Requires

 

The Development Requires

api yii2 paypal