ruby-ecomm-client 1.1.0 → 1.7.0

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.
Files changed (58) hide show
  1. checksums.yaml +15 -0
  2. data/.ruby-version +1 -1
  3. data/Gemfile +1 -0
  4. data/README.md +10 -0
  5. data/fixtures/vcr_cassettes/account_info/default.yml +49 -34
  6. data/fixtures/vcr_cassettes/account_info/unknown/resource_id.yml +42 -34
  7. data/fixtures/vcr_cassettes/account_info/unknown/resource_type.yml +42 -34
  8. data/fixtures/vcr_cassettes/account_info/unknown/source_tree_id.yml +42 -34
  9. data/fixtures/vcr_cassettes/express_checkout/configured.yml +39 -31
  10. data/fixtures/vcr_cassettes/express_checkout/unknown.yml +39 -31
  11. data/fixtures/vcr_cassettes/request_change/express/downgrade/default.yml +46 -36
  12. data/fixtures/vcr_cassettes/request_change/express/downgrade/noop.yml +55 -34
  13. data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/resource_id.yml +46 -34
  14. data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/resource_type.yml +47 -34
  15. data/fixtures/vcr_cassettes/request_change/express/downgrade/unknown/target_tree_id.yml +46 -34
  16. data/fixtures/vcr_cassettes/request_change/express/relay/default.yml +48 -0
  17. data/fixtures/vcr_cassettes/request_change/express/upgrade/default.yml +55 -36
  18. data/fixtures/vcr_cassettes/request_change/express/upgrade/noop.yml +46 -34
  19. data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/resource_id.yml +46 -34
  20. data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/resource_type.yml +47 -34
  21. data/fixtures/vcr_cassettes/request_change/express/upgrade/unknown/target_tree_id.yml +46 -34
  22. data/fixtures/vcr_cassettes/request_change/manager/downgrade/default.yml +43 -34
  23. data/fixtures/vcr_cassettes/request_change/manager/downgrade/noop.yml +43 -34
  24. data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/resource_id.yml +43 -34
  25. data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/resource_type.yml +43 -34
  26. data/fixtures/vcr_cassettes/request_change/manager/downgrade/unknown/target_tree_id.yml +43 -34
  27. data/fixtures/vcr_cassettes/request_change/manager/relay/default.yml +100 -0
  28. data/fixtures/vcr_cassettes/request_change/manager/upgrade/default.yml +43 -34
  29. data/fixtures/vcr_cassettes/request_change/manager/upgrade/noop.yml +43 -34
  30. data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/resource_id.yml +43 -34
  31. data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/resource_type.yml +43 -34
  32. data/fixtures/vcr_cassettes/request_change/manager/upgrade/unknown/target_tree_id.yml +43 -34
  33. data/fixtures/vcr_cassettes/transitions/default/unknown/source_tree_id.yml +42 -34
  34. data/fixtures/vcr_cassettes/transitions/many.yml +49 -34
  35. data/fixtures/vcr_cassettes/transitions/one.yml +49 -34
  36. data/lib/ruby-ecomm-client.rb +13 -1
  37. data/lib/ruby-ecomm-client/client.rb +19 -148
  38. data/lib/ruby-ecomm-client/config.rb +25 -0
  39. data/lib/ruby-ecomm-client/service_base.rb +55 -0
  40. data/lib/ruby-ecomm-client/service_manager.rb +75 -0
  41. data/lib/ruby-ecomm-client/service_profile.rb +30 -0
  42. data/lib/ruby-ecomm-client/service_purchase.rb +79 -0
  43. data/lib/ruby-ecomm-client/util.rb +16 -0
  44. data/lib/ruby-ecomm-client/version.rb +1 -1
  45. data/ruby-ecomm-client.gemspec +2 -1
  46. data/script/bootstrap +68 -0
  47. data/script/cibuild +4 -5
  48. data/spec/ruby-ecomm-client/client_spec.rb +32 -339
  49. data/spec/ruby-ecomm-client/config_spec.rb +56 -0
  50. data/spec/ruby-ecomm-client/service_base_spec.rb +119 -0
  51. data/spec/ruby-ecomm-client/service_manager_spec.rb +285 -0
  52. data/spec/ruby-ecomm-client/service_profile_spec.rb +33 -0
  53. data/spec/ruby-ecomm-client/service_purchase_spec.rb +160 -0
  54. data/spec/ruby-ecomm-client/util_spec.rb +66 -0
  55. data/spec/spec_helper.rb +10 -0
  56. metadata +160 -152
  57. data/lib/ruby-ecomm-client/converter.rb +0 -45
  58. data/spec/ruby-ecomm-client/converter_spec.rb +0 -96
@@ -1,42 +1,57 @@
1
- ---
2
- http_interactions:
3
- - request:
1
+ ---
2
+ http_interactions:
3
+ - request:
4
4
  method: post
5
- uri: http://bonsai.dev.glbt1.gdg/bonsai/bonsaimanager/service.asmx
6
- body:
7
- string: <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:tns="#Bonsai" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:GetAccountXml><tns:IDType>ORION</tns:IDType><tns:PrivateLabelID>1</tns:PrivateLabelID><tns:ResourceType>outright</tns:ResourceType><tns:TreeID>1735</tns:TreeID><tns:ResourceID>10e16f14-b606-11e3-a45e-0050569575d8</tns:ResourceID></tns:GetAccountXml></env:Body></env:Envelope>
8
- headers:
9
- content-type:
5
+ uri: http://bonsai.dev.glbt1.gdg/Bonsai/BonsaiManager/Service.asmx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
9
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="#Bonsai"
10
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:GetAccountXml><tns:ResourceID>b6be6fd0-c1a5-11e3-8e42-0050569575d8</tns:ResourceID><tns:ResourceType>outright</tns:ResourceType><tns:IDType>ORION</tns:IDType><tns:TreeID>2410</tns:TreeID><tns:PrivateLabelID>1</tns:PrivateLabelID></tns:GetAccountXml></env:Body></env:Envelope>
11
+ headers:
12
+ soapaction:
13
+ - ! '"#Bonsai/GetAccountXml"'
14
+ content-type:
10
15
  - text/xml;charset=UTF-8
11
- content-length:
12
- - "515"
13
- accept:
14
- - "*/*"
15
- soapaction:
16
- - "\"#Bonsai/GetAccountXml\""
17
- response:
18
- status:
16
+ content-length:
17
+ - '515'
18
+ accept:
19
+ - ! '*/*'
20
+ user-agent:
21
+ - Ruby
22
+ response:
23
+ status:
19
24
  code: 200
20
25
  message: OK
21
- headers:
22
- content-type:
23
- - text/xml; charset=utf-8
24
- content-length:
25
- - "1626"
26
- x-aspnet-version:
27
- - 4.0.30319
28
- cache-control:
26
+ headers:
27
+ cache-control:
29
28
  - private, max-age=0
30
- server:
29
+ content-type:
30
+ - text/xml; charset=utf-8
31
+ server:
31
32
  - Microsoft-IIS/7.0
32
- date:
33
- - Fri, 28 Mar 2014 00:22:33 GMT
34
- connection:
35
- - close
36
- x-powered-by:
33
+ x-aspnet-version:
34
+ - 4.0.30319
35
+ x-powered-by:
37
36
  - ASP.NET
38
- body:
39
- string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAccountXmlResponse xmlns="#Bonsai"><ResultCode>0</ResultCode><AccountXml><Bonsai><Bonsai PrivateLabelID="1" ResourceID="10e16f14-b606-11e3-a45e-0050569575d8" IsPastDue="False" IsFree="False" CurrentTreeID="1735" CurrentUnifiedProductID="2701" xmlns=""><Tree TreeID="1735" NodeID="1735" UnifiedProductID="2701" IsFree="False"><Transition NodeName="Outright - Monthly Plus" UnifiedProductID="2697" TreeID="1734" IsFree="False" NodeID="1734" /><Transition NodeName="Outright - Annual Plus 1 year" UnifiedProductID="2699" TreeID="1736" IsFree="False" NodeID="1736" /><Transition NodeName="Outright - Annual Plus 2 years" UnifiedProductID="2703" TreeID="1737" IsFree="False" NodeID="1737" /><Transition NodeName="Outright - Annual Plus 3 years" UnifiedProductID="2705" TreeID="1738" IsFree="False" NodeID="1738" /><Transition NodeName="Outright - Annual Plus 4 years" UnifiedProductID="2707" TreeID="1739" IsFree="False" NodeID="1739" /><Transition NodeName="Outright - Annual Plus 5 years" UnifiedProductID="2709" TreeID="1740" IsFree="False" NodeID="1740" /><FilteredTransitions /><Prepaid><Item Name="Prepaid Previous Tax - Outright" CategoryName="Prepaid Previous Tax" CategoryID="49" MinQty="1" MaxQty="-1" MinDuration="1" MaxDuration="-1" IsQuantityBased="False" Increment="1" UnifiedProductID="2711" /></Prepaid></Tree></Bonsai></Bonsai></AccountXml></GetAccountXmlResponse></soap:Body></soap:Envelope>
40
- http_version: "1.1"
41
- recorded_at: Fri, 28 Mar 2014 00:22:36 GMT
37
+ date:
38
+ - Fri, 18 Apr 2014 16:29:10 GMT
39
+ connection:
40
+ - close
41
+ content-length:
42
+ - '924'
43
+ body:
44
+ encoding: US-ASCII
45
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
46
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAccountXmlResponse
47
+ xmlns="#Bonsai"><ResultCode>0</ResultCode><AccountXml><Bonsai><Bonsai PrivateLabelID="1"
48
+ ResourceID="b6be6fd0-c1a5-11e3-8e42-0050569575d8" IsPastDue="False" IsFree="False"
49
+ CurrentTreeID="2410" CurrentUnifiedProductID="326365" xmlns=""><Tree TreeID="2410"
50
+ NodeID="2410" UnifiedProductID="326365" IsFree="False"><Transition NodeName="Starter
51
+ Outright Get Paid - Monthly" UnifiedProductID="326363" TreeID="2402" IsFree="False"
52
+ NodeID="2402" /><Transition NodeName="Premium Outright Get Paid - Monthly"
53
+ UnifiedProductID="326388" TreeID="2418" IsFree="False" NodeID="2418" /><FilteredTransitions
54
+ /></Tree></Bonsai></Bonsai></AccountXml></GetAccountXmlResponse></soap:Body></soap:Envelope>
55
+ http_version: '1.1'
56
+ recorded_at: Fri, 18 Apr 2014 16:30:09 GMT
42
57
  recorded_with: VCR 2.8.0
@@ -1,42 +1,57 @@
1
- ---
2
- http_interactions:
3
- - request:
1
+ ---
2
+ http_interactions:
3
+ - request:
4
4
  method: post
5
- uri: http://bonsai.dev.glbt1.gdg/bonsai/bonsaimanager/service.asmx
6
- body:
7
- string: <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:tns="#Bonsai" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:GetAccountXml><tns:IDType>ORION</tns:IDType><tns:PrivateLabelID>1</tns:PrivateLabelID><tns:ResourceType>outright</tns:ResourceType><tns:TreeID>1734</tns:TreeID><tns:ResourceID>10e16f14-b606-11e3-a45e-0050569575d8</tns:ResourceID></tns:GetAccountXml></env:Body></env:Envelope>
8
- headers:
9
- content-type:
5
+ uri: http://bonsai.dev.glbt1.gdg/Bonsai/BonsaiManager/Service.asmx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
9
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="#Bonsai"
10
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:GetAccountXml><tns:ResourceID>b6be6fd0-c1a5-11e3-8e42-0050569575d8</tns:ResourceID><tns:ResourceType>outright</tns:ResourceType><tns:IDType>ORION</tns:IDType><tns:TreeID>2402</tns:TreeID><tns:PrivateLabelID>1</tns:PrivateLabelID></tns:GetAccountXml></env:Body></env:Envelope>
11
+ headers:
12
+ soapaction:
13
+ - ! '"#Bonsai/GetAccountXml"'
14
+ content-type:
10
15
  - text/xml;charset=UTF-8
11
- content-length:
12
- - "515"
13
- accept:
14
- - "*/*"
15
- soapaction:
16
- - "\"#Bonsai/GetAccountXml\""
17
- response:
18
- status:
16
+ content-length:
17
+ - '515'
18
+ accept:
19
+ - ! '*/*'
20
+ user-agent:
21
+ - Ruby
22
+ response:
23
+ status:
19
24
  code: 200
20
25
  message: OK
21
- headers:
22
- content-type:
23
- - text/xml; charset=utf-8
24
- content-length:
25
- - "768"
26
- x-aspnet-version:
27
- - 4.0.30319
28
- cache-control:
26
+ headers:
27
+ cache-control:
29
28
  - private, max-age=0
30
- server:
29
+ content-type:
30
+ - text/xml; charset=utf-8
31
+ server:
31
32
  - Microsoft-IIS/7.0
32
- date:
33
- - Fri, 28 Mar 2014 00:22:33 GMT
34
- connection:
35
- - close
36
- x-powered-by:
33
+ x-aspnet-version:
34
+ - 4.0.30319
35
+ x-powered-by:
37
36
  - ASP.NET
38
- body:
39
- string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAccountXmlResponse xmlns="#Bonsai"><ResultCode>0</ResultCode><AccountXml><Bonsai><Bonsai PrivateLabelID="1" ResourceID="10e16f14-b606-11e3-a45e-0050569575d8" IsPastDue="False" IsFree="False" CurrentTreeID="1735" CurrentUnifiedProductID="2701" xmlns=""><Tree TreeID="1734" NodeID="1734" UnifiedProductID="2697" IsFree="False"><Transition NodeName="Outright - Free" UnifiedProductID="2701" TreeID="1735" IsFree="False" NodeID="1735" /><FilteredTransitions /></Tree></Bonsai></Bonsai></AccountXml></GetAccountXmlResponse></soap:Body></soap:Envelope>
40
- http_version: "1.1"
41
- recorded_at: Fri, 28 Mar 2014 00:22:36 GMT
37
+ date:
38
+ - Fri, 18 Apr 2014 16:29:09 GMT
39
+ connection:
40
+ - close
41
+ content-length:
42
+ - '926'
43
+ body:
44
+ encoding: US-ASCII
45
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
46
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAccountXmlResponse
47
+ xmlns="#Bonsai"><ResultCode>0</ResultCode><AccountXml><Bonsai><Bonsai PrivateLabelID="1"
48
+ ResourceID="b6be6fd0-c1a5-11e3-8e42-0050569575d8" IsPastDue="False" IsFree="False"
49
+ CurrentTreeID="2410" CurrentUnifiedProductID="326365" xmlns=""><Tree TreeID="2402"
50
+ NodeID="2402" UnifiedProductID="326363" IsFree="False"><Transition NodeName="Essential
51
+ Outright Get Paid - Monthly" UnifiedProductID="326365" TreeID="2410" IsFree="False"
52
+ NodeID="2410" /><Transition NodeName="Premium Outright Get Paid - Monthly"
53
+ UnifiedProductID="326388" TreeID="2418" IsFree="False" NodeID="2418" /><FilteredTransitions
54
+ /></Tree></Bonsai></Bonsai></AccountXml></GetAccountXmlResponse></soap:Body></soap:Envelope>
55
+ http_version: '1.1'
56
+ recorded_at: Fri, 18 Apr 2014 16:30:08 GMT
42
57
  recorded_with: VCR 2.8.0
@@ -1,10 +1,22 @@
1
+ require 'freddy'
1
2
  require 'savon'
2
3
 
3
4
  require 'ruby-ecomm-client/version'
4
5
  require 'ruby-ecomm-client/error'
5
- require 'ruby-ecomm-client/converter'
6
+ require 'ruby-ecomm-client'
7
+ require 'ruby-ecomm-client/util'
8
+
9
+ require 'ruby-ecomm-client/service_base'
10
+ require 'ruby-ecomm-client/service_manager'
11
+ require 'ruby-ecomm-client/service_profile'
12
+ require 'ruby-ecomm-client/service_purchase'
13
+
14
+ require 'ruby-ecomm-client/config'
6
15
  require 'ruby-ecomm-client/client'
