Paypal payment

Paypal submit form perveiw

download from google drive
define('APP_TOPDIR', realpath(__DIR__ . '/paypal/src/php'));
set_include_path(APP_TOPDIR . PATH_SEPARATOR . get_include_path());
require_once('paypal/examples/gwc.autoloader.php');
$paypal = \Rbs\Payment\Factory::factory('Paypal');



$produt_title = "Watch";
$produt_id = 5;
$amount = 20;
$friend1 = "Farid Milon";
$friend2 = "Maruf Hossen";
$custom_data = array('user_id'=>1, 'friend1' => $friend1, 'friend2' => $friend2);
$paypal->setAccountIdentifier('milon-facilitator2@webalive.com.au');
$paypal->setCurrency('AUD');
$paypal->setTestMode(true);
$paypal->setSingleItem($produt_title, $amount, $produt_id);
//$paypal->setOrderNumber(100);

$paypal->setCustomField($custom_data);
$paypal->setReturnOnSuccessUrl('paypal_success.php');
$paypal->setReturnOnFailureUrl('paypal_ipn.php');
$paypal->setNotificationUrl('paypal_cancel.php');
$paypal->proceed();


paypal_ipn.php

$filename ='log.php';
file_put_contents ($filename , print_r($_POST, true));

if(isset($_POST['txn_id']) && isset($_POST['payment_status']) && strtoupper($_POST['payment_status'])=='COMPLETED'){

$paypal_response = $_POST;
$explode = explode("&", $paypal_response['custom']);
$custom_array = array();
if(count($explode)>0){
  foreach($explode as $str){
  $exp = explode('=', $str);
  $custom_array[$exp[0]] = $exp[1];
  }
}

$save_data = array();
$save_data['customer_id'] = $custom_array['user_id'];
$save_data['friends'] = $custom_array['friend1'].', '.$custom_array['friend2'];
$save_data['event_id'] = $paypal_response['item_number'];
$save_data['title'] = $paypal_response['item_name'];
$save_data['txn_id'] = $paypal_response['txn_id'];
$save_data['amount'] = $paypal_response['mc_gross'];
$save_data['payment_status'] = $paypal_response['payment_status'];
$save_data['payment_date'] = date("Y-m-d H:i:s");
$save_data['address_name'] = $paypal_response['address_name'];
// save this data to orders table along with other information
}