activemerchant 1.1.0 → 1.2.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 (178) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +226 -0
  3. data/CONTRIBUTERS +52 -0
  4. data/README +34 -24
  5. data/Rakefile +152 -0
  6. data/gem-public_cert.pem +20 -0
  7. data/init.rb +3 -0
  8. data/lib/active_merchant.rb +3 -1
  9. data/lib/active_merchant/billing/credit_card.rb +21 -17
  10. data/lib/active_merchant/billing/credit_card_methods.rb +17 -19
  11. data/lib/active_merchant/billing/gateway.rb +160 -44
  12. data/lib/active_merchant/billing/gateways.rb +2 -15
  13. data/lib/active_merchant/billing/gateways/authorize_net.rb +21 -21
  14. data/lib/active_merchant/billing/gateways/bogus.rb +6 -6
  15. data/lib/active_merchant/billing/gateways/brain_tree.rb +191 -0
  16. data/lib/active_merchant/billing/gateways/card_stream.rb +207 -0
  17. data/lib/active_merchant/billing/gateways/cyber_source.rb +402 -0
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +41 -97
  19. data/lib/active_merchant/billing/gateways/efsnet.rb +256 -0
  20. data/lib/active_merchant/billing/gateways/eway.rb +77 -29
  21. data/lib/active_merchant/billing/gateways/exact.rb +230 -0
  22. data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -33
  23. data/lib/active_merchant/billing/gateways/moneris.rb +155 -125
  24. data/lib/active_merchant/billing/gateways/net_registry.rb +257 -0
  25. data/lib/active_merchant/billing/gateways/pay_junction.rb +407 -0
  26. data/lib/active_merchant/billing/gateways/payflow.rb +163 -25
  27. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +56 -38
  28. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +10 -1
  29. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +9 -0
  30. data/lib/active_merchant/billing/gateways/payflow_express.rb +36 -11
  31. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +6 -0
  32. data/lib/active_merchant/billing/gateways/payflow_uk.rb +7 -3
  33. data/lib/active_merchant/billing/gateways/payment_express.rb +261 -0
  34. data/lib/active_merchant/billing/gateways/paypal.rb +18 -4
  35. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +31 -15
  36. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +8 -0
  37. data/lib/active_merchant/billing/gateways/paypal_express.rb +33 -8
  38. data/lib/active_merchant/billing/gateways/plugnpay.rb +300 -0
  39. data/lib/active_merchant/billing/gateways/protx.rb +285 -0
  40. data/lib/active_merchant/billing/gateways/psigate.rb +13 -12
  41. data/lib/active_merchant/billing/gateways/psl_card.rb +297 -0
  42. data/lib/active_merchant/billing/gateways/quickpay.rb +197 -0
  43. data/lib/active_merchant/billing/gateways/realex.rb +212 -0
  44. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  45. data/lib/active_merchant/billing/gateways/trans_first.rb +136 -0
  46. data/lib/active_merchant/billing/gateways/trust_commerce.rb +43 -20
  47. data/lib/active_merchant/billing/gateways/usa_epay.rb +6 -5
  48. data/lib/active_merchant/billing/gateways/verifi.rb +235 -0
  49. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  50. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -2
  51. data/lib/active_merchant/billing/integrations/helper.rb +8 -1
  52. data/lib/active_merchant/billing/integrations/nochex.rb +62 -1
  53. data/lib/active_merchant/billing/integrations/nochex/notification.rb +9 -16
  54. data/lib/active_merchant/billing/integrations/notification.rb +1 -1
  55. data/lib/active_merchant/billing/integrations/paypal/helper.rb +59 -46
  56. data/lib/active_merchant/billing/integrations/paypal/notification.rb +14 -47
  57. data/lib/active_merchant/lib/error.rb +4 -0
  58. data/lib/active_merchant/lib/post_data.rb +22 -0
  59. data/lib/active_merchant/lib/posts_data.rb +23 -5
  60. data/lib/active_merchant/lib/requires_parameters.rb +2 -2
  61. data/lib/active_merchant/lib/validateable.rb +1 -1
  62. data/lib/support/gateway_support.rb +45 -0
  63. data/lib/tasks/cia.rb +1 -1
  64. data/script/generate +14 -0
  65. data/script/generator/base.rb +45 -0
  66. data/script/generator/generator.rb +24 -0
  67. data/script/generator/generators/gateway/gateway_generator.rb +14 -0
  68. data/script/generator/generators/gateway/templates/gateway.rb +73 -0
  69. data/script/generator/generators/gateway/templates/gateway_test.rb +41 -0
  70. data/script/generator/generators/gateway/templates/remote_gateway_test.rb +56 -0
  71. data/script/generator/generators/integration/integration_generator.rb +25 -0
  72. data/script/generator/generators/integration/templates/helper.rb +34 -0
  73. data/script/generator/generators/integration/templates/helper_test.rb +54 -0
  74. data/script/generator/generators/integration/templates/integration.rb +18 -0
  75. data/script/generator/generators/integration/templates/module_test.rb +9 -0
  76. data/script/generator/generators/integration/templates/notification.rb +100 -0
  77. data/script/generator/generators/integration/templates/notification_test.rb +41 -0
  78. data/script/generator/manifest.rb +20 -0
  79. data/test/extra/binding_of_caller.rb +80 -0
  80. data/test/extra/breakpoint.rb +547 -0
  81. data/test/fixtures.yml +251 -0
  82. data/test/remote_tests/remote_authorize_net_test.rb +113 -0
  83. data/test/remote_tests/remote_brain_tree_test.rb +78 -0
  84. data/test/remote_tests/remote_card_stream_test.rb +160 -0
  85. data/test/remote_tests/remote_cyber_source_test.rb +130 -0
  86. data/test/remote_tests/remote_data_cash_test.rb +155 -0
  87. data/test/remote_tests/remote_efsnet_test.rb +93 -0
  88. data/test/remote_tests/remote_eway_test.rb +71 -0
  89. data/test/remote_tests/remote_exact_test.rb +59 -0
  90. data/test/remote_tests/remote_gestpay_integration_test.rb +37 -0
  91. data/test/remote_tests/remote_linkpoint_test.rb +144 -0
  92. data/test/remote_tests/remote_moneris_test.rb +110 -0
  93. data/test/remote_tests/remote_net_registry_test.rb +120 -0
  94. data/test/remote_tests/remote_pay_junction_test.rb +162 -0
  95. data/test/remote_tests/remote_payflow_express_test.rb +50 -0
  96. data/test/remote_tests/remote_payflow_test.rb +241 -0
  97. data/test/remote_tests/remote_payflow_uk_test.rb +172 -0
  98. data/test/remote_tests/remote_payment_express_test.rb +136 -0
  99. data/test/remote_tests/remote_paypal_express_test.rb +49 -0
  100. data/test/remote_tests/remote_paypal_integration_test.rb +14 -0
  101. data/test/remote_tests/remote_paypal_test.rb +163 -0
  102. data/test/remote_tests/remote_plugnpay_test.rb +70 -0
  103. data/test/remote_tests/remote_protx_test.rb +184 -0
  104. data/test/remote_tests/remote_psigate_test.rb +87 -0
  105. data/test/remote_tests/remote_psl_card_test.rb +105 -0
  106. data/test/remote_tests/remote_quickpay_test.rb +182 -0
  107. data/test/remote_tests/remote_realex_test.rb +227 -0
  108. data/test/remote_tests/remote_secure_pay_test.rb +36 -0
  109. data/test/remote_tests/remote_trans_first_test.rb +37 -0
  110. data/test/remote_tests/remote_trust_commerce_test.rb +136 -0
  111. data/test/remote_tests/remote_usa_epay_test.rb +57 -0
  112. data/test/remote_tests/remote_verifi_test.rb +107 -0
  113. data/test/remote_tests/remote_viaklix_test.rb +53 -0
  114. data/test/test_helper.rb +132 -0
  115. data/test/unit/base_test.rb +61 -0
  116. data/test/unit/country_code_test.rb +33 -0
  117. data/test/unit/country_test.rb +64 -0
  118. data/test/unit/credit_card_formatting_test.rb +24 -0
  119. data/test/unit/credit_card_methods_test.rb +37 -0
  120. data/test/unit/credit_card_test.rb +365 -0
  121. data/test/unit/gateways/authorize_net_test.rb +140 -0
  122. data/test/unit/gateways/bogus_test.rb +43 -0
  123. data/test/unit/gateways/brain_tree_test.rb +77 -0
  124. data/test/unit/gateways/card_stream_test.rb +37 -0
  125. data/test/unit/gateways/cyber_source_test.rb +151 -0
  126. data/test/unit/gateways/data_cash_test.rb +23 -0
  127. data/test/unit/gateways/efsnet_test.rb +70 -0
  128. data/test/unit/gateways/eway_test.rb +105 -0
  129. data/test/unit/gateways/exact_test.rb +118 -0
  130. data/test/unit/gateways/gateway_test.rb +24 -0
  131. data/test/unit/gateways/linkpoint_test.rb +165 -0
  132. data/test/unit/gateways/moneris_test.rb +167 -0
  133. data/test/unit/gateways/net_registry_test.rb +478 -0
  134. data/test/unit/gateways/pay_junction_test.rb +61 -0
  135. data/test/unit/gateways/payflow_express_test.rb +165 -0
  136. data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
  137. data/test/unit/gateways/payflow_test.rb +230 -0
  138. data/test/unit/gateways/payflow_uk_test.rb +68 -0
  139. data/test/unit/gateways/payment_express_test.rb +215 -0
  140. data/test/unit/gateways/paypal_express_test.rb +222 -0
  141. data/test/unit/gateways/paypal_test.rb +241 -0
  142. data/test/unit/gateways/plugnpay_test.rb +79 -0
  143. data/test/unit/gateways/protx_test.rb +110 -0
  144. data/test/unit/gateways/psigate_test.rb +110 -0
  145. data/test/unit/gateways/psl_card_test.rb +51 -0
  146. data/test/unit/gateways/quickpay_test.rb +125 -0
  147. data/test/unit/gateways/realex_test.rb +150 -0
  148. data/test/unit/gateways/secure_pay_test.rb +78 -0
  149. data/test/unit/gateways/trans_first_test.rb +125 -0
  150. data/test/unit/gateways/trust_commerce_test.rb +57 -0
  151. data/test/unit/gateways/usa_epay_test.rb +117 -0
  152. data/test/unit/gateways/verifi_test.rb +91 -0
  153. data/test/unit/gateways/viaklix_test.rb +72 -0
  154. data/test/unit/integrations/action_view_helper_test.rb +54 -0
  155. data/test/unit/integrations/bogus_module_test.rb +16 -0
  156. data/test/unit/integrations/chronopay_module_test.rb +9 -0
  157. data/test/unit/integrations/gestpay_module_test.rb +10 -0
  158. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  159. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  160. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  161. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  162. data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
  163. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  164. data/test/unit/integrations/nochex_module_test.rb +9 -0
  165. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  166. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  167. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  168. data/test/unit/integrations/notifications/notification_test.rb +41 -0
  169. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  170. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  171. data/test/unit/integrations/paypal_module_test.rb +24 -0
  172. data/test/unit/integrations/two_checkout_module_test.rb +9 -0
  173. data/test/unit/post_data_test.rb +55 -0
  174. data/test/unit/response_test.rb +14 -0
  175. data/test/unit/validateable_test.rb +56 -0
  176. metadata +160 -7
  177. metadata.gz.sig +0 -0
  178. data/lib/active_merchant/billing/gateways/payflow/f73e89fd.0 +0 -17
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class PayflowUkTest < Test::Unit::TestCase
4
+ def setup
5
+ @gateway = PayflowUkGateway.new(
6
+ :login => 'LOGIN',
7
+ :password => 'PASSWORD'
8
+ )
9
+
10
+ @creditcard = CreditCard.new(
11
+ :number => '4242424242424242',
12
+ :month => 8,
13
+ :year => 2008,
14
+ :first_name => 'Longbob',
15
+ :last_name => 'Longsen'
16
+ )
17
+
18
+ @address = { :address1 => '1234 My Street',
19
+ :address2 => 'Apt 1',
20
+ :company => 'Widgets Inc',
21
+ :city => 'Ottawa',
22
+ :state => 'ON',
23
+ :zip => 'K1C2N6',
24
+ :country => 'Canada',
25
+ :phone => '(555)555-5555'
26
+ }
27
+ end
28
+
29
+ def test_successful_request
30
+ @creditcard.number = 1
31
+ assert response = @gateway.purchase(100, @creditcard, {})
32
+ assert_success response
33
+ assert_equal '5555', response.authorization
34
+ assert response.test?
35
+ end
36
+
37
+ def test_unsuccessful_request
38
+ @creditcard.number = 2
39
+ assert response = @gateway.purchase(100, @creditcard, {})
40
+ assert_failure response
41
+ assert response.test?
42
+ end
43
+
44
+ def test_request_error
45
+ @creditcard.number = 3
46
+ assert_raise(Error){ @gateway.purchase(100, @creditcard, {}) }
47
+ end
48
+
49
+ def test_default_currency
50
+ assert_equal 'GBP', PayflowUkGateway.default_currency
51
+ end
52
+
53
+ def test_express_instance
54
+ assert_instance_of PayflowExpressUkGateway, @gateway.express
55
+ end
56
+
57
+ def test_default_partner
58
+ assert_equal 'PayPalUk', PayflowUkGateway.partner
59
+ end
60
+
61
+ def test_supported_countries
62
+ assert_equal ['GB'], PayflowUkGateway.supported_countries
63
+ end
64
+
65
+ def test_supported_card_types
66
+ assert_equal [:visa, :master, :american_express, :discover, :solo, :switch], PayflowUkGateway.supported_cardtypes
67
+ end
68
+ end
@@ -0,0 +1,215 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class PaymentExpressTest < Test::Unit::TestCase
4
+ def setup
5
+
6
+ @gateway = PaymentExpressGateway.new(
7
+ :login => 'LOGIN',
8
+ :password => 'PASSWORD'
9
+ )
10
+
11
+ @visa = CreditCard.new(
12
+ :number => '4242424242424242',
13
+ :month => 8,
14
+ :year => 2008,
15
+ :first_name => 'Longbob',
16
+ :last_name => 'Longsen',
17
+ :type => 'visa'
18
+ )
19
+
20
+ @solo = CreditCard.new(
21
+ :type => "solo",
22
+ :number => "6334900000000005",
23
+ :month => 11,
24
+ :year => 2012,
25
+ :first_name => "Test",
26
+ :last_name => "Mensch",
27
+ :issue_number => '01'
28
+ )
29
+
30
+ @address = { :address1 => '1234 My Street',
31
+ :address2 => 'Apt 1',
32
+ :company => 'Widgets Inc',
33
+ :city => 'Ottawa',
34
+ :state => 'ON',
35
+ :zip => 'K1C2N6',
36
+ :country => 'Canada',
37
+ :phone => '(555)555-5555'
38
+ }
39
+ end
40
+
41
+ def test_successful_request
42
+ @visa.number = 1
43
+
44
+ assert response = @gateway.purchase(100, @visa)
45
+ assert_success response
46
+ assert_equal '5555', response.authorization
47
+ assert response.test?
48
+ end
49
+
50
+ def test_unsuccessful_request
51
+ @visa.number = 2
52
+ assert response = @gateway.purchase(100, @visa)
53
+ assert_failure response
54
+ assert response.test?
55
+ end
56
+
57
+ def test_request_error
58
+ @visa.number = 3
59
+ assert_raise(Error){ @gateway.purchase(100, @visa) }
60
+ end
61
+
62
+ def test_default_currency
63
+ assert_equal 'NZD', PaymentExpressGateway.default_currency
64
+ end
65
+
66
+ def test_invalid_credentials
67
+ @gateway.expects(:ssl_post).returns(invalid_credentials_response)
68
+
69
+ assert response = @gateway.purchase(100, @visa)
70
+ assert_equal 'Invalid Credentials', response.message
71
+ assert_failure response
72
+ end
73
+
74
+ def test_successful_authorization
75
+ @gateway.expects(:ssl_post).returns(successful_authorization_response)
76
+
77
+ assert response = @gateway.purchase(100, @visa)
78
+ assert_success response
79
+ assert response.test?
80
+ assert_equal 'APPROVED', response.message
81
+ assert_equal '00000004011a2478', response.authorization
82
+ end
83
+
84
+ def test_successful_solo_authorization
85
+ @gateway.expects(:ssl_post).returns(successful_authorization_response)
86
+
87
+ assert response = @gateway.purchase(100, @solo)
88
+ assert_success response
89
+ assert response.test?
90
+ assert_equal 'APPROVED', response.message
91
+ assert_equal '00000004011a2478', response.authorization
92
+ end
93
+
94
+ def test_successful_card_store
95
+ @gateway.expects(:ssl_post).returns( successful_store_response )
96
+
97
+ assert response = @gateway.store(@visa)
98
+ assert_success response
99
+ assert response.test?
100
+ assert_equal '0000030000141581', response.token
101
+ end
102
+
103
+ def test_successful_card_store_with_custom_billing_id
104
+ @gateway.expects(:ssl_post).returns( successful_store_response(:billing_id => "my-custom-id") )
105
+
106
+ assert response = @gateway.store(@visa, :billing_id => "my-custom-id")
107
+ assert_success response
108
+ assert response.test?
109
+ assert_equal 'my-custom-id', response.token
110
+ end
111
+
112
+ def test_unsuccessful_card_store
113
+ @gateway.expects(:ssl_post).returns( unsuccessful_store_response )
114
+
115
+ @visa.number = 2
116
+
117
+ assert response = @gateway.store(@visa)
118
+ assert_failure response
119
+ end
120
+
121
+ def test_purchase_using_token
122
+ @gateway.expects(:ssl_post).returns( successful_store_response )
123
+
124
+ assert response = @gateway.store(@visa)
125
+ token = response.token
126
+
127
+ @gateway.expects(:ssl_post).returns( successful_token_purchase_response )
128
+
129
+ assert response = @gateway.purchase(100, token)
130
+ assert_success response
131
+ assert_equal 'APPROVED', response.message
132
+ assert_equal '0000000303ace8db', response.authorization
133
+ end
134
+
135
+ def test_supported_countries
136
+ assert_equal ['AU','MY','NZ','SG','ZA','GB','US'], PaymentExpressGateway.supported_countries
137
+ end
138
+
139
+ def test_supported_card_types
140
+ assert_equal [ :visa, :master, :american_express, :diners_club, :jcb ], PaymentExpressGateway.supported_cardtypes
141
+ end
142
+
143
+ private
144
+ def invalid_credentials_response
145
+ '<Txn><ReCo>0</ReCo><ResponseText>Invalid Credentials</ResponseText></Txn>'
146
+ end
147
+
148
+ def successful_authorization_response
149
+ <<-RESPONSE
150
+ <Txn>
151
+ <Transaction success="1" reco="00" responsetext="APPROVED">
152
+ <Authorized>1</Authorized>
153
+ <MerchantReference>Test Transaction</MerchantReference>
154
+ <Cvc2></Cvc2>
155
+ <CardName>Visa</CardName>
156
+ <Retry>0</Retry>
157
+ <StatusRequired>0</StatusRequired>
158
+ <AuthCode>015921</AuthCode>
159
+ <Amount>1.23</Amount>
160
+ <InputCurrencyId>1</InputCurrencyId>
161
+ <InputCurrencyName>NZD</InputCurrencyName>
162
+ <Acquirer>WestpacTrust</Acquirer>
163
+ <CurrencyId>1</CurrencyId>
164
+ <CurrencyName>NZD</CurrencyName>
165
+ <CurrencyRate>1.00</CurrencyRate>
166
+ <Acquirer>WestpacTrust</Acquirer>
167
+ <AcquirerDate>30102000</AcquirerDate>
168
+ <AcquirerId>1</AcquirerId>
169
+ <CardHolderName>DPS</CardHolderName>
170
+ <DateSettlement>20050811</DateSettlement>
171
+ <TxnType>Purchase</TxnType>
172
+ <CardNumber>411111</CardNumber>
173
+ <DateExpiry>0807</DateExpiry>
174
+ <ProductId></ProductId>
175
+ <AcquirerDate>20050811</AcquirerDate>
176
+ <AcquirerTime>060039</AcquirerTime>
177
+ <AcquirerId>9000</AcquirerId>
178
+ <Acquirer>Test</Acquirer>
179
+ <TestMode>1</TestMode>
180
+ <CardId>2</CardId>
181
+ <CardHolderResponseText>APPROVED</CardHolderResponseText>
182
+ <CardHolderHelpText>The Transaction was approved</CardHolderHelpText>
183
+ <CardHolderResponseDescription>The Transaction was approved</CardHolderResponseDescription>
184
+ <MerchantResponseText>APPROVED</MerchantResponseText>
185
+ <MerchantHelpText>The Transaction was approved</MerchantHelpText>
186
+ <MerchantResponseDescription>The Transaction was approved</MerchantResponseDescription>
187
+ <GroupAccount>9997</GroupAccount>
188
+ <DpsTxnRef>00000004011a2478</DpsTxnRef>
189
+ <AllowRetry>0</AllowRetry>
190
+ <DpsBillingId></DpsBillingId>
191
+ <BillingId></BillingId>
192
+ <TransactionId>011a2478</TransactionId>
193
+ </Transaction>
194
+ <ReCo>00</ReCo>
195
+ <ResponseText>APPROVED</ResponseText>
196
+ <HelpText>The Transaction was approved</HelpText>
197
+ <Success>1</Success>
198
+ <TxnRef>00000004011a2478</TxnRef>
199
+ </Txn>
200
+ RESPONSE
201
+ end
202
+
203
+ def successful_store_response(options = {})
204
+ %(<Txn><Transaction success="1" reco="00" responsetext="APPROVED"><Authorized>1</Authorized><MerchantReference></MerchantReference><CardName>Visa</CardName><Retry>0</Retry><StatusRequired>0</StatusRequired><AuthCode>02381203accf5c00000003</AuthCode><Amount>0.01</Amount><CurrencyId>554</CurrencyId><InputCurrencyId>554</InputCurrencyId><InputCurrencyName>NZD</InputCurrencyName><CurrencyRate>1.00</CurrencyRate><CurrencyName>NZD</CurrencyName><CardHolderName>BOB BOBSEN</CardHolderName><DateSettlement>20070323</DateSettlement><TxnType>Auth</TxnType><CardNumber>424242........42</CardNumber><DateExpiry>0809</DateExpiry><ProductId></ProductId><AcquirerDate>20070323</AcquirerDate><AcquirerTime>023812</AcquirerTime><AcquirerId>9000</AcquirerId><Acquirer>Test</Acquirer><TestMode>1</TestMode><CardId>2</CardId><CardHolderResponseText>APPROVED</CardHolderResponseText><CardHolderHelpText>The Transaction was approved</CardHolderHelpText><CardHolderResponseDescription>The Transaction was approved</CardHolderResponseDescription><MerchantResponseText>APPROVED</MerchantResponseText><MerchantHelpText>The Transaction was approved</MerchantHelpText><MerchantResponseDescription>The Transaction was approved</MerchantResponseDescription><UrlFail></UrlFail><UrlSuccess></UrlSuccess><EnablePostResponse>0</EnablePostResponse><PxPayName></PxPayName><PxPayLogoSrc></PxPayLogoSrc><PxPayUserId></PxPayUserId><PxPayXsl></PxPayXsl><PxPayBgColor></PxPayBgColor><AcquirerPort>9999999999-99999999</AcquirerPort><AcquirerTxnRef>12835</AcquirerTxnRef><GroupAccount>9997</GroupAccount><DpsTxnRef>0000000303accf5c</DpsTxnRef><AllowRetry>0</AllowRetry><DpsBillingId>0000030000141581</DpsBillingId><BillingId>#{options[:billing_id]}</BillingId><TransactionId>03accf5c</TransactionId><PxHostId>00000003</PxHostId></Transaction><ReCo>00</ReCo><ResponseText>APPROVED</ResponseText><HelpText>The Transaction was approved</HelpText><Success>1</Success><DpsTxnRef>0000000303accf5c</DpsTxnRef><TxnRef></TxnRef></Txn>)
205
+ end
206
+
207
+ def unsuccessful_store_response(options = {})
208
+ %(<Txn><Transaction success="0" reco="QK" responsetext="INVALID CARD NUMBER"><Authorized>0</Authorized><MerchantReference></MerchantReference><CardName></CardName><Retry>0</Retry><StatusRequired>0</StatusRequired><AuthCode></AuthCode><Amount>0.01</Amount><CurrencyId>554</CurrencyId><InputCurrencyId>554</InputCurrencyId><InputCurrencyName>NZD</InputCurrencyName><CurrencyRate>1.00</CurrencyRate><CurrencyName>NZD</CurrencyName><CardHolderName>LONGBOB LONGSEN</CardHolderName><DateSettlement>19800101</DateSettlement><TxnType>Validate</TxnType><CardNumber>000000........00</CardNumber><DateExpiry>0808</DateExpiry><ProductId></ProductId><AcquirerDate></AcquirerDate><AcquirerTime></AcquirerTime><AcquirerId>9000</AcquirerId><Acquirer></Acquirer><TestMode>0</TestMode><CardId>0</CardId><CardHolderResponseText>INVALID CARD NUMBER</CardHolderResponseText><CardHolderHelpText>An Invalid Card Number was entered. Check the card number</CardHolderHelpText><CardHolderResponseDescription>An Invalid Card Number was entered. Check the card number</CardHolderResponseDescription><MerchantResponseText>INVALID CARD NUMBER</MerchantResponseText><MerchantHelpText>An Invalid Card Number was entered. Check the card number</MerchantHelpText><MerchantResponseDescription>An Invalid Card Number was entered. Check the card number</MerchantResponseDescription><UrlFail></UrlFail><UrlSuccess></UrlSuccess><EnablePostResponse>0</EnablePostResponse><PxPayName></PxPayName><PxPayLogoSrc></PxPayLogoSrc><PxPayUserId></PxPayUserId><PxPayXsl></PxPayXsl><PxPayBgColor></PxPayBgColor><AcquirerPort>9999999999-99999999</AcquirerPort><AcquirerTxnRef>0</AcquirerTxnRef><GroupAccount>9997</GroupAccount><DpsTxnRef></DpsTxnRef><AllowRetry>0</AllowRetry><DpsBillingId></DpsBillingId><BillingId></BillingId><TransactionId>00000000</TransactionId><PxHostId>00000003</PxHostId></Transaction><ReCo>QK</ReCo><ResponseText>INVALID CARD NUMBER</ResponseText><HelpText>An Invalid Card Number was entered. Check the card number</HelpText><Success>0</Success><DpsTxnRef></DpsTxnRef><TxnRef></TxnRef></Txn>)
209
+ end
210
+
211
+ def successful_token_purchase_response
212
+ %(<Txn><Transaction success="1" reco="00" responsetext="APPROVED"><Authorized>1</Authorized><MerchantReference></MerchantReference><CardName>Visa</CardName><Retry>0</Retry><StatusRequired>0</StatusRequired><AuthCode>030817</AuthCode><Amount>10.00</Amount><CurrencyId>554</CurrencyId><InputCurrencyId>554</InputCurrencyId><InputCurrencyName>NZD</InputCurrencyName><CurrencyRate>1.00</CurrencyRate><CurrencyName>NZD</CurrencyName><CardHolderName>LONGBOB LONGSEN</CardHolderName><DateSettlement>20070323</DateSettlement><TxnType>Purchase</TxnType><CardNumber>424242........42</CardNumber><DateExpiry>0808</DateExpiry><ProductId></ProductId><AcquirerDate>20070323</AcquirerDate><AcquirerTime>030817</AcquirerTime><AcquirerId>9000</AcquirerId><Acquirer>Test</Acquirer><TestMode>1</TestMode><CardId>2</CardId><CardHolderResponseText>APPROVED</CardHolderResponseText><CardHolderHelpText>The Transaction was approved</CardHolderHelpText><CardHolderResponseDescription>The Transaction was approved</CardHolderResponseDescription><MerchantResponseText>APPROVED</MerchantResponseText><MerchantHelpText>The Transaction was approved</MerchantHelpText><MerchantResponseDescription>The Transaction was approved</MerchantResponseDescription><UrlFail></UrlFail><UrlSuccess></UrlSuccess><EnablePostResponse>0</EnablePostResponse><PxPayName></PxPayName><PxPayLogoSrc></PxPayLogoSrc><PxPayUserId></PxPayUserId><PxPayXsl></PxPayXsl><PxPayBgColor></PxPayBgColor><AcquirerPort>9999999999-99999999</AcquirerPort><AcquirerTxnRef>12859</AcquirerTxnRef><GroupAccount>9997</GroupAccount><DpsTxnRef>0000000303ace8db</DpsTxnRef><AllowRetry>0</AllowRetry><DpsBillingId>0000030000141581</DpsBillingId><BillingId></BillingId><TransactionId>03ace8db</TransactionId><PxHostId>00000003</PxHostId></Transaction><ReCo>00</ReCo><ResponseText>APPROVED</ResponseText><HelpText>The Transaction was approved</HelpText><Success>1</Success><DpsTxnRef>0000000303ace8db</DpsTxnRef><TxnRef></TxnRef></Txn>)
213
+ end
214
+
215
+ end
@@ -0,0 +1,222 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class PaypalExpressTest < Test::Unit::TestCase
4
+ TEST_REDIRECT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=1234567890'
5
+ LIVE_REDIRECT_URL = 'https://www.paypal.com/cgibin/webscr?cmd=_express-checkout&token=1234567890'
6
+
7
+ def setup
8
+ @gateway = PaypalExpressGateway.new(
9
+ :login => 'cody',
10
+ :password => 'test',
11
+ :pem => ''
12
+ )
13
+
14
+ @address = { :address1 => '1234 My Street',
15
+ :address2 => 'Apt 1',
16
+ :company => 'Widgets Inc',
17
+ :city => 'Ottawa',
18
+ :state => 'ON',
19
+ :zip => 'K1C2N6',
20
+ :country => 'Canada',
21
+ :phone => '(555)555-5555'
22
+ }
23
+
24
+ Base.gateway_mode = :test
25
+ end
26
+
27
+ def teardown
28
+ Base.gateway_mode = :test
29
+ end
30
+
31
+ def test_live_redirect_url
32
+ Base.gateway_mode = :production
33
+ assert_equal LIVE_REDIRECT_URL, @gateway.redirect_url_for('1234567890')
34
+ end
35
+
36
+ def test_force_sandbox_redirect_url
37
+ Base.gateway_mode = :production
38
+
39
+ gateway = PaypalExpressGateway.new(
40
+ :login => 'cody',
41
+ :password => 'test',
42
+ :pem => '',
43
+ :test => true
44
+ )
45
+
46
+ assert gateway.test?
47
+ assert_equal TEST_REDIRECT_URL, gateway.redirect_url_for('1234567890')
48
+ end
49
+
50
+ def test_test_redirect_url
51
+ assert_equal :test, Base.gateway_mode
52
+ assert_equal TEST_REDIRECT_URL, @gateway.redirect_url_for('1234567890')
53
+ end
54
+
55
+ def test_get_express_details
56
+ @gateway.expects(:ssl_post).returns(successful_details_response)
57
+ response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
58
+
59
+ assert_instance_of PaypalExpressResponse, response
60
+ assert response.success?
61
+ assert response.test?
62
+
63
+ assert_equal 'EC-6WS104951Y388951L', response.token
64
+ assert_equal 'FWRVKNRRZ3WUC', response.payer_id
65
+ assert_equal 'buyer@jadedpallet.com', response.email
66
+
67
+ assert address = response.address
68
+ assert_equal 'Fred Brooks', address['name']
69
+ assert_nil address['company']
70
+ assert_equal '1234 Penny Lane', address['address1']
71
+ assert_nil address['address2']
72
+ assert_equal 'Jonsetown', address['city']
73
+ assert_equal 'NC', address['state']
74
+ assert_equal '23456', address['zip']
75
+ assert_equal 'US', address['country']
76
+ assert_nil address['phone']
77
+ end
78
+
79
+ def test_authorization
80
+ @gateway.expects(:ssl_post).returns(successful_authorization_response)
81
+ response = @gateway.authorize(300, :token => 'EC-6WS104951Y388951L', :payer_id => 'FWRVKNRRZ3WUC')
82
+ assert response.success?
83
+ assert_not_nil response.authorization
84
+ assert response.test?
85
+ end
86
+
87
+ def test_default_payflow_currency
88
+ assert_equal 'USD', PayflowExpressGateway.default_currency
89
+ end
90
+
91
+ def test_default_partner
92
+ assert_equal 'PayPal', PayflowExpressGateway.partner
93
+ end
94
+
95
+ def test_uk_partner
96
+ assert_equal 'PayPalUk', PayflowExpressUkGateway.partner
97
+ end
98
+
99
+ def test_handle_non_zero_amount
100
+ xml = REXML::Document.new(@gateway.send(:build_setup_request, 'SetExpressCheckout', 50, {}))
101
+
102
+ assert_equal '0.50', REXML::XPath.first(xml, '//n2:OrderTotal').text
103
+ end
104
+
105
+ def test_handles_zero_amount
106
+ xml = REXML::Document.new(@gateway.send(:build_setup_request, 'SetExpressCheckout', 0, {}))
107
+
108
+ assert_equal '1.00', REXML::XPath.first(xml, '//n2:OrderTotal').text
109
+ end
110
+
111
+ def test_supported_countries
112
+ assert_equal ['US'], PaypalExpressGateway.supported_countries
113
+ end
114
+
115
+ def test_button_source
116
+ PaypalExpressGateway.application_id = 'ActiveMerchant_EC'
117
+
118
+ xml = REXML::Document.new(@gateway.send(:build_sale_or_authorization_request, 'Test', 100, {}))
119
+ assert_equal 'ActiveMerchant_EC', REXML::XPath.first(xml, '//n2:ButtonSource').text
120
+ end
121
+
122
+ def successful_details_response
123
+ <<-RESPONSE
124
+ <?xml version='1.0' encoding='UTF-8'?>
125
+ <SOAP-ENV:Envelope xmlns:cc='urn:ebay:apis:CoreComponentTypes' xmlns:sizeship='urn:ebay:api:PayPalAPI/sizeship.xsd' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:saml='urn:oasis:names:tc:SAML:1.0:assertion' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:wsu='http://schemas.xmlsoap.org/ws/2002/07/utility' xmlns:ebl='urn:ebay:apis:eBLBaseComponents' xmlns:ds='http://www.w3.org/2000/09/xmldsig#' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:ns='urn:ebay:api:PayPalAPI' xmlns:market='urn:ebay:apis:Market' xmlns:ship='urn:ebay:apis:ship' xmlns:auction='urn:ebay:apis:Auction' xmlns:wsse='http://schemas.xmlsoap.org/ws/2002/12/secext' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
126
+ <SOAP-ENV:Header>
127
+ <Security xsi:type='wsse:SecurityType' xmlns='http://schemas.xmlsoap.org/ws/2002/12/secext'/>
128
+ <RequesterCredentials xsi:type='ebl:CustomSecurityHeaderType' xmlns='urn:ebay:api:PayPalAPI'>
129
+ <Credentials xsi:type='ebl:UserIdPasswordType' xmlns='urn:ebay:apis:eBLBaseComponents'>
130
+ <Username xsi:type='xs:string'/>
131
+ <Password xsi:type='xs:string'/>
132
+ <Subject xsi:type='xs:string'/>
133
+ </Credentials>
134
+ </RequesterCredentials>
135
+ </SOAP-ENV:Header>
136
+ <SOAP-ENV:Body id='_0'>
137
+ <GetExpressCheckoutDetailsResponse xmlns='urn:ebay:api:PayPalAPI'>
138
+ <Timestamp xmlns='urn:ebay:apis:eBLBaseComponents'>2007-02-12T23:59:43Z</Timestamp>
139
+ <Ack xmlns='urn:ebay:apis:eBLBaseComponents'>Success</Ack>
140
+ <CorrelationID xmlns='urn:ebay:apis:eBLBaseComponents'>c73044f11da65</CorrelationID>
141
+ <Version xmlns='urn:ebay:apis:eBLBaseComponents'>2.000000</Version>
142
+ <Build xmlns='urn:ebay:apis:eBLBaseComponents'>1.0006</Build>
143
+ <GetExpressCheckoutDetailsResponseDetails xsi:type='ebl:GetExpressCheckoutDetailsResponseDetailsType' xmlns='urn:ebay:apis:eBLBaseComponents'>
144
+ <Token xsi:type='ebl:ExpressCheckoutTokenType'>EC-6WS104951Y388951L</Token>
145
+ <PayerInfo xsi:type='ebl:PayerInfoType'>
146
+ <Payer xsi:type='ebl:EmailAddressType'>buyer@jadedpallet.com</Payer>
147
+ <PayerID xsi:type='ebl:UserIDType'>FWRVKNRRZ3WUC</PayerID>
148
+ <PayerStatus xsi:type='ebl:PayPalUserStatusCodeType'>verified</PayerStatus>
149
+ <PayerName xsi:type='ebl:PersonNameType'>
150
+ <Salutation xmlns='urn:ebay:apis:eBLBaseComponents'/>
151
+ <FirstName xmlns='urn:ebay:apis:eBLBaseComponents'>Fred</FirstName>
152
+ <MiddleName xmlns='urn:ebay:apis:eBLBaseComponents'/>
153
+ <LastName xmlns='urn:ebay:apis:eBLBaseComponents'>Brooks</LastName>
154
+ <Suffix xmlns='urn:ebay:apis:eBLBaseComponents'/>
155
+ </PayerName>
156
+ <PayerCountry xsi:type='ebl:CountryCodeType'>US</PayerCountry>
157
+ <PayerBusiness xsi:type='xs:string'/>
158
+ <Address xsi:type='ebl:AddressType'>
159
+ <Name xsi:type='xs:string'>Fred Brooks</Name>
160
+ <Street1 xsi:type='xs:string'>1234 Penny Lane</Street1>
161
+ <Street2 xsi:type='xs:string'/>
162
+ <CityName xsi:type='xs:string'>Jonsetown</CityName>
163
+ <StateOrProvince xsi:type='xs:string'>NC</StateOrProvince>
164
+ <Country xsi:type='ebl:CountryCodeType'>US</Country>
165
+ <CountryName>United States</CountryName>
166
+ <PostalCode xsi:type='xs:string'>23456</PostalCode>
167
+ <AddressOwner xsi:type='ebl:AddressOwnerCodeType'>PayPal</AddressOwner>
168
+ <AddressStatus xsi:type='ebl:AddressStatusCodeType'>Confirmed</AddressStatus>
169
+ </Address>
170
+ </PayerInfo>
171
+ <InvoiceID xsi:type='xs:string'>1230123</InvoiceID>
172
+ </GetExpressCheckoutDetailsResponseDetails>
173
+ </GetExpressCheckoutDetailsResponse>
174
+ </SOAP-ENV:Body>
175
+ </SOAP-ENV:Envelope>
176
+ RESPONSE
177
+ end
178
+
179
+ def successful_authorization_response
180
+ <<-RESPONSE
181
+ <?xml version='1.0' encoding='UTF-8'?>
182
+ <SOAP-ENV:Envelope xmlns:cc='urn:ebay:apis:CoreComponentTypes' xmlns:sizeship='urn:ebay:api:PayPalAPI/sizeship.xsd' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:saml='urn:oasis:names:tc:SAML:1.0:assertion' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:wsu='http://schemas.xmlsoap.org/ws/2002/07/utility' xmlns:ebl='urn:ebay:apis:eBLBaseComponents' xmlns:ds='http://www.w3.org/2000/09/xmldsig#' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:ns='urn:ebay:api:PayPalAPI' xmlns:market='urn:ebay:apis:Market' xmlns:ship='urn:ebay:apis:ship' xmlns:auction='urn:ebay:apis:Auction' xmlns:wsse='http://schemas.xmlsoap.org/ws/2002/12/secext' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
183
+ <SOAP-ENV:Header>
184
+ <Security xsi:type='wsse:SecurityType' xmlns='http://schemas.xmlsoap.org/ws/2002/12/secext'/>
185
+ <RequesterCredentials xsi:type='ebl:CustomSecurityHeaderType' xmlns='urn:ebay:api:PayPalAPI'>
186
+ <Credentials xsi:type='ebl:UserIdPasswordType' xmlns='urn:ebay:apis:eBLBaseComponents'>
187
+ <Username xsi:type='xs:string'/>
188
+ <Password xsi:type='xs:string'/>
189
+ <Subject xsi:type='xs:string'/>
190
+ </Credentials>
191
+ </RequesterCredentials>
192
+ </SOAP-ENV:Header>
193
+ <SOAP-ENV:Body id='_0'>
194
+ <DoExpressCheckoutPaymentResponse xmlns='urn:ebay:api:PayPalAPI'>
195
+ <Timestamp xmlns='urn:ebay:apis:eBLBaseComponents'>2007-02-13T00:18:50Z</Timestamp>
196
+ <Ack xmlns='urn:ebay:apis:eBLBaseComponents'>Success</Ack>
197
+ <CorrelationID xmlns='urn:ebay:apis:eBLBaseComponents'>62450a4266d04</CorrelationID>
198
+ <Version xmlns='urn:ebay:apis:eBLBaseComponents'>2.000000</Version>
199
+ <Build xmlns='urn:ebay:apis:eBLBaseComponents'>1.0006</Build>
200
+ <DoExpressCheckoutPaymentResponseDetails xsi:type='ebl:DoExpressCheckoutPaymentResponseDetailsType' xmlns='urn:ebay:apis:eBLBaseComponents'>
201
+ <Token xsi:type='ebl:ExpressCheckoutTokenType'>EC-6WS104951Y388951L</Token>
202
+ <PaymentInfo xsi:type='ebl:PaymentInfoType'>
203
+ <TransactionID>8B266858CH956410C</TransactionID>
204
+ <ParentTransactionID xsi:type='ebl:TransactionId'/>
205
+ <ReceiptID/>
206
+ <TransactionType xsi:type='ebl:PaymentTransactionCodeType'>express-checkout</TransactionType>
207
+ <PaymentType xsi:type='ebl:PaymentCodeType'>instant</PaymentType>
208
+ <PaymentDate xsi:type='xs:dateTime'>2007-02-13T00:18:48Z</PaymentDate>
209
+ <GrossAmount currencyID='USD' xsi:type='cc:BasicAmountType'>3.00</GrossAmount>
210
+ <TaxAmount currencyID='USD' xsi:type='cc:BasicAmountType'>0.00</TaxAmount>
211
+ <ExchangeRate xsi:type='xs:string'/>
212
+ <PaymentStatus xsi:type='ebl:PaymentStatusCodeType'>Pending</PaymentStatus>
213
+ <PendingReason xsi:type='ebl:PendingStatusCodeType'>authorization</PendingReason>
214
+ <ReasonCode xsi:type='ebl:ReversalReasonCodeType'>none</ReasonCode>
215
+ </PaymentInfo>
216
+ </DoExpressCheckoutPaymentResponseDetails>
217
+ </DoExpressCheckoutPaymentResponse>
218
+ </SOAP-ENV:Body>
219
+ </SOAP-ENV:Envelope>
220
+ RESPONSE
221
+ end
222
+ end