PHP code example of sahusoftcom / paypal-expresscheckout-digital-goods

1. Go to this page and download the library: Download sahusoftcom/paypal-expresscheckout-digital-goods library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sahusoftcom / paypal-expresscheckout-digital-goods example snippets



namespace App;
 
use SahusoftCom\PayPal\PaymentRequest;
use SahusoftCom\PayPal\PaymentResponse;

class PaymentController {	

    	public $apiContext;
    
	public function __construct()
	{
	    $apiContext = (object)[];
		
            $apiContext->APIUSERNAME = "YOUR-API-USERNAME";
            $apiContext->APIPASSWORD = "YOUR-API-PASSWORD";
            $apiContext->APISIGNATURE = "YOUR-API-SIGNATURE";
            $apiContext->ENDPOINT = "https://api-3t.sandbox.paypal.com/nvp";
            $apiContext->VERSION = "65.1";
            $apiContext->REDIRECTURL = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
	    
	    $data = [];
            $data['RETURNURL'] = "http://paypal.local.geekydev.com/getDone";
            $data['CANCELURL'] = "http://paypal.local.geekydev.com/getCancel";
            $data['NOTIFYURL'] = "http://paypal.local.geekydev.com/getNotified";
        
            $data['CURRENCY'] = "USD";
            $data['TOTAL_AMOUNT'] = "100";
            $data['AMOUNT'] = "100";
            $data['TAX_AMOUNT'] = "0";
            $data['DESCRIPTION'] = "Movies";
            $data['PAYMENT_ACTION'] = "SALE";
            $data['NOSHIPPING'] = "1";
        
            $data['ITEM_LIST'] = [];
            $data['ITEM_LIST'][0] = [
            	'NAME'			=> 'First Item Name',
        		'NUMBER'		=> 123,
        		'QUANTITY'		=> 1,
        		'TAX_AMOUNT'	=> 0,
        		'AMOUNT'		=> 100,
        		'URL'           => "Your product's url",
        		'DESCRIPTION'	=> 'First Name Description'
            ];
	}
	
	public function checkOut()
	{
            $object = new PaymentRequest($this->apiContext);
            $object->execute($this->data);
	}
	
	public function getDone()
	{
            $object = new \SahusoftCom\PayPal\PaymentResponse($apiContext);
            $response = $object->handle($this->data);

            echo "<pre>";
            print_r($response);
            echo "</pre>";
	}
	
	public function getCancel()
	{
	   // Do your thing
	}