Jump to content
neildaemond

get and post variables are not being passed to page

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

Share this post


Link to post
Share on other sites

could you please provide a code sample, so we could take a look.

thank you.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Template caching is set from setup => templates => template name => cache

Share this post


Link to post
Share on other sites

Solved!

Well, the cache wasn't on but apeisa's direction made me try out other template settings...

I went to

setup => templates => template name => urls

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

Now it works :D

Thanks!

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By brdje
      Greetings,
       
      I've created a product database which all use the template product.php and are published on the website.
      I'm trying to create an overview table with pagination of all the products, but using $pages->get does not return an object, only the object title.
      $products = $pages->get("template=product, limit=10"); This returns 10 strings in the frontend but not the object. When looping over the result set to get product fields, i get the following error:
      Notice: Trying to get property 'title' of non-object
       
      Because the product database is fairly large, i've added a pagination using the same query and this does return all the pages, but i can't click on the links that the paginator renders.
      $results = $pages->find("template=product, limit=10"); if($results->getTotal() > 10) { echo $results->renderPager(array( "nextItemLabel" => "Volgende", "previousItemLabel" => "Vorige", "currentItemClass" => 'active' )); }
      I've added the option in the template to allow page numbers. When i navigate to the link manually, i still end up seeing the 10 first products.
       
      I've tried changing several settings around, but i'm a bit stuck on how to resolve these issues. Do you have any advice what I need to adjust?
      Thanks in advance for your feedback.
       
       
    • By iipa
      Hello forum!
      I have a site, where I want to remember two settings defined by user:
      1) Theme (light or dark)
      2) Language (Finnish or English)
      Because user makes changes to these settings on client side, I am a bit lost with how can I save them in ProcessWire $session variable? I would like to use $session for more reliable saving, and since it is only two variables I will use, I doubt it will become too resource-needy.
      I have tried using jQuery's post() -method referring to a file in Templates folder (theme.php), but I get 403 Forbidden Error. I don't like the idea of trying to post to same file user currently is in, which is why I thought having a separate file would be good in this.
      Contents of theme.php:
      <?php namespace ProcessWire; header('Access-Control-Allow-Origin: https://domain.com'); $theme = $input->post['theme']; if(!empty($theme)) $session->theme = $theme; ?> Long story short: Does anybody have any pro tips I could use with setting and getting $session variables?
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By pwFoo
      With JS fetch() it is a bit tricky to get for example $_POST populated (params need to be FormData / forms), but would it possible to get PW $input (get, post, urlSegments, queryString) working for fetch requests?
      Is there a fix / hook / workaround to solve it PW side?
×
×
  • Create New...