7
16
 
8
17
  module RubyEcommClient
9
18
  # Your code goes here...
10
19
  end
20
+
21
+ #HACK: Avoid broken adapter ignoring SSL Certs when ExCon installed
22
+ HTTPI::Adapter.use = :net_http
@@ -1,33 +1,6 @@
1
1
  module RubyEcommClient
2
2
  class Client
3
- include ResponseConverter
4
-
5
- ENDPOINTS_MANAGER = {
6
- :development => 'http://bonsai.dev.glbt1.gdg/bonsai/bonsaimanager/service.asmx',
7
- :test => 'http://bonsai.dev.glbt1.gdg/bonsai/bonsaimanager/service.asmx',
8
- :production => 'http://gdbonsaiXv01.prod.mesa1.gdg/bonsai/bonsaimanager/service.asmx',
9
- :qa => 'http://bonsai.test.glbt1.gdg/bonsai/bonsaimanager/service.asmx'
10
- }
11
- ENDPOINTS_PROFILE = {
12
- :development => 'http://gdcomm.dev.glbt1.gdg/WSgdInstantPurchasePublic/Service.asmx',
13
- :test => 'http://gdcomm.dev.glbt1.gdg/WSgdInstantPurchasePublic/Service.asmx',
14
- :production => 'http://gdcomm.godaddy.com/WSgdInstantPurchasePublic/Service.asmx',
15
- :qa => 'http://gdcomm.test.glbt1.gdg/WSgdInstantPurchasePublic/Service.asmx'
16
- }
17
- ENDPOINTS_PURCHASE = {
18
- :development => 'https://bonsaipurchase.dev.glbt1.gdg/BonsaiPurchase/Service.asmx',
19
- :test => 'https://bonsaipurchase.dev.glbt1.gdg/BonsaiPurchase/Service.asmx',
20
- :production => 'https://bonsaipurchase.prod.mesa1.gdg/BonsaiPurchase/Service.asmx',
21
- :qa => 'https://bonsaipurchase.test.glbt1.gdg/BonsaiPurchase/Service.asmx'
22
- }
23
-
24
- HOST_NAME = `hostname`.chomp
25
-
26
- ID_TYPE = 'ORION'
27
-
28
- WSDL_MANAGER = 'manager.wsdl'
29
- WSDL_PROFILE = 'profile.wsdl'
30
- WSDL_PURCHASE = 'purchase.wsdl'
3
+ include Utils
31
4
 
32
5
  attr_accessor :shopper_id, :resource_type, :resource_id
33
6
 
@@ -41,148 +14,46 @@ module RubyEcommClient
41
14
  @resource_id = resource_id
42
15
  end
43
16
 
44
- def self.environment
45
- ((defined?(Rails) ? Rails.env : ENV['RAILS_ENV']) || 'development').to_sym
46
- end
47
-
48
17
  def express_checkout?
49
- result = client_profile.call(:shopper_has_instant_purchase_payment, :message => {
50
- 'sShopperID' => @shopper_id
51
- })
52
- response = convert_value(result.body[:shopper_has_instant_purchase_payment_response])
53
- response[:b_has_instant_purchase_payment]
18
+ service_profile.express_checkout?
54
19
  end
55
20
 
56
21
  def account_info(source_tree_id = 0)
57
- result = client_manager.call(:get_account_xml, :message => {
58
- 'ResourceID' => @resource_id,
59
- 'ResourceType' => @resource_type,
60
- 'IDType' => ID_TYPE,
61
- 'TreeID' => source_tree_id,
62
- 'PrivateLabelID' => 1
63
- })
64
- response = convert_response(result.body[:get_account_xml_response])
65
- if response[:result_code] == 0
66
- response[:account_xml][:bonsai][:bonsai]
67
- else
68
- raise RubyEcommError.new(response[:result_code])
69
- end
22
+ service_manager.account_info(source_tree_id)
70
23
  end
71
24
 
72
25
  def transitions(source_tree_id = 0)
73
- transitions = account_info(source_tree_id)[:tree][:transition]
74
- transitions.is_a?(Array) ? transitions : [transitions]
26
+ service_manager.transitions(source_tree_id)
75
27
  end
76
28
 
77
- def request_change(target_tree_id, client_ip = '127.0.0.1')
78
- raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
79
-
80
- if express_checkout?
81
- request_change_via_express(target_tree_id, client_ip)
82
- else
83
- request_change_via_manager(target_tree_id)
84
- end
85
- end
86
-
87
- private
88
-
89
- def blank?(value)
90
- value.nil? || value.to_s == ''
29
+ def find_transition(transitions, target_pfid)
30
+ service_manager.find_transition(transitions, target_pfid)
91
31
  end
92
32
 
93
- def wsdl_path
94
- "#{File.expand_path(File.dirname(__FILE__))}/wsdl/"
95
- end
96
-
97
- def shared_globals(globals)
98
- globals.convert_response_tags_to TAG_CONVERTER
99
- globals.log false
100
- globals.logger Rails.logger if defined?(Rails)
101
- globals.namespace '#Bonsai'
102
- globals.open_timeout 15
103
- globals.read_timeout 15
33
+ def request_change_via_manager(target_tree_id)
34
+ service_manager.request_change_via_manager(target_tree_id)
104
35
  end
105
36
 
106
- def client_manager
107
- @client_manager ||= Savon.client do |globals|
108
- shared_globals(globals)
109
-
110
- globals.wsdl "#{wsdl_path}#{WSDL_MANAGER}"
111
- globals.endpoint ENDPOINTS_MANAGER[Client.environment]
112
- end
37
+ def request_change_via_express(target_tree_id, client_ip = '127.0.0.1')
38
+ service_purchase.request_change_via_express(target_tree_id, client_ip)
113
39
  end
114
40
 
115
- def client_profile
116
- @client_profile ||= Savon.client do |globals|
117
- shared_globals(globals)
118
-
119
- globals.wsdl "#{wsdl_path}#{WSDL_PROFILE}"
120
- globals.endpoint ENDPOINTS_PROFILE[Client.environment]
121
- globals.namespace 'http://tempuri.org/'
122
- end
41
+ def request_change(target_tree_id, client_ip = '127.0.0.1')
42
+ service_purchase.request_change(target_tree_id, client_ip)
123
43
  end
124
44
 
125
- def client_purchase
126
- @client_purchase ||= Savon.client do |globals|
127
- shared_globals(globals)
128
-
129
- globals.wsdl "#{wsdl_path}#{WSDL_PURCHASE}"
130
- globals.endpoint ENDPOINTS_PURCHASE[Client.environment]
45
+ private
131
46
 
132
- globals.ssl_verify_mode :none
133
- ssl_cert_file = "config/environments/#{Client.environment}/client.crt"
134
- globals.ssl_cert_file ssl_cert_file if File.exists?(ssl_cert_file)
135
- ssl_cert_key_file = "config/environments/#{Client.environment}/client.key"
136
- globals.ssl_cert_key_file ssl_cert_key_file if File.exists?(ssl_cert_key_file)
137
- end
47
+ def service_manager
48
+ @service_manager ||= ServiceManager.new(self)
138
49
  end
139
50
 
140
- def request_change_via_express(target_tree_id, client_ip = '127.0.0.1')
141
- raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
142
-
143
- result = client_purchase.call(:purchase_change_account_request, :message => {
144
- 'ResourceID' => @resource_id,
145
- 'ResourceType' => @resource_type,
146
- 'IDType' => ID_TYPE,
147
- 'AccountPurchaseChangeXml' => "<ClientChange TreeID='#{target_tree_id}' ShopperID='#{@shopper_id}' TransactionCurrency='USD' RequestingApp='outright' RequestingAppHost='#{HOST_NAME}' ClientAddr='#{client_ip}' EnteredBy='customer' OrderSource='Online' RedirectToBasket='false' EstimateOnly='false' SendConfirmEmail='false'/>",
148
- 'RenewalPFID' => 0,
149
- 'RenewalPeriods' => 0,
150
- 'ItemRequestXml' => '<itemRequest/>'
151
- })
152
- response = convert_response(result.body[:purchase_change_account_request_response])
153
- if response[:result_code] == 0
154
- {
155
- :used_express_checkout => true,
156
- :request_result => response[:purchase_change_account_request_result],
157
- :error => response[:error],
158
- :order_xml => response[:order_xml]
159
- }
160
- else
161
- raise RubyEcommError.new(response[:result_code], response[:change_account_request_result])
162
- end
51
+ def service_profile
52
+ @service_profile ||= ServiceProfile.new(self)
163
53
  end
164
54
 
165
- def request_change_via_manager(target_tree_id)
166
- raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
167
-
168
- result = client_manager.call(:change_account_request, :message => {
169
- 'ResourceID' => @resource_id,
170
- 'ResourceType' => @resource_type,
171
- 'IDType' => ID_TYPE,
172
- 'AccountChangeXml' => "<ClientChange TreeID='#{target_tree_id}' ShopperID='#{@shopper_id}'/>",
173
- 'RenewalPFID' => 0,
174
- 'RenewalPeriods' => 0,
175
- 'ItemRequestXml' => '<itemRequest/>'
176
- })
177
- response = convert_response(result.body[:change_account_request_response])
178
- if response[:result_code] == 0
179
- {
180
- :used_express_checkout => false,
181
- :request_result => response[:change_account_request_result]
182
- }
183
- else
184
- raise RubyEcommError.new(response[:result_code], response[:change_account_request_result])
185
- end
55
+ def service_purchase
56
+ @service_purchase ||= ServicePurchase.new(self)
186
57
  end
187
58
  end
188
59
  end
@@ -0,0 +1,25 @@
1
+ module RubyEcommClient
2
+ class Config
3
+ include Utils
4
+
5
+ attr_accessor :requesting_app,
6
+ :ssl_cert_content,
7
+ :ssl_cert_file,
8
+ :ssl_cert_key_content,
9
+ :ssl_cert_key_file
10
+
11
+ def validate
12
+ raise ArgumentError.new('requesting_app must be specified') if Config.blank?(requesting_app)
13
+ end
14
+ end
15
+
16
+ def self.configure
17
+ cur_config = config
18
+ yield cur_config
19
+ cur_config.validate
20
+ end
21
+
22
+ def self.config
23
+ @config ||= Config.new
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ module RubyEcommClient
2
+ class ServiceBase
3
+ include Utils
4
+ include Freddy::ResponseConverter
5
+
6
+ ID_TYPE = 'ORION'
7
+
8
+ def initialize(config_client)
9
+ raise ArgumentError.new('config_client must be specified') if config_client.nil?
10
+
11
+ @config_client = config_client
12
+ end
13
+
14
+ protected
15
+
16
+ attr_reader :config_client
17
+
18
+ def config_global
19
+ RubyEcommClient.config
20
+ end
21
+
22
+ def wsdl_path
23
+ "#{File.expand_path(File.dirname(__FILE__))}/wsdl/"
24
+ end
25
+
26
+ def create_client
27
+ Savon.client do |globals|
28
+ globals.convert_response_tags_to TAG_CONVERTER
29
+ globals.log false
30
+ globals.logger Rails.logger if defined?(Rails)
31
+ globals.namespace '#Bonsai'
32
+ globals.open_timeout 15
33
+ globals.read_timeout 15
34
+
35
+ yield globals
36
+ end
37
+ end
38
+
39
+ def generate_request_hash
40
+ {
41
+ 'ResourceID' => config_client.resource_id,
42
+ 'ResourceType' => config_client.resource_type,
43
+ 'IDType' => ID_TYPE
44
+ }
45
+ end
46
+
47
+ def generate_request_change_hash
48
+ generate_request_hash.merge({
49
+ 'RenewalPFID' => 0,
50
+ 'RenewalPeriods' => 0,
51
+ 'ItemRequestXml' => '<itemRequest/>'
52
+ })
53
+ end
54
+ end
55
+ end