Skip to content

Instantly share code, notes, and snippets.

@jasonhuck
Created November 5, 2010 10:13
Show Gist options
  • Save jasonhuck/663918 to your computer and use it in GitHub Desktop.
Save jasonhuck/663918 to your computer and use it in GitHub Desktop.
An example of how to use the PayPal NVP API in Lasso to perform an Express Checkout transaction.
--- Include this at the top of every page, e.g., [library('config.inc')]. ---
[//lasso
// include required tags
// (these could also be loaded via LassoStartup)
library('tags/dictionary.inc'); // http://tagswap.net/dictionary
library('tags/paypal_nvpapi.inc');
// create a new paypal object to work with
var('pp') = paypal_nvpapi(
-pwd='your-api-password',
-user='your-api-username',
-signature='your-api-signature',
-test=true // use the sandbox server
);
]
-- Process a user-submitted form with Express Checkout. ---
[//lasso
// include standard configuration.
library('config.inc');
// call the SetExpressCheckout method
// the [$response] variable will contain all of the
// parameters returned by PayPal, which you can
// access as member tags, e.g., [$response->foo]
var('response') = $pp->SetExpressCheckout(
-paymentaction='Authorization',
-amt='19.95',
-returnurl='your-return-url',
-cancelurl='your-cancel-url'
);
// if the operation was successful...
if($response->ack >> 'Success');
// send the user to PayPal with the token you just got back
redirect_url('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' + $response->token);
else;
'Could not continue due to an error.';
/if;
]
-- User completes transaction and is redirected to your-return-url by PayPal. ---
[//lasso
// include standard configuration.
library('config.inc');
// if the token param was passed to the page...
if(action_param('token'));
// set it to a variable
var('token') = action_param('token');
// call the GetExpressCheckoutDetails method
var('response') = $pp->GetExpressCheckoutDetails( -token=$token);
// if the operation was successful...
if($response->ack >> 'Success');
// complete the transaction by calling the DoExpressCheckoutPayment method
var('response') = $pp->DoExpressCheckoutPayment(
-paymentaction='Authorization',
-payerid=$response->payerID,
-amt='19.95',
-token=$token
);
if($response->ack >> 'Success');
'Transaction successful!';
else;
'Transaction could not be completed due to an error.';
/if;
else;
'Could not continue due to an error.';
/if;
else;
'No token was passed to the page.';
/if;
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment