Link | paypal_nvpapi |
Author | Jason Huck |
Category | Utility |
Version | 8.5.x |
License | Public Domain |
Posted | 02 Nov 2010 |
Updated | 02 Nov 2010 |
More by this author... |
This is a simple wrapper for the PayPal Web Payments Pro NVP API. Requires [dictionary].
// create a new PayPal object, passing in your API credentials // include the -test keyword to hit the sandbox var('myPayPalObject') = paypal_nvpapi( -user='paypal_api_username', -pwd='paypal_api_password', -signature='paypal_api_signature', -test=true ); // call whichever method you need, and pass in the required // arguments, based on the API documentation // for best results, match spelling and capitalization exactly var('response') = $myPayPalObject->DoDirectPayment( -paymentaction='Authorization', -ipaddress=client_ip, -amt=0.00, -acct='XXXX-XXXX-XXXX-XXXX', -expdate='MMYYYY', -creditcardtype='AMEX', -ccv2=123, -email='user@domain.tld', -firstname='Joe', -lastname='User', -street='1234 This Way', -city='Omaha', -state='NE', -zip='90210', -countrycode='US' ); // the result will be a [dictionary] (http://tagswap.net/dictionary) // which you can treat like a map, or just access the parameters directly: var('transactionID') = $response->TransactionID;
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_type( 'nvpapi', -namespace='paypal_', -prototype, -description='Lasso wrapper for the PayPal Web Payments Pro NVP API.' ); // do not pass the "subject" param, regardless of the docs // including it causes calls to fail local( 'test' = false, 'user' = string, 'pwd' = string, 'signature' = string, 'version' = '64.0' // as of 6-22-2010 ); define_tag('oncreate'); local('ivars') = @self->properties->first; iterate(#ivars->keys, local('i')); !local_defined(#i) ? loop_continue; if(#i == 'test'); self->'test' = boolean(local(#i)); else; #ivars->find(#i) = local(#i); /if; /iterate; /define_tag; define_tag( 'connect', -req='method', -req='params', -type='array' ); local('url') = (self->'test' ? 'https://api-3t.sandbox.paypal.com/nvp' | 'https://api-3t.paypal.com/nvp'); local('ivars') = self->properties->first; local('postparams') = array('method' = #method); iterate(#ivars->keys, local('i')); (#i == 'test' || #ivars->find(#i) == '') ? loop_continue; #postparams->insert(#i = encode_url(string(#ivars->find(#i)))); /iterate; #postparams->merge(#params); protect; handle_error; local('result') = dictionary( 'error_code' = error_code, 'error_message' = error_msg ); /handle_error; local('result') = dictionary; local('response') = include_url( #url, -getparams=#postparams, -timeout=30, -connecttimeout=30 ); local('pairs') = #response->split('&'); iterate(#pairs, local('i')); local('p') = string(#i)->split('='); #result->insert(#p->first = decode_url(#p->second)); /iterate; /protect; return(#result); /define_tag; define_tag('_unknowntag'); local('params') = array; iterate(params, local('i')); #i->isa('pair') ? #params->insert(string(#i->first)->removeleading('-')& = #i->second); /iterate; return(self->connect(tag_name, #params)); /define_tag; /define_type;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft