PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] Integrate Paypal PHP sdk with Cakephp 3.x

 January 01, 2022     cakephp-3.0, paypal, paypal-rest-sdk, sdk     No comments   

Issue

To use Paypal PHP SDK is quite simple but when i try to use this SDK in cakephp 3.x then it generates errors. I changed namespace name in "Paypal SDK project" to bring all files under one name space.

My cakephp project namespace name is namespace App

but namespace in Paypal SDK is namespace PayPal I just changed it to "namespace App" and put all files in PayPal folder and put that folder in "src" folder in cakephp project. but PayPal does not work using this technique.

Can you please advise me how to use this SDK in CakePHP or where to put files are best. I know there are some other techniques to make payment via paypal without SDK but i want to use SDK.

Can you please guide me little bit how to integrate PayPal PHP SDK in CakePHP.

SDK is provided here https://github.com/paypal/PayPal-PHP-SDK some payment samples are here http://paypal.github.io/PayPal-PHP-SDK/sample/


Solution

1. Use composer for installation which will manages the dependencies:

Go to your project directory (Eg:E:\xampp\htdocs\cakephp) in command promot and type following:

composer require "paypal/rest-api-sdk-php:*"

This will install latest version of paypal sdk into the vendor folder,you can go into vendor and check that.

2. Configure your environment:

Make any function for configuration of paypal in any controller you would like:

public function configuration() {
   $apiContext = new \PayPal\Rest\ApiContext(
     new \PayPal\Auth\OAuthTokenCredential(
     'YOUR APPLICATION CLIENT ID',  // you will get information about client id and secret once you have created test account in paypal sandbox  
     'YOUR APPLICATION CLIENT SECRET'  
    )
  );
 }

As you are using cakephp framework you don't need to write following line into your function as suggested in papal documentation:

// Autoload SDK package for composer based installations
 require 'vendor/autoload.php';

This is because you have already done that with autoload.php file within your vendor folder.

3. Using paypal classes:

You need to use paypal classes/namespace within your controller in this way:

namespace App\Controller; // your controller have this already

use App\Controller\AppController; // your controller have this already

use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;

4. Completely follow this quick start guide which will be pretty straight forward now:

Paypal quick start guide.

For making sandbox test accounts:(Paypal developer guide)



Answered By - Manohar Khadka
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing