[paypal_nvpapi]

Description

Link: [paypal_nvpapi]
Author: Jason Huck
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Nov. 02, 2010
Updated: Nov. 02, 2010
More by this author...

This is a simple wrapper for the PayPal Web Payments Pro NVP API. Requires [dictionary].

Parameters

none


Sample Usage

// 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;
						

Source Code

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net