Welcome Guest, Not a member yet? Register   Sign In
Paypal Library- successfull transaction returns query string
#11

[eluser]octavianmh[/eluser]
Awesome, let us know how the library works out!
#12

[eluser]ldg430[/eluser]
The app is for cooking class registration. I do not use the shopping cart at this time. User picks the class he wants to attend, fills in the registration form and clicks the PayPal checkout button to initiate the PayPal Express Checkout process.

The attached library allows you to transact a total amount and provide a summary description for the transaction.

If you want to carry over the shopping cart items to PayPal, you will have to modify the library and provide additional parameters (line items) to the SetExpressCheckout API call.

My controller is your run-of-the-mill CI registration form with validation. When the user clicks the checkout button, validate the input fields, save all the posted variables and redirect him to the Checkout function:

[pre]
function checkout() {

// set from_paypal flag so in case the user cancels or encounters any error, we can bring
// the user back to the pre-filled form

$this->session->set_userdata('from_paypal', TRUE);

// call paypal SetExpressCheckout API

$resArray = $this->paypal->set_expresscheckout($this->session->userdata('payment_amount'));

// if success, redirect user to PayPal login page

if (strtoupper($resArray['ACK']) == "SUCCESS") {
$this->paypal->paypal_redirect(urldecode($resArray['TOKEN']));
} else {

// otherwise, log error and send user back to pre-filled form

$this->session->set_flashdata('output', "There is a problem with the PayPal transaction. "
.urldecode($resArray['L_LONGMESSAGE0']));
log_message('debug',"Paypal SetExpressCheckout Error - "
.urldecode($resArray['L_LONGMESSAGE0']));
redirect ($this->session->userdata('class_url'));
}
return;
}
[/pre]

From the PayPal page, the user can either cancel or complete the payment. The CANCEL URL points to Cancel function in my controller:

[pre]
function cancel() {

// We can redirect the user straight to the pre-filled form page. However, PayPal includes
// a TOKEN parameter in the URL. We do not want to show this parameter to the user.
// So instead we use this function for PayPal to redirect to and then we send back the user
// to the pre-filled form.

redirect ($this->session->userdata('class_url'));
return;
}
[/pre]

If user completes the payment, he is redirected to the RETURN URL which calls the Confirm function in my controller:
[pre]
function confirm() {

$this->session->set_userdata('token', $_REQUEST['token']);
$this->session->set_userdata('payerid', $_REQUEST['PayerID']);
$resArray = $this->paypal->do_expresscheckout_payment($this->session->userdata('payment_amount'), $this->session->userdata('token'), $this->session->userdata('payerid'));

// if successs, redirect user to the thank you page

if (strtoupper($resArray['ACK']) == "SUCCESS") {
$this->session->set_userdata('txnid', $resArray['TRANSACTIONID']);
redirect ('ptest/thankyou');

// otherwise, log error and send user back to pre-filled form

} else {
$this->session->set_flashdata('output', "There is a problem with the PayPal transaction. "
.urldecode($resArray['L_LONGMESSAGE0']));
log_message('debug',"Paypal DoExpressCheckout Error - "
.urldecode($resArray['L_LONGMESSAGE0']));
redirect ($this->session->userdata('class_url'));
}
return;
}
[/pre]

NOTE - the RETURN URL will contain two parameters - &token=XXX&PayerID=XXX - which I use in the DoExpressCheckout API call. Also note that I am not using the GetExpressCheckoutDetails API since I am having the user confirm the payment in PayPal and I don't need the user's PayPal shipping address information - since I am not shipping anything and already captured this on my form. This way, the user only has to go to PayPal once - login and pay - and then back to my page. (BTW, this API is included in the library if you want to use it.)

That is basically it (except for not processing curl errors - which I will be working on next...)

Hope this helps...
#13

[eluser]ldg430[/eluser]
fast_eddie,

i also ran into the same pagination issue with query strings enabled tonight. the page links have controller/function?per_page=offset in them and i am getting 404s.

i searched the forum and found this

http://ellislab.com/forums/viewthread/130845/

it's late so will try this fix tomorrow...
#14

[eluser]Fast Eddie[/eluser]
ldg430 - WOW this is great! thanks! I have a lot of great code to work with now Smile

I checked out the forum post about the pagination issue and the fix listed there worked!

Thank you everyone for your assistance!! Smile




Theme © iAndrew 2016 - Forum software by © MyBB