VPaypal 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +79 -0
- data/certs/api_cert_chain.crt +35 -0
- data/certs/client.cert +16 -0
- data/certs/client.keys +15 -0
- data/config/v_paypal.yml +21 -0
- data/lib/v_paypal.rb +2 -0
- data/lib/v_paypal/PayPalAPIInterfaceServiceClient.rb +197 -0
- data/lib/v_paypal/default.rb +5147 -0
- data/lib/v_paypal/defaultDriver.rb +178 -0
- data/lib/v_paypal/paypal_pro.rb +267 -0
- data/lib/v_paypal/requester_credentials_handler.rb +24 -0
- data/test/v_paypal_test.rb +165 -0
- metadata +57 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'soap/rpc/driver'
|
2
|
+
class PayPalAPIInterface < ::SOAP::RPC::Driver
|
3
|
+
DefaultEndpointUrl = "https://api.sandbox.paypal.com/2.0/"
|
4
|
+
MappingRegistry = ::SOAP::Mapping::Registry.new
|
5
|
+
|
6
|
+
Methods = [
|
7
|
+
[ nil,
|
8
|
+
"refundTransaction",
|
9
|
+
[ ["in", "RefundTransactionRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "RefundTransactionReq"], true],
|
10
|
+
["out", "RefundTransactionResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "RefundTransactionResponse"], true] ],
|
11
|
+
{ :request_style => :document, :request_use => :literal,
|
12
|
+
:response_style => :document, :response_use => :literal }
|
13
|
+
],
|
14
|
+
[ nil,
|
15
|
+
"getTransactionDetails",
|
16
|
+
[ ["in", "GetTransactionDetailsRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "GetTransactionDetailsReq"], true],
|
17
|
+
["out", "GetTransactionDetailsResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "GetTransactionDetailsResponse"], true] ],
|
18
|
+
{ :request_style => :document, :request_use => :literal,
|
19
|
+
:response_style => :document, :response_use => :literal }
|
20
|
+
],
|
21
|
+
[ nil,
|
22
|
+
"billUser",
|
23
|
+
[ ["in", "BillUserRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "BillUserReq"], true],
|
24
|
+
["out", "BillUserResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "BillUserResponse"], true] ],
|
25
|
+
{ :request_style => :document, :request_use => :literal,
|
26
|
+
:response_style => :document, :response_use => :literal }
|
27
|
+
],
|
28
|
+
[ nil,
|
29
|
+
"transactionSearch",
|
30
|
+
[ ["in", "TransactionSearchRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "TransactionSearchReq"], true],
|
31
|
+
["out", "TransactionSearchResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "TransactionSearchResponse"], true] ],
|
32
|
+
{ :request_style => :document, :request_use => :literal,
|
33
|
+
:response_style => :document, :response_use => :literal }
|
34
|
+
],
|
35
|
+
[ nil,
|
36
|
+
"massPay",
|
37
|
+
[ ["in", "MassPayRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "MassPayReq"], true],
|
38
|
+
["out", "MassPayResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "MassPayResponse"], true] ],
|
39
|
+
{ :request_style => :document, :request_use => :literal,
|
40
|
+
:response_style => :document, :response_use => :literal }
|
41
|
+
],
|
42
|
+
[ nil,
|
43
|
+
"billAgreementUpdate",
|
44
|
+
[ ["in", "BillAgreementUpdateRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "BillAgreementUpdateReq"], true],
|
45
|
+
["out", "body", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "BAUpdateResponse"], true] ],
|
46
|
+
{ :request_style => :document, :request_use => :literal,
|
47
|
+
:response_style => :document, :response_use => :literal }
|
48
|
+
],
|
49
|
+
[ nil,
|
50
|
+
"addressVerify",
|
51
|
+
[ ["in", "AddressVerifyRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "AddressVerifyReq"], true],
|
52
|
+
["out", "AddressVerifyResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "AddressVerifyResponse"], true] ],
|
53
|
+
{ :request_style => :document, :request_use => :literal,
|
54
|
+
:response_style => :document, :response_use => :literal }
|
55
|
+
]
|
56
|
+
]
|
57
|
+
|
58
|
+
def initialize(endpoint_url = nil)
|
59
|
+
endpoint_url ||= DefaultEndpointUrl
|
60
|
+
super(endpoint_url, nil)
|
61
|
+
self.mapping_registry = MappingRegistry
|
62
|
+
init_methods
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def init_methods
|
68
|
+
Methods.each do |definitions|
|
69
|
+
opt = definitions.last
|
70
|
+
if opt[:request_style] == :document
|
71
|
+
add_document_operation(*definitions)
|
72
|
+
else
|
73
|
+
add_rpc_operation(*definitions)
|
74
|
+
qname = definitions[0]
|
75
|
+
name = definitions[2]
|
76
|
+
if qname.name != name and qname.name.capitalize == name.capitalize
|
77
|
+
::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
|
78
|
+
__send__(name, *arg)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#require 'soap/rpc/driver'
|
87
|
+
|
88
|
+
class PayPalAPIAAInterface < ::SOAP::RPC::Driver
|
89
|
+
DefaultEndpointUrl = "https://api-aa.sandbox.paypal.com/2.0/"
|
90
|
+
MappingRegistry = ::SOAP::Mapping::Registry.new
|
91
|
+
|
92
|
+
Methods = [
|
93
|
+
[ nil,
|
94
|
+
"doExpressCheckoutPayment",
|
95
|
+
[ ["in", "DoExpressCheckoutPaymentRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoExpressCheckoutPaymentReq"], true],
|
96
|
+
["out", "DoExpressCheckoutPaymentResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoExpressCheckoutPaymentResponse"], true] ],
|
97
|
+
{ :request_style => :document, :request_use => :literal,
|
98
|
+
:response_style => :document, :response_use => :literal }
|
99
|
+
],
|
100
|
+
[ nil,
|
101
|
+
"setExpressCheckout",
|
102
|
+
[ ["in", "SetExpressCheckoutRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "SetExpressCheckoutReq"], true],
|
103
|
+
["out", "SetExpressCheckoutResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "SetExpressCheckoutResponse"], true] ],
|
104
|
+
{ :request_style => :document, :request_use => :literal,
|
105
|
+
:response_style => :document, :response_use => :literal }
|
106
|
+
],
|
107
|
+
[ nil,
|
108
|
+
"getExpressCheckoutDetails",
|
109
|
+
[ ["in", "GetExpressCheckoutDetailsRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "GetExpressCheckoutDetailsReq"], true],
|
110
|
+
["out", "GetExpressCheckoutDetailsResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "GetExpressCheckoutDetailsResponse"], true] ],
|
111
|
+
{ :request_style => :document, :request_use => :literal,
|
112
|
+
:response_style => :document, :response_use => :literal }
|
113
|
+
],
|
114
|
+
[ nil,
|
115
|
+
"doDirectPayment",
|
116
|
+
[ ["in", "DoDirectPaymentRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoDirectPaymentReq"], true],
|
117
|
+
["out", "DoDirectPaymentResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoDirectPaymentResponse"], true] ],
|
118
|
+
{ :request_style => :document, :request_use => :literal,
|
119
|
+
:response_style => :document, :response_use => :literal }
|
120
|
+
],
|
121
|
+
[ nil,
|
122
|
+
"doCapture",
|
123
|
+
[ ["in", "DoCaptureRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoCaptureReq"], true],
|
124
|
+
["out", "DoCaptureResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoCaptureResponse"], true] ],
|
125
|
+
{ :request_style => :document, :request_use => :literal,
|
126
|
+
:response_style => :document, :response_use => :literal }
|
127
|
+
],
|
128
|
+
[ nil,
|
129
|
+
"doReauthorization",
|
130
|
+
[ ["in", "DoReauthorizationRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoReauthorizationReq"], true],
|
131
|
+
["out", "DoReauthorizationResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoReauthorizationResponse"], true] ],
|
132
|
+
{ :request_style => :document, :request_use => :literal,
|
133
|
+
:response_style => :document, :response_use => :literal }
|
134
|
+
],
|
135
|
+
[ nil,
|
136
|
+
"doVoid",
|
137
|
+
[ ["in", "DoVoidRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoVoidReq"], true],
|
138
|
+
["out", "DoVoidResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoVoidResponse"], true] ],
|
139
|
+
{ :request_style => :document, :request_use => :literal,
|
140
|
+
:response_style => :document, :response_use => :literal }
|
141
|
+
],
|
142
|
+
[ nil,
|
143
|
+
"doAuthorization",
|
144
|
+
[ ["in", "DoAuthorizationRequest", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoAuthorizationReq"], true],
|
145
|
+
["out", "DoAuthorizationResponse", ["::SOAP::SOAPElement", "urn:ebay:api:PayPalAPI", "DoAuthorizationResponse"], true] ],
|
146
|
+
{ :request_style => :document, :request_use => :literal,
|
147
|
+
:response_style => :document, :response_use => :literal }
|
148
|
+
]
|
149
|
+
]
|
150
|
+
|
151
|
+
def initialize(endpoint_url = nil)
|
152
|
+
endpoint_url ||= DefaultEndpointUrl
|
153
|
+
super(endpoint_url, nil)
|
154
|
+
self.mapping_registry = MappingRegistry
|
155
|
+
init_methods
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def init_methods
|
161
|
+
Methods.each do |definitions|
|
162
|
+
opt = definitions.last
|
163
|
+
if opt[:request_style] == :document
|
164
|
+
add_document_operation(*definitions)
|
165
|
+
else
|
166
|
+
add_rpc_operation(*definitions)
|
167
|
+
qname = definitions[0]
|
168
|
+
name = definitions[2]
|
169
|
+
if qname.name != name and qname.name.capitalize == name.capitalize
|
170
|
+
::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
|
171
|
+
__send__(name, *arg)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
@@ -0,0 +1,267 @@
|
|
1
|
+
module VPaypal
|
2
|
+
require File.dirname(__FILE__) + '/defaultDriver'
|
3
|
+
require File.dirname(__FILE__) + '/default'
|
4
|
+
class PaypalPro
|
5
|
+
attr_accessor :client
|
6
|
+
|
7
|
+
=begin
|
8
|
+
Creates the headerhandler for each request in initialization of VPaypal object.Reads required paypal account information and certificate paths from paypal.yml.The necessary required Information includes:
|
9
|
+
@ca_file: Location of Paypal Server Certificate in your server.
|
10
|
+
@client_keys : Location of client.keys file that contains rsa key part of cert_key_pem.txt(digital client certificate from paypal)
|
11
|
+
@client_cert: Location of client.cert file that contains the rest of the part of certificate.
|
12
|
+
@paypal_username:Username for merchant account
|
13
|
+
@paypal_password:Password for merchant account
|
14
|
+
By default these files are searched in the current folder lib/paypal
|
15
|
+
Make changes in paypal.yml as it suits you.
|
16
|
+
Example:New instance can be created as
|
17
|
+
vpp = VPaypal::PaypalPro.new(options)
|
18
|
+
Where
|
19
|
+
options = {"prefs"=>"path of v_paypal.yml"}
|
20
|
+
=end
|
21
|
+
|
22
|
+
def initialize(options = {"prefs"=>nil})
|
23
|
+
prefs = File.expand_path(options[:prefs] || File.dirname(__FILE__) +"/../../config/v_paypal.yml")
|
24
|
+
YAML.load(File.open(prefs)).each {|pref, value| eval("@#{pref} =\"#{value}\"")}if File.exists?(prefs)
|
25
|
+
client = PayPalAPIAAInterface.new
|
26
|
+
client.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_PEER
|
27
|
+
client.options['protocol.http.ssl_config.ca_file'] = "#{File.expand_path(File.dirname(__FILE__))+@ca_file}"
|
28
|
+
client.options['protocol.http.ssl_config.client_cert'] = "#{File.expand_path(File.dirname(__FILE__))+@client_cert}"
|
29
|
+
client.options['protocol.http.ssl_config.client_key'] = "#{File.expand_path(File.dirname(__FILE__))+@client_keys}"
|
30
|
+
client.headerhandler << RequesterCredentialsHandler.new(@paypal_username, @paypal_password,'')
|
31
|
+
@client = client
|
32
|
+
end
|
33
|
+
|
34
|
+
=begin
|
35
|
+
Takes two parameters
|
36
|
+
request:Name of request without "Request" word appended with it.
|
37
|
+
Example-For SetExpressCheckout Request request string should be "SetExpressCheckout"
|
38
|
+
options:Contains all the parameters required for given Request.These parameters are passed through a multi dimensional Hash.This Hash has the same tree structure as the paypal request has.
|
39
|
+
Example:
|
40
|
+
res = vpp.vRequest("DoExpressCheckoutPayment",{ "Token" => token_value,
|
41
|
+
"PaymentAction-PaymentActionCode" => "Sale",
|
42
|
+
"PayerID" => payerID,
|
43
|
+
"PaymentDetails" =>
|
44
|
+
{"OrderTotal"=>amount,
|
45
|
+
"ShipppingTotal" =>shipping_total,
|
46
|
+
"ShipToAddress-Address"=>
|
47
|
+
{"Name" => name,
|
48
|
+
"Street1" => street1,
|
49
|
+
"StateOrProvince" => state,
|
50
|
+
"CityName" => city,
|
51
|
+
"Country" => country,
|
52
|
+
"PostalCode" => zip
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
})
|
57
|
+
One needs to remember that if variable name is different from object name in the request ,the key value must contain both name seperated by a hyphen(-).{"VariableName-ObjectName"=>value}
|
58
|
+
Example: "ShipToAddress-Address"=>
|
59
|
+
{"Name" => name,
|
60
|
+
"Street1" => street1,
|
61
|
+
"StateOrProvince" => state,
|
62
|
+
"CityName" => city,
|
63
|
+
"Country" => country,
|
64
|
+
"PostalCode" => zip
|
65
|
+
}
|
66
|
+
|
67
|
+
Returns Response.Check res.ack for 'Success' Or 'Failure' .Errors can be viewed in res.errors
|
68
|
+
=end
|
69
|
+
|
70
|
+
def vRequest(request = nil ,options = nil)
|
71
|
+
if request != "GetExpressCheckoutDetails"
|
72
|
+
req = eval("#{request}Req").new
|
73
|
+
type = eval("#{request}RequestType").new
|
74
|
+
type.version = "2.0"
|
75
|
+
details = eval("#{request}RequestDetailsType").new
|
76
|
+
request = request[/^(.)(.*)?/]
|
77
|
+
var_name = $1.swapcase.concat($2)
|
78
|
+
type.instance_variable_set(eval(":@#{var_name}RequestDetails"),details)
|
79
|
+
s = assignOptions(options,details)
|
80
|
+
details = s
|
81
|
+
req.instance_variable_set(eval(":@#{var_name}Request"),type)
|
82
|
+
m = @client.method(var_name)
|
83
|
+
res = m.call(req)
|
84
|
+
else
|
85
|
+
res = vGetExpressCheckoutDetails(options)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
=begin
|
90
|
+
Sets all the parameters required for SetExpressCheckoutRequest.These parameters are passed through options in a multi dimensional Hash.This Hash is has the same tree structure as the paypal request has.Please follow carefully the paypal pro documentaion to create options hash for request.As this module uses the variable name and object name as given in the paypal pro documentation.
|
91
|
+
|
92
|
+
Example:
|
93
|
+
res = vpp.vSetExpressCheckoutRequest({"OrderTotal"=>"10.00","CancelURL"=>url_for(:action => "cancel"),"ReturnURL"=>url_for(:action => "return")})
|
94
|
+
The response contains token which can be accessed as res.token Append this token to the redirect url and redirect user to paypal screen
|
95
|
+
redirect_to "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#{res.token.to_s}"
|
96
|
+
**Currently not in use
|
97
|
+
=end
|
98
|
+
|
99
|
+
def vSetExpressCheckoutRequest(options = nil)
|
100
|
+
req = SetExpressCheckoutReq.new
|
101
|
+
type = SetExpressCheckoutRequestType.new
|
102
|
+
type.version = "2.0"
|
103
|
+
details = SetExpressCheckoutRequestDetailsType.new
|
104
|
+
type.setExpressCheckoutRequestDetails = details
|
105
|
+
s = assignOptions(options,details)
|
106
|
+
details = s
|
107
|
+
req.setExpressCheckoutRequest = type
|
108
|
+
res = @client.setExpressCheckout(req)
|
109
|
+
end
|
110
|
+
|
111
|
+
=begin
|
112
|
+
Sets all the parameters required for GetExpressCheckoutDetails.These parameters are passed through options in a multi dimensional Hash.This Hash has the same tree structure as the paypal request has.The only value required here for this request is token
|
113
|
+
Example :
|
114
|
+
res = vpp.vGetExpressCheckoutDetails({"token"=>params[:token]})
|
115
|
+
The Response returned contains account insormation of user.Can be easily accessed as -
|
116
|
+
firstName =res.getExpressCheckoutDetailsResponseDetails.payerInfo.payerName.firstName
|
117
|
+
=end
|
118
|
+
|
119
|
+
def vGetExpressCheckoutDetails(options = nil)
|
120
|
+
req = GetExpressCheckoutDetailsReq.new
|
121
|
+
type = GetExpressCheckoutDetailsRequestType.new
|
122
|
+
type.version = "2.0"
|
123
|
+
type.token=options["token"]
|
124
|
+
req.getExpressCheckoutDetailsRequest = type
|
125
|
+
res = @client.getExpressCheckoutDetails(req)
|
126
|
+
end
|
127
|
+
|
128
|
+
=begin
|
129
|
+
Sets all the parameters required for DoExpressCheckoutPaymentRequest.These parameters are passed through options in a multi dimensional Hash.This Hash has the same tree structure as the paypal request has.
|
130
|
+
Example:
|
131
|
+
res = vpp.vDoExpressCheckoutPaymentRequest({ "Token" => token_value,
|
132
|
+
"PaymentAction-PaymentActionCode" => "Sale",
|
133
|
+
"PayerID" => payerID,
|
134
|
+
"PaymentDetails" =>
|
135
|
+
{"OrderTotal"=>amount,
|
136
|
+
"ShipppingTotal" =>shipping_total,
|
137
|
+
"ShipToAddress-Address"=>
|
138
|
+
{"Name" => name,
|
139
|
+
"Street1" => street1,
|
140
|
+
"StateOrProvince" => state,
|
141
|
+
"CityName" => city,
|
142
|
+
"Country" => country,
|
143
|
+
"PostalCode" => zip
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
})
|
148
|
+
One needs to remember that if variable name is different from object name in the request ,the key value must contain both name seperated by a hyphen(-).{"VariableName-ObjectName"=>value}
|
149
|
+
Example: "ShipToAddress-Address"=>
|
150
|
+
{"Name" => name,
|
151
|
+
"Street1" => street1,
|
152
|
+
"StateOrProvince" => state,
|
153
|
+
"CityName" => city,
|
154
|
+
"Country" => country,
|
155
|
+
"PostalCode" => zip
|
156
|
+
}
|
157
|
+
|
158
|
+
Return Response.Check res.ack for 'Success' Or 'Failure' .Errors can be viewed in res.errors
|
159
|
+
**Currently not in use
|
160
|
+
=end
|
161
|
+
|
162
|
+
def vDoExpressCheckoutPaymentRequest(options = nil)
|
163
|
+
req = DoExpressCheckoutPaymentReq.new
|
164
|
+
type = DoExpressCheckoutPaymentRequestType.new
|
165
|
+
type.version = "2.0"
|
166
|
+
details = DoExpressCheckoutPaymentRequestDetailsType.new
|
167
|
+
type.doExpressCheckoutPaymentRequestDetails = details
|
168
|
+
s = assignOptions(options,details)
|
169
|
+
details = s
|
170
|
+
req.doExpressCheckoutPaymentRequest = type
|
171
|
+
res = @client.doExpressCheckoutPayment(req)
|
172
|
+
end
|
173
|
+
|
174
|
+
=begin
|
175
|
+
Sets all the parameters required for DodirectPaymentRequest.These parameters are passed through options in a multi dimensional Hash.This Hash has the same tree structure as the paypal request has.
|
176
|
+
|
177
|
+
One needs to remember that if variable name is different from object name in the request ,the key value must contain both name seperated by a hyphen(-).{"VariableName-ObjectName"=>value}
|
178
|
+
Example: "CreditCard-CreditCardDetails" =>
|
179
|
+
{"CardOwner-PayerInfo" =>
|
180
|
+
{"PayerName-PersonName" =>
|
181
|
+
{"FirstName"=> fname,
|
182
|
+
"LastName" => lname
|
183
|
+
},
|
184
|
+
"Address" =>
|
185
|
+
{ "Street1"=>line1 ,
|
186
|
+
"StateOrProvince"=>state,
|
187
|
+
"CityName"=>city,
|
188
|
+
"Country"=>country,
|
189
|
+
"PostalCode" => zip,
|
190
|
+
} ,
|
191
|
+
},
|
192
|
+
"CreditCardType" => type,
|
193
|
+
"CreditCardNumber" =>number,
|
194
|
+
"ExpMonth" =>expmonth,
|
195
|
+
"ExpYear" => expyear ,
|
196
|
+
"CVV2" => cvm
|
197
|
+
},
|
198
|
+
**Currently not in use
|
199
|
+
=end
|
200
|
+
|
201
|
+
def vDoDirectPaymentRequest(options = nil)
|
202
|
+
req = DoDirectPaymentReq.new
|
203
|
+
type = DoDirectPaymentRequestType.new
|
204
|
+
type.version = "2.0"
|
205
|
+
details = DoDirectPaymentRequestDetailsType.new
|
206
|
+
type.doDirectPaymentRequestDetails = details
|
207
|
+
s = assignOptions(options,details)
|
208
|
+
details = s
|
209
|
+
req.doDirectPaymentRequest = type
|
210
|
+
res = @client.doDirectPayment(req)
|
211
|
+
end
|
212
|
+
|
213
|
+
=begin
|
214
|
+
assignOptions is called by every request function in VPaypal class.It makes recursive calls to self.It takes two argument a Hash array or a string and a class object.The class object is the parent class and the hashed array contains the values of the instance variables of this object.If the instance variable itself is a class object and its value in Hash is also a Hash the function is called recursively wid the value of hash as options and class created by as parent_class.
|
215
|
+
=end
|
216
|
+
|
217
|
+
def assignOptions(options = nil, parent_class = nil)
|
218
|
+
class_variables = parent_class.instance_variables
|
219
|
+
options.each do |key,child|
|
220
|
+
if key.include?("-")
|
221
|
+
key = key[/^(.)(.*)-(.*)?/]
|
222
|
+
else
|
223
|
+
key = key[/^(.)(.*)?/]
|
224
|
+
end
|
225
|
+
var_name = $1.swapcase.concat($2)
|
226
|
+
if $3.nil?
|
227
|
+
cl_name = $1.concat($2)
|
228
|
+
else
|
229
|
+
cl_name = $3
|
230
|
+
end
|
231
|
+
if class_variables.include?("@#{var_name}")
|
232
|
+
f = false
|
233
|
+
begin
|
234
|
+
eval("@#{var_name} = #{cl_name}Type.new")
|
235
|
+
f = true
|
236
|
+
|
237
|
+
if(child.class.to_s == 'Hash')
|
238
|
+
assignOptions(child,eval("@#{var_name}"))
|
239
|
+
# If class is derrived from String then simply assign child value
|
240
|
+
else
|
241
|
+
eval("@#{var_name} = '#{child.to_s}'")
|
242
|
+
end
|
243
|
+
# if no class with name as key exists then assign the child value to the instance variable of parent class
|
244
|
+
rescue NameError
|
245
|
+
# Creating OrderTotal object
|
246
|
+
if var_name.to_s == "orderTotal"
|
247
|
+
ns = "urn:ebay:apis:eBLBaseComponents"
|
248
|
+
otqname = XSD::QName.new(ns, "OrderTotal")
|
249
|
+
otele = SOAP::SOAPElement.new(otqname, child)
|
250
|
+
otele.extraattr["currencyID"] = "USD"
|
251
|
+
parent_class.orderTotal = otele
|
252
|
+
else
|
253
|
+
parent_class.instance_variable_set(eval(":@#{var_name}") , child)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
#assigning object to the instance variable of parent class
|
258
|
+
if f
|
259
|
+
parent_class.instance_variable_set(eval(":@#{var_name}") , eval("@#{var_name}"))
|
260
|
+
end
|
261
|
+
end
|
262
|
+
parent_class
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module VPaypal
|
2
|
+
require 'soap/header/simplehandler'
|
3
|
+
class RequesterCredentialsHandler < SOAP::Header::SimpleHandler
|
4
|
+
HeaderName = XSD::QName.new('urn:ebay:api:PayPalAPI',
|
5
|
+
'RequesterCredentials')
|
6
|
+
CredentialsName =
|
7
|
+
XSD::QName.new('urn:ebay:apis:eBLBaseComponents', 'Credentials')
|
8
|
+
UsernameName = XSD::QName.new(nil, 'Username')
|
9
|
+
PasswordName = XSD::QName.new(nil, 'Password')
|
10
|
+
SubjectName = XSD::QName.new(nil, 'Subject')
|
11
|
+
|
12
|
+
def initialize(username, password, subject)
|
13
|
+
super(HeaderName)
|
14
|
+
@username, @password, @subject = username, password, subject
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_simple_outbound
|
18
|
+
{CredentialsName => {UsernameName => @username, PasswordName =>
|
19
|
+
@password,
|
20
|
+
SubjectName => @subject}}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|