bitcko/yii2-bitcko-paypal-api

Bitcko Yii2 Paypal Api Extension use to integrate Paypal payments in your project using Paylpal php SDK

Installs: 6 426

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 8

Open Issues: 2

Type:yii2-extension

dev-master 2018-12-27 09:53 UTC

This package is not auto-updated.

Last update: 2024-11-16 02:11:35 UTC


README

Yii2 Bitcko PayPal Api extension use to integrate simple PayPal payment in your website.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require bitcko/yii2-bitcko-paypal-api:dev-master

or add

"bitcko/bitcko/yii2-bitcko-paypal-api": "dev-master"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

  1. Create developer account in PayPal and then create an app. PayPal Developer Dashboard.
  2. Copy and paste the client Id and client secret in params.php file that exists in app config directory:
<?php

return [
    'adminEmail' => 'admin@example.com',
    'payPalClientId'=>'app client id here',
    'payPalClientSecret'=>'app client secret here'
];
  1. Configure the extension in components section in web.php file exists in app config directory:
<?php
'components'=> [
    ...
 'PayPalRestApi'=>[
            'class'=>'bitcko\paypalrestapi\PayPalRestApi',
            'redirectUrl'=>'/site/make-payment', // Redirect Url after payment
            ]
            ...
        ]
  1. Controller example: call first the checkout action that will redirect you to the redirectUrl you mentioned in the previous step, in this example ("/site/make-payment")
<?php

namespace app\controllers;

use Yii;

use yii\web\Controller;

class SiteController extends Controller
{
   
    public function actionCheckout(){
        // Setup order information array with all items
        $params = [
            'method'=>'paypal',
            'intent'=>'sale',
            'order'=>[
                'description'=>'Payment description',
                'subtotal'=>44,
                'shippingCost'=>0,
                'total'=>44,
                'currency'=>'USD',
                'items'=>[
                    [
                        'name'=>'Item one',
                        'price'=>10,
                        'quantity'=>1,
                        'currency'=>'USD'
                    ],
                    [
                        'name'=>'Item two',
                        'price'=>12,
                        'quantity'=>2,
                        'currency'=>'USD'
                    ],
                    [
                        'name'=>'Item three',
                        'price'=>1,
                        'quantity'=>10,
                        'currency'=>'USD'
                    ],

                ]

            ]
        ];
        
        // In this action you will redirect to the PayPpal website to login with you buyer account and complete the payment
        Yii::$app->PayPalRestApi->checkOut($params);
    }

    public function actionMakePayment(){
         // Setup order information array 
        $params = [
            'order'=>[
                'description'=>'Payment description',
                'subtotal'=>44,
                'shippingCost'=>0,
                'total'=>44,
                'currency'=>'USD',
            ]
        ];
      // In case of payment success this will return the payment object that contains all information about the order
      // In case of failure it will return Null
      return  Yii::$app->PayPalRestApi->processPayment($params);

    }
}