Yii Framework-PayPal Integration in Web application and Testing With PayPal Sandbox Account Credentials

Mithun Kadyada
Tensult Blogs
Published in
4 min readSep 27, 2019

This Blog has moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

Ref: https://developer.paypal.com/docs/checkout/#how-the-buttons-work

Overview:

PayPal Integration helps business organization to receive online payment from customers of other countries. Adding PayPal to Web Application can be achieved in two ways :one is Integrating PayPal smart buttons and the other way is PayPal Extension through PayPal SDKs.

In this article,I am going to explain about PayPal Extension through PayPal SDKs in Yii Framework and testing the work-flow with PayPal Sandbox account.

To Integrate And test PayPal Integration you must follow the following steps:

  1. Creating PayPal Account and Login as PayPal Developer.
  • Go to - PayPal and Create a Personal PayPal Account.
  • Go to - Developer and Login with your PayPal Account Credentials.
  • Go to - SANDBOX in your Dashboard — >Create Account.

2. Creating and Setting up PayPal Sandbox Account.

  • Fill In the Create Account Form.(Create one Personal or buyer Account and one Business or merchant Account)

~Country

a) If you need to test transactions for a PayPal account based in a particular country you may set that here.

~Account Type

a. Business — Fully functional test seller account or Business Account(can also be used as a buyer account.)

b. Personal — Test buyer account.

~Email Address

a. The email address entered here needs to be valid, however, no PayPal emails will be sent to this address.

b. Email notifications PayPal would typically send will be available within the Notifications section of the sandbox account after it has been created.

~Password

a. This is the password that will be used to login to the PayPal sandbox account you are creating.

~PayPal Balance

a. If you like to set an initial balance for the account you are created you may do so here. This can be helpful if you would like to test payments with PayPal funds.

~Bank Verified Account

a. In most cases you should set this to Yes. If you would like to specifically test payments that are from non-verified accounts, though, you could set that up here.

  • After Creating Business Account ,Got To SANDBOX →Accounts →Manage Accounts → Click on View/Edit Account
  • Click on API Credentials to get Your Sandbox API-credentials.

3. Setting Up PayPal Integration in Your Yii Web Application.

  • A PayPal component for Yii framework to utilize Express Checkout and Direct Payment APIs. A simple component that will help you easily implement Express Checkout and Direct Payment APIs in your Yii applications.
  • Requirements:(CURL PHP extension and API Credentials).
  • Installation - Download the extension from the Github repo, extract the files to their appropriate folders. After place this code within your configuration file (main.php) inside the ‘components’ section.
  • Change ‘apiLive’ => true , if you’re using Your PayPal Business Account Credentials Instead of Sandbox Account Credentials.
  • Controller : If you’re order-form is calling a particular action in your Controller, then paste the following code in your action to redirect PayPal.

The Above code will call directly PayPal `DoExpressCheckout` API within YourController . If You want call `DoDirectPayment` method paste the following function in Your code.

Note:

  • DoDirectPayment will not support all the countries. Currently it is only available to US, UK, and Canadian merchants.
  • We are calling the PayPal API directly from YourController. You can also call through paypalController with the following code.
list($paypal) = Yii::app()->createController('paypal');$paypal->actionBuy($paymentInfo);

References:

--

--