paypal-payment 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +18 -0
  4. data/Guardfile +24 -0
  5. data/README.rdoc +107 -0
  6. data/Rakefile +5 -0
  7. data/docs/AdaptivePayments.rdoc +84 -0
  8. data/docs/PP_NVPAPI_DeveloperGuide.pdf +0 -0
  9. data/docs/PP_WPP_IntegrationGuide.pdf +0 -0
  10. data/docs/adaptive_payments.md +55 -0
  11. data/docs/api.txt +67 -0
  12. data/docs/design.txt +38 -0
  13. data/docs/express_checkout.md +172 -0
  14. data/docs/requirements.txt +32 -0
  15. data/lib/paypal-payment.rb +10 -0
  16. data/lib/paypal/adaptive_payments.rb +31 -0
  17. data/lib/paypal/adaptive_payments/api.rb +51 -0
  18. data/lib/paypal/adaptive_payments/base.rb +11 -0
  19. data/lib/paypal/adaptive_payments/client_details.rb +14 -0
  20. data/lib/paypal/adaptive_payments/display_options.rb +10 -0
  21. data/lib/paypal/adaptive_payments/funding_constraint.rb +11 -0
  22. data/lib/paypal/adaptive_payments/funding_type_info.rb +8 -0
  23. data/lib/paypal/adaptive_payments/funding_type_list.rb +11 -0
  24. data/lib/paypal/adaptive_payments/initiating_entity.rb +11 -0
  25. data/lib/paypal/adaptive_payments/institution_customer.rb +13 -0
  26. data/lib/paypal/adaptive_payments/invoice_data.rb +13 -0
  27. data/lib/paypal/adaptive_payments/invoice_item.rb +11 -0
  28. data/lib/paypal/adaptive_payments/payment.rb +105 -0
  29. data/lib/paypal/adaptive_payments/payment_info.rb +18 -0
  30. data/lib/paypal/adaptive_payments/payment_info_list.rb +11 -0
  31. data/lib/paypal/adaptive_payments/payment_options.rb +39 -0
  32. data/lib/paypal/adaptive_payments/phone.rb +9 -0
  33. data/lib/paypal/adaptive_payments/preapproval.rb +52 -0
  34. data/lib/paypal/adaptive_payments/receiver.rb +17 -0
  35. data/lib/paypal/adaptive_payments/receiver_list.rb +49 -0
  36. data/lib/paypal/adaptive_payments/receiver_options.rb +19 -0
  37. data/lib/paypal/adaptive_payments/request.rb +51 -0
  38. data/lib/paypal/adaptive_payments/response.rb +38 -0
  39. data/lib/paypal/adaptive_payments/response/address.rb +13 -0
  40. data/lib/paypal/adaptive_payments/response/address_list.rb +11 -0
  41. data/lib/paypal/adaptive_payments/response/base_address.rb +13 -0
  42. data/lib/paypal/adaptive_payments/response/details.rb +19 -0
  43. data/lib/paypal/adaptive_payments/response/error_list.rb +15 -0
  44. data/lib/paypal/adaptive_payments/response/pay.rb +31 -0
  45. data/lib/paypal/adaptive_payments/response/pay_error.rb +16 -0
  46. data/lib/paypal/adaptive_payments/response/pay_error_list.rb +15 -0
  47. data/lib/paypal/adaptive_payments/response/pay_options.rb +7 -0
  48. data/lib/paypal/adaptive_payments/response/preapproval.rb +47 -0
  49. data/lib/paypal/adaptive_payments/response/refund.rb +16 -0
  50. data/lib/paypal/adaptive_payments/response/refund_info.rb +24 -0
  51. data/lib/paypal/adaptive_payments/response/refund_info_list.rb +11 -0
  52. data/lib/paypal/adaptive_payments/response/shipping_address.rb +11 -0
  53. data/lib/paypal/adaptive_payments/sender_identifier.rb +7 -0
  54. data/lib/paypal/adaptive_payments/sender_options.rb +8 -0
  55. data/lib/paypal/api.rb +94 -0
  56. data/lib/paypal/cacert.pem +3987 -0
  57. data/lib/paypal/common.rb +11 -0
  58. data/lib/paypal/common/base.rb +83 -0
  59. data/lib/paypal/common/error_data.rb +15 -0
  60. data/lib/paypal/common/request.rb +45 -0
  61. data/lib/paypal/common/request_envelope.rb +13 -0
  62. data/lib/paypal/common/response.rb +34 -0
  63. data/lib/paypal/common/response_envelope.rb +19 -0
  64. data/lib/paypal/express_checkout.rb +19 -0
  65. data/lib/paypal/express_checkout/account.rb +16 -0
  66. data/lib/paypal/express_checkout/api.rb +43 -0
  67. data/lib/paypal/express_checkout/base.rb +37 -0
  68. data/lib/paypal/express_checkout/billing.rb +7 -0
  69. data/lib/paypal/express_checkout/callback.rb +17 -0
  70. data/lib/paypal/express_checkout/checkout.rb +144 -0
  71. data/lib/paypal/express_checkout/fields.rb +449 -0
  72. data/lib/paypal/express_checkout/fmf.rb +7 -0
  73. data/lib/paypal/express_checkout/payment.rb +76 -0
  74. data/lib/paypal/express_checkout/payment_item.rb +7 -0
  75. data/lib/paypal/express_checkout/recurring.rb +131 -0
  76. data/lib/paypal/express_checkout/request.rb +212 -0
  77. data/lib/paypal/express_checkout/response.rb +52 -0
  78. data/lib/paypal/express_checkout/response/account.rb +30 -0
  79. data/lib/paypal/express_checkout/response/address.rb +29 -0
  80. data/lib/paypal/express_checkout/response/authorization.rb +25 -0
  81. data/lib/paypal/express_checkout/response/base.rb +125 -0
  82. data/lib/paypal/express_checkout/response/callback_request.rb +10 -0
  83. data/lib/paypal/express_checkout/response/callback_response.rb +8 -0
  84. data/lib/paypal/express_checkout/response/capture.rb +14 -0
  85. data/lib/paypal/express_checkout/response/checkout.rb +11 -0
  86. data/lib/paypal/express_checkout/response/details.rb +35 -0
  87. data/lib/paypal/express_checkout/response/manage_profile.rb +9 -0
  88. data/lib/paypal/express_checkout/response/notification.rb +85 -0
  89. data/lib/paypal/express_checkout/response/payment.rb +24 -0
  90. data/lib/paypal/express_checkout/response/profile.rb +58 -0
  91. data/lib/paypal/express_checkout/response/reference.rb +11 -0
  92. data/lib/paypal/express_checkout/response/refund.rb +13 -0
  93. data/lib/paypal/express_checkout/response/search.rb +33 -0
  94. data/lib/paypal/express_checkout/response/transaction_details.rb +11 -0
  95. data/lib/paypal/express_checkout/shipping_option.rb +7 -0
  96. data/lib/paypal/express_checkout/utils.rb +26 -0
  97. data/lib/paypal/express_checkout/version.rb +10 -0
  98. data/lib/paypal/invoice.rb +22 -0
  99. data/lib/paypal/invoice/api.rb +51 -0
  100. data/lib/paypal/invoice/base.rb +11 -0
  101. data/lib/paypal/invoice/base_address.rb +11 -0
  102. data/lib/paypal/invoice/business_info.rb +17 -0
  103. data/lib/paypal/invoice/date_range.rb +8 -0
  104. data/lib/paypal/invoice/invoice.rb +117 -0
  105. data/lib/paypal/invoice/invoice_details.rb +38 -0
  106. data/lib/paypal/invoice/invoice_item.rb +13 -0
  107. data/lib/paypal/invoice/invoice_item_list.rb +10 -0
  108. data/lib/paypal/invoice/invoice_summary.rb +22 -0
  109. data/lib/paypal/invoice/invoice_summary_list.rb +10 -0
  110. data/lib/paypal/invoice/other_payment_details.rb +13 -0
  111. data/lib/paypal/invoice/payment_details.rb +16 -0
  112. data/lib/paypal/invoice/paypal_payment_details.rb +11 -0
  113. data/lib/paypal/invoice/request.rb +43 -0
  114. data/lib/paypal/invoice/response.rb +27 -0
  115. data/lib/paypal/invoice/response/details.rb +23 -0
  116. data/lib/paypal/invoice/response/invoice.rb +10 -0
  117. data/lib/paypal/invoice/response/search.rb +15 -0
  118. data/lib/paypal/invoice/search.rb +19 -0
  119. data/lib/paypal/invoice/search_parameters.rb +20 -0
  120. data/lib/paypal/permissions.rb +12 -0
  121. data/lib/paypal/permissions/api.rb +60 -0
  122. data/lib/paypal/permissions/base.rb +11 -0
  123. data/lib/paypal/permissions/permission.rb +33 -0
  124. data/lib/paypal/permissions/personal_data.rb +17 -0
  125. data/lib/paypal/permissions/request.rb +52 -0
  126. data/lib/paypal/permissions/response.rb +24 -0
  127. data/lib/paypal/permissions/response/permission.rb +14 -0
  128. data/lib/paypal/permissions/response/personal_data.rb +8 -0
  129. data/lib/paypal/permissions/response/token.rb +10 -0
  130. data/lib/paypal/permissions/token.rb +13 -0
  131. data/lib/paypal/recurring.rb +110 -0
  132. data/lib/paypal/request.rb +82 -0
  133. data/lib/paypal/version.rb +8 -0
  134. data/paypal-payment.gemspec +30 -0
  135. data/spec/fixtures/adaptive_payments/payment/create/failure.yml +62 -0
  136. data/spec/fixtures/adaptive_payments/payment/create/success.yml +58 -0
  137. data/spec/fixtures/adaptive_payments/payment/details/success.yml +113 -0
  138. data/spec/fixtures/adaptive_payments/payment/pay/failure.yml +62 -0
  139. data/spec/fixtures/adaptive_payments/payment/pay/preapproval.yml +58 -0
  140. data/spec/fixtures/adaptive_payments/payment/pay/success.yml +58 -0
  141. data/spec/fixtures/adaptive_payments/payment/pay/with_pay_key.yml +58 -0
  142. data/spec/fixtures/adaptive_payments/payment/refund/failure.yml +62 -0
  143. data/spec/fixtures/adaptive_payments/payment/refund/success.yml +58 -0
  144. data/spec/fixtures/adaptive_payments/payment/shipping_addresses/success.yml +113 -0
  145. data/spec/fixtures/adaptive_payments/payment_options/get/success.yml +174 -0
  146. data/spec/fixtures/adaptive_payments/payment_options/set/success.yml +113 -0
  147. data/spec/fixtures/adaptive_payments/preapproval/create/success.yml +58 -0
  148. data/spec/fixtures/adaptive_payments/preapproval/details/success.yml +168 -0
  149. data/spec/fixtures/express_checkout/account/balance/success.yml +32 -0
  150. data/spec/fixtures/express_checkout/account/pal_details/success.yml +32 -0
  151. data/spec/fixtures/express_checkout/checkout/checkout/sales/success.yml +61 -0
  152. data/spec/fixtures/express_checkout/checkout/checkout/success.yml +32 -0
  153. data/spec/fixtures/express_checkout/checkout/details/failure.yml +32 -0
  154. data/spec/fixtures/express_checkout/checkout/details/success.yml +61 -0
  155. data/spec/fixtures/express_checkout/checkout/pay/sales/success.yml +61 -0
  156. data/spec/fixtures/express_checkout/checkout/pay/success.yml +61 -0
  157. data/spec/fixtures/express_checkout/payment/details/failure.yml +32 -0
  158. data/spec/fixtures/express_checkout/payment/details/success.yml +32 -0
  159. data/spec/fixtures/express_checkout/payment/refund/failure.yml +32 -0
  160. data/spec/fixtures/express_checkout/payment/refund/success.yml +32 -0
  161. data/spec/fixtures/express_checkout/payment/search/success.yml +32 -0
  162. data/spec/fixtures/express_checkout/recurring/cancel/failure.yml +32 -0
  163. data/spec/fixtures/express_checkout/recurring/cancel/success.yml +32 -0
  164. data/spec/fixtures/express_checkout/recurring/checkout/success.yml +32 -0
  165. data/spec/fixtures/express_checkout/recurring/create_profile/failure.yml +32 -0
  166. data/spec/fixtures/express_checkout/recurring/create_profile/success.yml +61 -0
  167. data/spec/fixtures/express_checkout/recurring/profile/failure.yml +32 -0
  168. data/spec/fixtures/express_checkout/recurring/profile/success.yml +32 -0
  169. data/spec/fixtures/express_checkout/recurring/reactivate/failure.yml +32 -0
  170. data/spec/fixtures/express_checkout/recurring/reactivate/success.yml +32 -0
  171. data/spec/fixtures/express_checkout/recurring/suspend/failure.yml +32 -0
  172. data/spec/fixtures/express_checkout/recurring/suspend/success.yml +32 -0
  173. data/spec/fixtures/express_checkout/recurring/update_profile/failure.yml +32 -0
  174. data/spec/fixtures/express_checkout/recurring/update_profile/profile.yml +32 -0
  175. data/spec/fixtures/express_checkout/recurring/update_profile/success.yml +32 -0
  176. data/spec/fixtures/invoice/cancel/success.yml +174 -0
  177. data/spec/fixtures/invoice/create/failure.yml +62 -0
  178. data/spec/fixtures/invoice/create/success.yml +60 -0
  179. data/spec/fixtures/invoice/create_and_send/failure.yml +62 -0
  180. data/spec/fixtures/invoice/create_and_send/success.yml +60 -0
  181. data/spec/fixtures/invoice/details/success.yml +117 -0
  182. data/spec/fixtures/invoice/mark_as_paid/failure.yml +180 -0
  183. data/spec/fixtures/invoice/mark_as_paid/success.yml +174 -0
  184. data/spec/fixtures/invoice/mark_as_refunded/success.yml +174 -0
  185. data/spec/fixtures/invoice/mark_as_unpaid/success.yml +231 -0
  186. data/spec/fixtures/invoice/search/success.yml +174 -0
  187. data/spec/fixtures/invoice/send/success.yml +117 -0
  188. data/spec/fixtures/invoice/update/failure.yml +119 -0
  189. data/spec/fixtures/invoice/update/success.yml +117 -0
  190. data/spec/fixtures/ipn/express_checkout.json +35 -0
  191. data/spec/fixtures/ipn/recurring_payment.json +44 -0
  192. data/spec/fixtures/ipn/recurring_payment_profile_created.json +31 -0
  193. data/spec/fixtures/ipn/recurring_payment_profile_created_with_initial_amount.json +33 -0
  194. data/spec/fixtures/ipn/recurring_payment_skipped.json +30 -0
  195. data/spec/fixtures/ipn/recurring_payment_with_initial_amount.json +44 -0
  196. data/spec/fixtures/notification/failure.yml +50 -0
  197. data/spec/fixtures/notification/success.yml +50 -0
  198. data/spec/paypal/adaptive_payments/api_spec.rb +20 -0
  199. data/spec/paypal/adaptive_payments/payment/base_spec.rb +28 -0
  200. data/spec/paypal/adaptive_payments/payment/create_spec.rb +63 -0
  201. data/spec/paypal/adaptive_payments/payment/details_spec.rb +34 -0
  202. data/spec/paypal/adaptive_payments/payment/pay_spec.rb +97 -0
  203. data/spec/paypal/adaptive_payments/payment/refund_spec.rb +49 -0
  204. data/spec/paypal/adaptive_payments/payment/shipping_addresses_spec.rb +30 -0
  205. data/spec/paypal/adaptive_payments/payment_options/get_spec.rb +33 -0
  206. data/spec/paypal/adaptive_payments/payment_options/set_spec.rb +66 -0
  207. data/spec/paypal/adaptive_payments/preapproval/cancel_spec.rb +34 -0
  208. data/spec/paypal/adaptive_payments/preapproval/create_spec.rb +39 -0
  209. data/spec/paypal/adaptive_payments/preapproval/details_spec.rb +34 -0
  210. data/spec/paypal/adaptive_payments/request_spec.rb +48 -0
  211. data/spec/paypal/api_spec.rb +78 -0
  212. data/spec/paypal/common/base_spec.rb +157 -0
  213. data/spec/paypal/common/error_data_spec.rb +0 -0
  214. data/spec/paypal/common/request_envelope_spec.rb +6 -0
  215. data/spec/paypal/common/response_spec.rb +0 -0
  216. data/spec/paypal/express_checkout/account/balance_spec.rb +25 -0
  217. data/spec/paypal/express_checkout/account/pal_details_spec.rb +20 -0
  218. data/spec/paypal/express_checkout/checkout/checkout_spec.rb +73 -0
  219. data/spec/paypal/express_checkout/checkout/details_spec.rb +70 -0
  220. data/spec/paypal/express_checkout/checkout/pay_spec.rb +68 -0
  221. data/spec/paypal/express_checkout/fields_spec.rb +138 -0
  222. data/spec/paypal/express_checkout/payment/refund_spec.rb +34 -0
  223. data/spec/paypal/express_checkout/payment/search_spec.rb +24 -0
  224. data/spec/paypal/express_checkout/payment/transaction_details_spec.rb +30 -0
  225. data/spec/paypal/express_checkout/payment_spec.rb +13 -0
  226. data/spec/paypal/express_checkout/recurring/create_profile_spec.rb +50 -0
  227. data/spec/paypal/express_checkout/recurring/manage_profile_spec.rb +62 -0
  228. data/spec/paypal/express_checkout/recurring/profile_spec.rb +44 -0
  229. data/spec/paypal/express_checkout/recurring/update_profile_spec.rb +50 -0
  230. data/spec/paypal/express_checkout/request_spec.rb +221 -0
  231. data/spec/paypal/express_checkout/response/account_spec.rb +33 -0
  232. data/spec/paypal/express_checkout/response/base_spec.rb +253 -0
  233. data/spec/paypal/invoice/cancel_spec.rb +38 -0
  234. data/spec/paypal/invoice/create_and_send_spec.rb +58 -0
  235. data/spec/paypal/invoice/create_spec.rb +58 -0
  236. data/spec/paypal/invoice/details_spec.rb +39 -0
  237. data/spec/paypal/invoice/mark_as_paid_spec.rb +75 -0
  238. data/spec/paypal/invoice/mark_as_refunded_spec.rb +47 -0
  239. data/spec/paypal/invoice/mark_as_unpaid_spec.rb +43 -0
  240. data/spec/paypal/invoice/search_spec.rb +70 -0
  241. data/spec/paypal/invoice/send_spec.rb +48 -0
  242. data/spec/paypal/invoice/update_spec.rb +72 -0
  243. data/spec/paypal/request_spec.rb +45 -0
  244. data/spec/spec_helper.rb +35 -0
  245. metadata +546 -0
