bitcko / yii2-bitcko-paypal-api

Bitcko Yii2 Paypal Api Extension use to integrate Paypal payments in your project using Paylpal php SDK
Apache License 2.0
2 stars 8 forks source link

Go live feature FIX here #2

Open scastel83 opened 4 years ago

scastel83 commented 4 years ago

Oh man, here is the fix : you will need to modify the file located in the vendor folder

the file is located here in your yii
/vendor/bitcko/yii2-bitcko-paypal-api/PayPalRestApi.php

File contents

#begin modification a top of the file
namespace bitcko\paypalrestapi;

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Api\PaymentExecution;
#add thi one it is new -------------------
use PayPal\Rest\ApiContext;
use PayPal\Exception\PayPalConnectionException;
use yii\helpers\Url;
use Yii;

class PayPalRestApi
{
    private $apiContext;
    public $redirectUrl;

    public function __construct()
    {

        $cred = new \PayPal\Auth\OAuthTokenCredential(
                Yii::$app->params['payPalClientId'],
                Yii::$app->params['payPalClientSecret']
            );

            $apiContext = new ApiContext($cred);
#####here is the toggle to change from live to dev ######          
  $apiContext->setConfig(
                  array(
                   # 'mode' => 'sandbox',
                    'mode' => 'live',
                  )
            );

        $this->apiContext = $apiContext;
    }

#end of section to modify :) in this file
gabriele-carbonai commented 4 years ago

Thank you for that, you help me a lot.

marcis commented 3 years ago

What about setting it from a param?

For example:

 $apiContext->setConfig(
    array(
        # 'mode' => 'sandbox',
        'mode' => Yii::$app->params['payPalMode'],
    )
);
HJPoyntz commented 3 months ago

You can override the class like so if you still need to use composer:

Add this to web.php.

 'PayPalRestApi' => [
            'class'=> 'app\overrides\PaypalRestApiOverride',
            'redirectUrl'=> 'products/make-payment',
]

It doesn't strictly have to be located here but just add

<?php

namespace app\overrides;

use bitcko\paypalrestapi\PayPalRestApi;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Api\PaymentExecution;
#add thi one it is new -------------------
use PayPal\Rest\ApiContext;
use PayPal\Exception\PayPalConnectionException;
use yii\helpers\Url;
use Yii;

class PaypalRestApiOverride extends PayPalRestApi{
  // Copy all the class methods/variables from PayPalRestApi into here
}