Jump to content

get and post variables are not being passed to page


neildaemond
 Share

Recommended Posts

I'm trying to get Paypal express checkout working... After going through the process, paypal redirects me back to my site where I'm supposed to grab the get variable 'token'

anyways, I could never see it, and finally tried getting paypal to redirect to a page outside the PW site with the same code. The variables were now there.

Come to think of it, I haven't been able to post forms to other pages either. The forms work when they post to themselves, but not when they post to other pages.

Is this a security measure so that people cannot post false values to the page?

Perhaps there's a setting somewhere I can change?

EDIT (Solved):

I went to

setup => templates => template name => urls

and I set "should page urls end with a slash?" to NO.

EDIT (Even Better Solution):

Make sure my return urls have slashes on them, also my urls in forms. Thanks Soma!

Edited by neildaemond
Link to comment
Share on other sites

u.have pw tamplate caches turded on?

Hmm, I don't remember ever turning it on. I'm not 100% how to check, but under modules the 'Cache' module (under Pagefield) isn't installed, and the 'Markup Cache' and 'Page Render' modules are permanently installed and I just tried clearing them now... didn't work

as for the code, to start with I used pretty much the exact same code from here http://coding.smashingmagazine.com/2011/09/05/getting-started-with-the-paypal-api/

this part went in my 'payment' page

class Paypal {
  /**
   * Last error message(s)
   * @var array
   */
  protected $_errors = array();

  /**
   * API Credentials
   * Use the correct credentials for the environment in use (Live / Sandbox)
   * @var array
   */
  protected $_credentials = array(
  'USER' => 'seller_1297608781_biz_api1.lionite.com',
  'PWD' => '1297608792',
  'SIGNATURE' => 'A3g66.FS3NAf4mkHn3BDQdpo6JD.ACcPc4wMrInvUEqO3Uapovity47p',
  );

  /**
   * API endpoint
   * Live - https://api-3t.paypal.com/nvp
   * Sandbox - https://api-3t.sandbox.paypal.com/nvp
   * @var string
   */
  protected $_endPoint = 'https://api-3t.sandbox.paypal.com/nvp';

  /**
   * API Version
   * @var string
   */
  protected $_version = '74.0';

  /**
   * Make API request
   *
   * @param string $method string API method to request
   * @param array $params Additional request parameters
   * @return array / boolean Response array / boolean false on failure
   */
  public function request($method,$params = array()) {
  $this -> _errors = array();
  if( empty($method) ) { //Check if API method is not empty
	 $this -> _errors = array('API method is missing');
	 return false;
  }

  //Our request parameters
  $requestParams = array(
	 'METHOD' => $method,
	 'VERSION' => $this -> _version
  ) + $this -> _credentials;

  //Building our NVP string
  $request = http_build_query($requestParams + $params);

  //cURL settings
  $curlOptions = array (
	 CURLOPT_URL => $this -> _endPoint,
	 CURLOPT_VERBOSE => 1,
	 CURLOPT_SSL_VERIFYPEER => true,
	 CURLOPT_SSL_VERIFYHOST => 2,
	 CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem', //CA cert file
	 CURLOPT_RETURNTRANSFER => 1,
	 CURLOPT_POST => 1,
	 CURLOPT_POSTFIELDS => $request
  );

  $ch = curl_init();
  curl_setopt_array($ch,$curlOptions);

  //Sending our request - $response will hold the API response
  $response = curl_exec($ch);

  //Checking for cURL errors
  if (curl_errno($ch)) {
	 $this -> _errors = curl_error($ch);
	 curl_close($ch);
	 return false;
	 //Handle errors
  } else  {
	 curl_close($ch);
	 $responseArray = array();
	 parse_str($response,$responseArray); // Break the NVP string to an array
	 return $responseArray;
  }
  }
}
//Our request parameters
$requestParams = array(
  'RETURNURL' => 'http://www.yourdomain.com/payment/success',
  'CANCELURL' => 'http://www.yourdomain.com/payment/cancelled'
);

$orderParams = array(
  'PAYMENTREQUEST_0_AMT' => '500',
  'PAYMENTREQUEST_0_SHIPPINGAMT' => '4',
  'PAYMENTREQUEST_0_CURRENCYCODE' => 'GBP',
  'PAYMENTREQUEST_0_ITEMAMT' => '496'
);

$item = array(
  'L_PAYMENTREQUEST_0_NAME0' => 'iPhone',
  'L_PAYMENTREQUEST_0_DESC0' => 'White iPhone, 16GB',
  'L_PAYMENTREQUEST_0_AMT0' => '496',
  'L_PAYMENTREQUEST_0_QTY0' => '1'
);

$paypal = new Paypal();
$response = $paypal -> request('SetExpressCheckout',$requestParams + $orderParams + $item);

if(is_array($response) && $response['ACK'] == 'Success') { //Request successful
  $token = $response['TOKEN'];
  header( 'Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) );
}

and this part goes in my 'success' page which paypal redirects me to after the paypal user logs in and confirms the purchase on their end


class Paypal {
...
}
if( isset($_GET['token']) && !empty($_GET['token']) ) { // Token parameter exists
  // Get checkout details, including buyer information.
  // We can save it for future reference or cross-check with the data we have
  $paypal = new Paypal();
  $checkoutDetails = $paypal -> request('GetExpressCheckoutDetails', array('TOKEN' => $_GET['token']));

  // Complete the checkout transaction
  $requestParams = array(
      'TOKEN' => $_GET['token'],
      'PAYMENTACTION' => 'Sale',
      'PAYERID' => $_GET['PayerID'],
      'PAYMENTREQUEST_0_AMT' => '500', // Same amount as in the original request
      'PAYMENTREQUEST_0_CURRENCYCODE' => 'GBP' // Same currency as the original request
  );

  $response = $paypal -> request('DoExpressCheckoutPayment',$requestParams);
  if( is_array($response) && $response['ACK'] == 'Success') { // Payment successful
       echo "success"
      // We'll fetch the transaction ID for internal bookkeeping
      $transactionId = $response['PAYMENTINFO_0_TRANSACTIONID'];
  }
}

Note: The following code (from above) needs to have your specific details

protected $_credentials = array(
  'USER' => 'seller_1297608781_biz_api1.lionite.com',
  'PWD' => '1297608792',
  'SIGNATURE' => 'A3g66.FS3NAf4mkHn3BDQdpo6JD.ACcPc4wMrInvUEqO3Uapovity47p',
  );

$requestParams = array(
  'RETURNURL' => 'http://www.yourdomain.com/payment/success',
  'CANCELURL' => 'http://www.yourdomain.com/payment/cancelled'
);

also, you need a cacert.pem. I got from cURL website and put it in same folder as Paypal class

again, It works if my success page is in another success.php file outside of my PW site.

Also, I'm using PW 2.2.9 and installed it using the blank profile (i think soma made).

Thanks guys, this issue I'm having is really frustrating me, is quite crucial, and needed it working days ago.. haha.

Link to comment
Share on other sites

Dont need to turn of slash trailing. Just add the slash to the return url.

oh facepalm :'( ... so much heartache for something so stupid! I knew I was doing something very wrong because no one seemed to have this same problem... this is a much better solution :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...