File without changes
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+ describe PayPal::Common::RequestEnvelope do
4
+ its(:error_language) { should eql('en_US') }
5
+ its(:detail_level) { should eql('ReturnAll') }
6
+ end
File without changes
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::ExpressCheckout
4
+
5
+ describe PayPal::ExpressCheckout::Account do
6
+ describe "#balance" do
7
+ context "when successful" do
8
+ use_vcr_cassette "express_checkout/account/balance/success"
9
+
10
+ let(:account) { Account.new }
11
+
12
+ subject { account.balance }
13
+
14
+ it { should be_success }
15
+ it { should be_valid }
16
+ its(:balances) { should have(1).item }
17
+ it "should have the correct amount" do
18
+ subject.balances.first[:amount].should eql(224.58)
19
+ end
20
+ it "should have the correct currency" do
21
+ subject.balances.first[:currency].should eql('USD')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::ExpressCheckout
4
+
5
+ describe PayPal::ExpressCheckout::Account do
6
+ describe "#pal_details" do
7
+ context "when successful" do
8
+ use_vcr_cassette "express_checkout/account/pal_details/success"
9
+
10
+ let(:account) { Account.new }
11
+
12
+ subject { account.pal_details }
13
+
14
+ it { should be_success }
15
+ it { should be_valid }
16
+ its(:pal) { should_not be_empty }
17
+ its(:locale) { should_not be_empty }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::ExpressCheckout
4
+
5
+ describe PayPal::ExpressCheckout::Checkout do
6
+ describe "#checkout" do
7
+ context "for authorization (Recurring)" do
8
+ context "when successful" do
9
+ use_vcr_cassette "express_checkout/checkout/checkout/success"
10
+ let(:token) { "EC-2EV77664BK856305S" }
11
+ let(:payment) {
12
+ PayPal::ExpressCheckout::Payment.new(
13
+ :payment_action => "Authorization",
14
+ :description => "Awesome - Monthly Subscription",
15
+ :notify_url => "http://example.com/paypal/ipn",
16
+ :amount => "9.00",
17
+ :currency => "USD"
18
+ )
19
+ }
20
+ let(:billing) {
21
+ PayPal::ExpressCheckout::Billing.new(
22
+ :type => 'RecurringPayments',
23
+ :description => "Awesome - Monthly Subscription"
24
+ )
25
+ }
26
+ subject {
27
+ ppc = PayPal::ExpressCheckout::Checkout.new({
28
+ :return_url => "http://example.com/thank_you",
29
+ :cancel_url => "http://example.com/canceled",
30
+ :billings => [ billing ],
31
+ :payments => [ payment ]
32
+ })
33
+
34
+ ppc.checkout
35
+ }
36
+
37
+ its(:valid?) { should be_true }
38
+ its(:errors) { should be_empty }
39
+ its(:checkout_url) { should == "#{PayPal::Api.site_endpoint}?cmd=_express-checkout&token=#{token}&useraction=commit" }
40
+ end
41
+ end
42
+
43
+ context "for sales" do
44
+ context "when successful" do
45
+ use_vcr_cassette "express_checkout/checkout/checkout/sales/success"
46
+
47
+ let(:token) { "EC-12X82860F72356252" }
48
+ let(:payment) {
49
+ PayPal::ExpressCheckout::Payment.new(
50
+ :payment_action => "Sale",
51
+ :description => "Awesome Shop",
52
+ :amount => "20.00",
53
+ :currency => "USD"
54
+ )
55
+ }
56
+ subject {
57
+ ppc = PayPal::ExpressCheckout::Checkout.new({
58
+ :return_url => "http://example.com/thank_you",
59
+ :cancel_url => "http://example.com/canceled",
60
+ :payments => [ payment ]
61
+ })
62
+
63
+ response = ppc.checkout
64
+ response
65
+ }
66
+
67
+ its(:valid?) { should be_true }
68
+ its(:errors) { should be_empty }
69
+ its(:checkout_url) { should == "#{PayPal::Api.site_endpoint}?cmd=_express-checkout&token=#{token}&useraction=commit" }
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,70 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::ExpressCheckout
4
+
5
+ describe PayPal::ExpressCheckout::Checkout do
6
+ describe "#details" do
7
+ context "when successful" do
8
+ use_vcr_cassette "express_checkout/checkout/details/success"#, :record => :all
9
+ let(:payment) {
10
+ PayPal::ExpressCheckout::Payment.new(
11
+ :notify_url => "http://example.com/paypal/ipn",
12
+ :description => "Awesome - Monthly Subscription",
13
+ :amount => "9.00",
14
+ :currency => "USD",
15
+ :payment_action => "Sales"
16
+ )
17
+ }
18
+ let(:checkout) {
19
+ ppc = PayPal::ExpressCheckout::Checkout.new(
20
+ :return_url => "http://example.com/thank_you",
21
+ :cancel_url => "http://example.com/canceled",
22
+ :payments => [ payment ]
23
+ )
24
+
25
+ ppc.checkout
26
+ }
27
+ let(:token) { checkout.token }
28
+
29
+ subject {
30
+ ppr = PayPal::ExpressCheckout::Checkout.new(:token => token)
31
+ ppr.details
32
+ }
33
+
34
+ it { should be_valid }
35
+ it { should be_success }
36
+
37
+ its(:errors) { should be_empty }
38
+ its(:checkout_status) { should == "PaymentActionNotInitiated" }
39
+ its(:requested_at) { should be_a(Time) }
40
+ its(:currency) { should == "USD" }
41
+ its(:description) { should == "Awesome - Monthly Subscription" }
42
+ its(:notify_url) { should == "http://example.com/paypal/ipn" }
43
+ end
44
+
45
+ # context "when cancelled" do
46
+ # use_vcr_cassette "details/cancelled"
47
+ # subject {
48
+ # ppr = PayPal::Recurring.new(:token => "EC-8J298813NS092694P")
49
+ # ppr.checkout_details
50
+ # }
51
+
52
+ # it { should be_valid }
53
+ # it { should be_success }
54
+
55
+ # its(:agreed?) { should be_false }
56
+ # end
57
+
58
+ context "when failure" do
59
+ use_vcr_cassette "express_checkout/checkout/details/failure"
60
+
61
+ subject { PayPal::ExpressCheckout::Checkout.new.details }
62
+
63
+ it { should_not be_valid }
64
+ it { should_not be_success }
65
+
66
+ its(:errors) { should have(1).item }
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::ExpressCheckout
4
+
5
+ describe PayPal::ExpressCheckout::Checkout do
6
+ describe "#pay" do
7
+ context "for Authorization" do
8
+ context "when successful" do
9
+ use_vcr_cassette "express_checkout/checkout/pay/success"
10
+ # let(:payer_id) { "4YLKLC48QZJ6Y" }
11
+ let(:token) { "EC-66R94860GU0469430" }
12
+ let(:payment) {
13
+ PayPal::ExpressCheckout::Payment.new(
14
+ :payment_action => "Authorization",
15
+ :description => "MacBook Air",
16
+ :notify_url => "http://example.com/paypal/ipn",
17
+ :amount => "1300.00",
18
+ :currency => "USD"
19
+ )
20
+ }
21
+ let(:payer_id) {
22
+ co = PayPal::ExpressCheckout::Checkout.new(:token => token)
23
+ co.details.payer_id
24
+ }
25
+ subject {
26
+ co = PayPal::ExpressCheckout::Checkout.new(
27
+ :token => token,
28
+ :payer_id => payer_id,
29
+ :payments => [payment]
30
+ )
31
+ co.pay
32
+ }
33
+ # it { puts "checkout.checkout_url = #{checkout.checkout_url}" }
34
+ its(:valid?) { should be_true }
35
+ its(:errors) { should be_empty }
36
+ # its(:checkout_url) { should == "#{PayPal::Api.site_endpoint}?cmd=_express-checkout&token=#{token}&useraction=commit" }
37
+ end
38
+ end
39
+
40
+ context "for Sale" do
41
+ use_vcr_cassette "express_checkout/checkout/pay/sales/success"
42
+
43
+ let(:token) { "EC-4NT45905PP4254419" }
44
+ let(:details) { PayPal::ExpressCheckout::Checkout.new(:token => token).details }
45
+ let(:payer_id) { details.payer_id }
46
+ let(:payment) {
47
+ PayPal::ExpressCheckout::Payment.new(
48
+ :payment_action => "Sale",
49
+ :description => "Awesome Shop",
50
+ :amount => "20.00",
51
+ :currency => "USD"
52
+ )
53
+ }
54
+
55
+ subject {
56
+ co = PayPal::ExpressCheckout::Checkout.new(
57
+ :token => token,
58
+ :payer_id => payer_id,
59
+ :payments => [payment]
60
+ )
61
+ co.pay
62
+ }
63
+
64
+ its(:valid?) { should be_true }
65
+ its(:errors) { should be_empty }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ class FieldsTestHarness
4
+ include PayPal::ExpressCheckout::Fields
5
+ end
6
+
7
+ class AssociationTestHarness
8
+ include PayPal::ExpressCheckout::Fields
9
+ end
10
+
11
+ class SuperTestHarness
12
+ include PayPal::ExpressCheckout::Fields
13
+
14
+ has_fields :payer
15
+
16
+ has_many :shipping_options
17
+ end
18
+
19
+ class SubTestHarness < SuperTestHarness
20
+ has_fields :amount
21
+
22
+ has_many :payment_items
23
+ end
24
+
25
+ describe PayPal::ExpressCheckout::Fields do
26
+ describe "##has_fields" do
27
+ before { FieldsTestHarness.has_fields(:checkout, :buyer) }
28
+
29
+ subject { FieldsTestHarness.new }
30
+
31
+ [:checkout, :buyer].each do |group|
32
+ PayPal::ExpressCheckout::Fields::ATTRIBUTES[group].each_key do |field|
33
+ its(:methods) { should include(field) }
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "##field_map" do
39
+ let(:model) { FieldsTestHarness }
40
+ let(:value) { PayPal::ExpressCheckout::Fields::ATTRIBUTES[:shipping_option][:amount] }
41
+
42
+ before do
43
+ model.has_fields(:payer, :shipping_option)
44
+ end
45
+
46
+ subject { model.field_map }
47
+
48
+ [:payer, :shipping_option].each do |group|
49
+ PayPal::ExpressCheckout::Fields::ATTRIBUTES[group].each_key do |field|
50
+ it { should have_key(field) }
51
+ end
52
+ end
53
+
54
+ it "should return the correct value" do
55
+ subject[:amount].should eql(value)
56
+ end
57
+
58
+ context "with associations" do
59
+ let(:model) { AssociationTestHarness }
60
+
61
+ before do
62
+ model.has_many(:shipping_options)
63
+ end
64
+
65
+ it "should return the correct value" do
66
+ subject[:shipping_options].should eql(PayPal::ExpressCheckout::Fields::ASSOCIATIONS[:shipping_options])
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "##has_many" do
72
+ before { FieldsTestHarness.has_many(:shipping_options) }
73
+
74
+ subject { FieldsTestHarness.new }
75
+
76
+ [:shipping_options].each do |association|
77
+ its(:methods) { should include(association) }
78
+
79
+ it "should return empty array for associations" do
80
+ subject.shipping_options.should eql([])
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#collect_group" do
86
+ let(:field_count) {
87
+ PayPal::ExpressCheckout::Fields::ATTRIBUTES[:amount].size +
88
+ PayPal::ExpressCheckout::Fields::ATTRIBUTES[:credit_card].size + 1
89
+ }
90
+
91
+ before do
92
+ AssociationTestHarness.has_fields(:amount, :credit_card)
93
+ AssociationTestHarness.has_many(:shipping_options)
94
+ end
95
+
96
+ subject { AssociationTestHarness.new.group_fields(:amount, :credit_card, :shipping_options) }
97
+
98
+ its(:count) { should eql(field_count) }
99
+ end
100
+
101
+ describe "inheritance" do
102
+ describe "super class" do
103
+ subject { SuperTestHarness.new }
104
+
105
+ [:payer_id, :email].each do |field|
106
+ its(:methods) { should include(field) }
107
+ end
108
+ [:amount, :fee_amount].each do |field|
109
+ its(:methods) { should_not include(field) }
110
+ end
111
+ [:shipping_options].each do |association|
112
+ its(:methods) { should include(association) }
113
+ end
114
+ [:payment_items].each do |association|
115
+ its(:methods) { should_not include(association) }
116
+ end
117
+ end
118
+
119
+ describe "subclass" do
120
+ subject { SubTestHarness.new }
121
+
122
+ [:payer_id, :email, :amount, :fee_amount].each do |field|
123
+ its(:methods) { should include(field) }
124
+ end
125
+ [:shipping_options, :payment_items].each do |association|
126
+ its(:methods) { should include(association) }
127
+ end
128
+
129
+ describe "#field_map" do
130
+ subject { SubTestHarness.field_map }
131
+
132
+ [:payer_id, :email, :amount, :fee_amount].each do |field|
133
+ it { should have_key(field) }
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe PayPal::ExpressCheckout::Payment do
4
+ describe "#refund" do
5
+ let(:paypal) {
6
+ PayPal::ExpressCheckout::Payment.new({
7
+ :profile_id => "I-9P7YSC1J6XET",
8
+ :transaction_id => "9H105857DB8084710",
9
+ :refund_type => "Full",
10
+ :amount => "9.00",
11
+ :currency => "USD"
12
+ })
13
+ }
14
+
15
+ context "when successful" do
16
+ use_vcr_cassette "express_checkout/payment/refund/success"
17
+ subject { paypal.refund }
18
+
19
+ its(:refund_transaction_id) { should eql("4T450045RX025224L") }
20
+ its(:fee_refund_amount) { should eql("0.26") }
21
+ its(:gross_refund_amount) { should eql("9.00") }
22
+ its(:net_refund_amount) { should eql("8.74") }
23
+ its(:total_refunded_amount) { should eql("9.00") }
24
+ its(:currency) { should eql("USD") }
25
+ end
26
+
27
+ context "when failure" do
28
+ use_vcr_cassette "express_checkout/payment/refund/failure"
29
+ subject { paypal.refund }
30
+
31
+ its(:errors) { should have(1).items }
32
+ end
33
+ end
34
+ end