Reputation: 100175
I am using a payment method which on success returns a url like mysite/payment/sucess?auth=SDX53641sSDFSDF, but since i am using codeigniter, question marks in url are not working for me. I tried routing but it didnt work. As a final resort i created a pre system hook and unset the GET part from the url for with i had to set
$config["uri_protocol"] = "REQUEST_URI";
It worked that way but all other links in my site were not working as intended, tried changing the uri_protocol but could not make it work by any means. So basically my problem is handling the ?auth=SDFSEFSDFXsdf5345sdf part in my url, whenever the paypment method redirects to my site with the url mentioned above, it gets redirected to homepage instead of the function inside controller. How can i handle this, i'm using codeIgniter 1.7 version, and couldnt find any way. Please suggest some solution.
Upvotes: 1
Views: 4079
Reputation: 71
Looking at the example code in the Stripe docs: https://stripe.com/docs/payments/checkout/set-up-a-subscription one might conclude that you can only retrieve a checkout_session_id as a named GET parameter like this:
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
After playing around with .htaccess and config settings (as in previous answers) and finally getting it to work, it suddenly dawned on me that the DEVELOPER is in control of the success_url format, not Stripe. So one can avoid all the problems with a GET parameter by specifying the success url in the normal, clean Codeigniter format, like this:
'success_url' => 'https://example.com/success/{CHECKOUT_SESSION_ID}',
In my routes file, the incoming CHECKOUT_SESSION_ID string is passed to the Subscription controller's checkout_success method with this route:
$route['success/(:any)'] = 'subscription/checkout_success/$1';
The method accepts the $checkout_session_id like this:
function checkout_success($checkout_session_id)
{
// Do something with the $checkout_session_id...
}
I'm new to Stripe Checkout but this seems to simplify the integration without breaking Codeigniter's GET processing rules.
Upvotes: 0
Reputation: 1354
hope this will help you ! no need to change htaccess,just change your code.
redirect(base_url()."controller_name/function_name");
Upvotes: 0
Reputation: 2183
I think I would extend the core URI class, by creating new file at application/libraries/MY_URI.php which will extend the CI_URI class, then copy the _fetch_uri_string method and here you can add your logic if the $_SERVER['QUERY_STRING'] is present:
class MY_URI extends CI_URI { function __construct() { parent::CI_URI(); } //Whatever this method returns the router class is using to map controller and action accordingly. function _fetch_uri_string() { if(isset($_SERVER['QUERY_STRING']) AND !empty($_GET['auth'])) { //Do your logic here, For example you can do something like if you are using REQUEST_URI $this->uri_string = 'payment/success/'.$_GET['auth']; return; //You will set the uri_string to controller/action/param the CI way and process further } //Here goes the rest of the method that you copied } }
Also please NOTE that you must do security check of your URL and I hope this works for you, otherwise you can try extending the CI_Router class or other methods (experiment little bit with few methods, though the _set_routing is important). These 2 classes are responsible for the intercepted urls and mapping them to controller/action/params in CI.
Upvotes: 2
Reputation: 3758
I believe this thread holds the answer.
Basically add
$config['enable_query_strings'] = TRUE;
to your config.php
Upvotes: 1