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
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::Payment do
6
+ let(:pay_key) { 'AP-4E8509886U908932M' }
7
+ let(:receiver_email) { 'chardy_1345003248_per@gmail.com' }
8
+ let(:receiver) { Receiver.new(:email => receiver_email, :amount => 10.0) }
9
+ let(:receiver_list) { ReceiverList.new(:receivers => [receiver]) }
10
+
11
+ describe "#refund" do
12
+ context "when successful" do
13
+ use_vcr_cassette "adaptive_payments/payment/refund/success"#, :record => :all
14
+
15
+ let(:payment) {
16
+ PayPal::AdaptivePayments::Payment.new(
17
+ :pay_key => pay_key,
18
+ :currency_code => 'USD'
19
+ )
20
+ }
21
+
22
+ subject { payment.refund }
23
+
24
+ its(:success?) { should be_true }
25
+ its(:valid?) { should be_true }
26
+ its(:refund_infos) { should have(1).item }
27
+ end
28
+
29
+ context "when failure" do
30
+ use_vcr_cassette "adaptive_payments/payment/refund/failure"#, :record => :all
31
+
32
+ let(:payment) {
33
+ PayPal::AdaptivePayments::Payment.new(
34
+ :pay_key => pay_key,
35
+ :receiver => receiver,
36
+ :currency_code => 'USD'
37
+ )
38
+ }
39
+
40
+ subject { payment.pay }
41
+
42
+ before { subject }
43
+
44
+ its(:success?) { should be_false }
45
+ its(:valid?) { should be_false }
46
+ its(:errors) { should_not be_empty }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::Payment do
6
+ let(:receiver_email) { 'chardy_1345003248_per@gmail.com' }
7
+ let(:receiver) { Receiver.new(:email => receiver_email, :amount => 10.0) }
8
+ let(:receiver_list) { ReceiverList.new(:receivers => [receiver]) }
9
+ let(:payment) {
10
+ PayPal::AdaptivePayments::Payment.new(
11
+ :receiver => receiver,
12
+ :currency_code => 'USD',
13
+ :cancel_url => 'http://example.com/cancel',
14
+ :return_url => 'http://example.com/thank_you'
15
+ )
16
+ }
17
+
18
+ describe "#shipping_addresses" do
19
+ context "when successful" do
20
+ use_vcr_cassette "adaptive_payments/payment/shipping_addresses/success"#, :record => :all
21
+
22
+ subject { payment.shipping_addresses }
23
+
24
+ before { payment.create }
25
+
26
+ its(:success?) { should be_true }
27
+ its(:valid?) { should be_true }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::PaymentOptions do
6
+ let(:receiver_email) { 'chardy_1345003248_per@gmail.com' }
7
+ let(:receiver) { Receiver.new(:email => receiver_email, :amount => 40.0) }
8
+ let(:receiver_list) { ReceiverList.new(:receivers => [receiver]) }
9
+ let(:payment) {
10
+ PayPal::AdaptivePayments::Payment.new(
11
+ :receiver => receiver,
12
+ :currency_code => 'USD',
13
+ :cancel_url => 'http://example.com/cancel',
14
+ :return_url => 'http://example.com/thank_you'
15
+ )
16
+ }
17
+
18
+ describe "#get" do
19
+ context "when successful" do
20
+ use_vcr_cassette "adaptive_payments/payment_options/get/success"#, :record => :all
21
+
22
+ before { payment.create }
23
+
24
+ let(:payment_options) {
25
+ PaymentOptions.new(:pay_key => payment.pay_key)
26
+ }
27
+
28
+ subject { payment_options.get }
29
+
30
+ its(:success?) { should be_true }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::PaymentOptions do
6
+ let(:receiver_email) { 'chardy_1345003248_per@gmail.com' }
7
+ let(:receiver) { Receiver.new(:email => receiver_email, :amount => 40.0) }
8
+ let(:receiver_list) { ReceiverList.new(:receivers => [receiver]) }
9
+ let(:payment) {
10
+ PayPal::AdaptivePayments::Payment.new(
11
+ :receiver => receiver,
12
+ :currency_code => 'USD',
13
+ :cancel_url => 'http://example.com/cancel',
14
+ :return_url => 'http://example.com/thank_you'
15
+ )
16
+ }
17
+
18
+ describe "#set" do
19
+ context "when successful" do
20
+ use_vcr_cassette "adaptive_payments/payment_options/set/success"#, :record => :all
21
+
22
+ before { payment.create }
23
+
24
+ let(:payment_options) {
25
+ PaymentOptions.new(
26
+ :pay_key => payment.pay_key,
27
+ :display_options => {
28
+ :email_header_image_url => "http://example.com/email_header.png",
29
+ :email_marketing_image_url => "http://example.com/email_marketing.png",
30
+ :business_name => "Dynosoft"
31
+ },
32
+ :sender_options => {
33
+ :require_shipping_address_selection => false,
34
+ :referrer_code => "RRRR"
35
+ },
36
+ :receiver_options => [
37
+ {
38
+ :description => "Testing",
39
+ :customer_id => "CUST_A",
40
+ :invoice_data => {
41
+ :item => [
42
+ {
43
+ :name => "Item A",
44
+ :identifier => "AA",
45
+ :price => 30.0,
46
+ :item_price => 15.0,
47
+ :item_count => 2
48
+ }
49
+ ],
50
+ :total_tax => 10.0,
51
+ :total_shipping => 0.0
52
+ },
53
+ :receiver => {
54
+ :email => receiver_email
55
+ }
56
+ }
57
+ ]
58
+ )
59
+ }
60
+
61
+ subject { payment_options.set }
62
+
63
+ its(:success?) { should be_true }
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::Preapproval do
6
+ let(:starting_date) { Date.today }
7
+
8
+ describe "#cancel" do
9
+ context "when successful" do
10
+ use_vcr_cassette "adaptive_payments/preapproval/details/success"#, :record => :all
11
+
12
+ let(:preapproval) {
13
+ Preapproval.new(
14
+ :client_details => {
15
+ :ip_address => "234.8.8.18",
16
+ :device_id => "123456",
17
+ :application_id => "PP"
18
+ },
19
+ :starting_date => starting_date,
20
+ :currency_code => 'USD',
21
+ :max_total_amount_of_all_payments => 2000.0,
22
+ :cancel_url => 'http://example.com/cancel',
23
+ :return_url => 'http://example.com/return'
24
+ )
25
+ }
26
+
27
+ before { preapproval.create }
28
+
29
+ subject { preapproval.cancel }
30
+
31
+ its(:success?) { should be_true }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::Preapproval do
6
+ let(:starting_date) { Date.today }
7
+
8
+ describe "#create" do
9
+ context "when successful" do
10
+ use_vcr_cassette "adaptive_payments/preapproval/create/success"#, :record => :all
11
+
12
+ let(:preapproval) {
13
+ Preapproval.new(
14
+ :client_details => {
15
+ :ip_address => "234.8.8.18",
16
+ :device_id => "123456",
17
+ :application_id => "PP"
18
+ },
19
+ :starting_date => starting_date,
20
+ :currency_code => 'USD',
21
+ :max_total_amount_of_all_payments => 2000.0,
22
+ :cancel_url => 'http://dss.example.com/cancel?preapprovalkey=${preapprovalkey}',
23
+ :return_url => 'http://dss.example.com/accepted?preapprovalkey=${preapprovalkey}'
24
+ )
25
+ }
26
+
27
+ subject { preapproval.create }
28
+
29
+ before { subject }
30
+
31
+ it "sets preapproval_key" do
32
+ preapproval.preapproval_key.should eql(subject.preapproval_key)
33
+ end
34
+ its(:success?) { should be_true }
35
+ its(:preapproval_key) { should_not be_nil }
36
+ its(:preapproval_url) { should eql("https://www.sandbox.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=#{preapproval.preapproval_key}") }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ include PayPal::AdaptivePayments
4
+
5
+ describe PayPal::AdaptivePayments::Preapproval do
6
+ let(:starting_date) { Date.today }
7
+
8
+ describe "#details" do
9
+ context "when successful" do
10
+ use_vcr_cassette "adaptive_payments/preapproval/details/success"#, :record => :all
11
+
12
+ let(:preapproval) {
13
+ Preapproval.new(
14
+ :client_details => {
15
+ :ip_address => "234.8.8.18",
16
+ :device_id => "123456",
17
+ :application_id => "PP"
18
+ },
19
+ :starting_date => starting_date,
20
+ :currency_code => 'USD',
21
+ :max_total_amount_of_all_payments => 2000.0,
22
+ :cancel_url => 'http://example.com/cancel',
23
+ :return_url => 'http://example.com/return'
24
+ )
25
+ }
26
+
27
+ before { preapproval.create }
28
+
29
+ subject { preapproval.details }
30
+
31
+ its(:success?) { should be_true }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe PayPal::AdaptivePayments::Request do
4
+ let(:pay_uri) { "#{PayPal::AdaptivePayments::Api.api_endpoint}/#{PayPal::AdaptivePayments::Request::METHODS[:pay]}" }
5
+
6
+ describe "#default_headers" do
7
+ subject { PayPal::AdaptivePayments::Request.new.default_headers }
8
+
9
+ [
10
+ 'X-PAYPAL-SECURITY-USERID',
11
+ 'X-PAYPAL-SECURITY-PASSWORD',
12
+ 'X-PAYPAL-SECURITY-SIGNATURE',
13
+ 'X-PAYPAL-REQUEST-DATA-FORMAT',
14
+ 'X-PAYPAL-RESPONSE-DATA-FORMAT',
15
+ 'X-PAYPAL-APPLICATION-ID',
16
+ 'User-Agent'
17
+ ].each do |key|
18
+ it "has key #{key}" do
19
+ subject.should have_key(key)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#method_endpoint" do
25
+ it "sets method api endpoint" do
26
+ subject.method_endpoint(:pay).should eql(pay_uri)
27
+ end
28
+ end
29
+
30
+ describe "#run" do
31
+ before :all do
32
+ VCR.eject_cassette
33
+ VCR.turn_off!
34
+ end
35
+
36
+ after :all do
37
+ VCR.turn_on!
38
+ end
39
+
40
+ it "sets body with JSON" do
41
+ stub_request(:post, pay_uri).
42
+ with(:body => MultiJson.dump({:abc => 'ABC', :requestEnvelope => {:errorLanguage => 'en_US', :detailLevel => 'ReturnAll'} })).
43
+ to_return(:status => 200, :body => "", :headers => {})
44
+
45
+ subject.run(:pay, {:abc => 'ABC'})
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,78 @@
1
+ require "spec_helper"
2
+
3
+ describe PayPal::Api do
4
+ after do
5
+ PayPal::Api.sandbox = true
6
+ end
7
+
8
+ subject { PayPal::Api }
9
+
10
+ describe ".sandbox=" do
11
+ before { PayPal::Api.instance.sandbox = false }
12
+ it "sets sandbox" do
13
+ expect{ subject.sandbox = true }.to change { PayPal::Api.instance.sandbox? }.from(false).to(true)
14
+ end
15
+ end
16
+
17
+ context "when sandbox" do
18
+ before { PayPal::Api.instance.sandbox = true }
19
+ its(:environment) { should eql(:sandbox) }
20
+ its(:site_endpoint) { should eql(PayPal::Api::SITE_ENDPOINTS[:sandbox]) }
21
+ end
22
+
23
+ context "when production" do
24
+ before { PayPal::Api.instance.sandbox = false }
25
+ its(:environment) { should eql(:production) }
26
+ its(:site_endpoint) { should eql(PayPal::Api::SITE_ENDPOINTS[:production]) }
27
+ end
28
+
29
+ describe ".instance" do
30
+ subject { PayPal::Api.instance }
31
+
32
+ it "should not be nil" do
33
+ should_not be_nil
34
+ end
35
+
36
+ describe "#sandbox?" do
37
+ it "detects sandbox" do
38
+ subject.sandbox = true
39
+ subject.should be_sandbox
40
+ end
41
+
42
+ it "ignores sandbox" do
43
+ subject.sandbox = false
44
+ subject.should_not be_sandbox
45
+ end
46
+ end
47
+
48
+ describe "#environment" do
49
+ it "returns production" do
50
+ subject.sandbox = false
51
+ subject.environment.should eq(:production)
52
+ end
53
+
54
+ it "returns sandbox" do
55
+ subject.sandbox = true
56
+ subject.environment.should eq(:sandbox)
57
+ end
58
+ end
59
+
60
+ describe "#configure" do
61
+ it "yields PayPal::Api.instance" do
62
+ subject.configure do |config|
63
+ config.should eql(PayPal::Api.instance)
64
+ end
65
+ end
66
+
67
+ it "sets attributes" do
68
+ subject.configure do |config|
69
+ config.sandbox = false
70
+ config.username = "test@api.com"
71
+ end
72
+
73
+ subject.sandbox.should be_false
74
+ subject.username.should eql("test@api.com")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,157 @@
1
+ require "spec_helper"
2
+
3
+ class SimpleTestHarness
4
+ include PayPal::Common::Base
5
+
6
+ attr_accessor :name, :email, :number, :phone
7
+ end
8
+
9
+ class PhoneTestHarness
10
+ include PayPal::Common::Base
11
+
12
+ attr_accessor :number, :country_code
13
+ end
14
+
15
+ class DeepTestHarness
16
+ include PayPal::Common::Base
17
+
18
+ attr_accessor :name, :receivers
19
+
20
+ def set_receivers(value)
21
+ self.receivers = build_value(SimpleTestHarness, value)
22
+ end
23
+ end
24
+
25
+ class ResponseTestHarness
26
+ include PayPal::Common::Base
27
+
28
+ attr_accessor :timestamp, :ack
29
+
30
+ def set_timestamp(value)
31
+ self.timestamp = Time.parse(value)
32
+ rescue
33
+ end
34
+ end
35
+
36
+ describe PayPal::Common::Base do
37
+ let(:name) { "Peter" }
38
+ let(:email) { "peter@spiderman.com" }
39
+ let(:number) { "12345" }
40
+ let(:attributes) { {:name => name, :email => email, :number => number} }
41
+ let(:phone_attrs) { {:number => "98765432", :country_code => "65"} }
42
+ let(:phone) { PhoneTestHarness.new(phone_attrs) }
43
+ let(:simple) { SimpleTestHarness.new(attributes.merge(:phone => phone)) }
44
+ let(:deep) { DeepTestHarness.new(:name => "deep test", :receivers => [simple]) }
45
+
46
+ describe "#initialize" do
47
+ subject { simple }
48
+
49
+ it "sets attributes" do
50
+ subject.name.should eql(name)
51
+ subject.email.should eql(email)
52
+ subject.number.should eql(number)
53
+ subject.phone.should eql(phone)
54
+ end
55
+
56
+ context "with camel case keys" do
57
+ subject { PhoneTestHarness.new('number' => '98765432', 'countryCode' => '65') }
58
+
59
+ it "sets attributes" do
60
+ subject.number.should eql('98765432')
61
+ subject.country_code.should eql('65')
62
+ end
63
+ end
64
+
65
+ context "with array value" do
66
+
67
+ it "build_value" do
68
+ DeepTestHarness.any_instance.should_receive(:build_value).with(SimpleTestHarness, [attributes, attributes])
69
+ DeepTestHarness.new(:name => "deep test", :receivers => [attributes, attributes])
70
+ end
71
+ end
72
+
73
+ context "with set_<attribute> method" do
74
+ subject { ResponseTestHarness.new('ack' => 'Success', 'timestamp' => '2013-01-03T22:10:56.934-08:00') }
75
+
76
+ it "sets attributes" do
77
+ subject.timestamp.is_a?(Time)
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#build_value" do
83
+ subject { DeepTestHarness.new.build_value(PhoneTestHarness, [phone_attrs, phone_attrs]) }
84
+
85
+ its(:size) { should eql(2) }
86
+ its(:first) { should be_a(PhoneTestHarness) }
87
+ end
88
+
89
+ describe "#camelize" do
90
+ let(:term) { "starting_date" }
91
+ let(:upper_case) { false }
92
+
93
+ subject { SimpleTestHarness.new.camelize(term, upper_case) }
94
+
95
+ it { should eql("startingDate") }
96
+ end
97
+
98
+ describe "#to_hash" do
99
+ subject { simple.to_hash }
100
+
101
+ it "has all keys" do
102
+ subject.should have_key(:name)
103
+ subject.should have_key(:email)
104
+ subject.should have_key(:number)
105
+ subject.should have_key(:phone)
106
+ end
107
+
108
+ it "sets all values" do
109
+ subject[:name].should eql(name)
110
+ subject[:email].should eql(email)
111
+ subject[:number].should eql(number)
112
+ subject[:phone].should eql({:number => "98765432", :countryCode => "65"})
113
+ end
114
+
115
+ context "with parameters" do
116
+ subject { simple.to_hash(:name, :email) }
117
+
118
+ it "only has selected keys" do
119
+ subject.should have_key(:name)
120
+ subject.should have_key(:email)
121
+ subject.should_not have_key(:number)
122
+ subject.should_not have_key(:phone)
123
+ end
124
+
125
+ it "only sets selected values" do
126
+ subject[:name].should eql(name)
127
+ subject[:email].should eql(email)
128
+ subject[:number].should be_nil
129
+ subject[:phone].should be_nil
130
+ end
131
+ end
132
+
133
+ context "deep" do
134
+ subject { deep.to_hash }
135
+
136
+ it "has object hash" do
137
+ subject[:receivers].should eql([attributes.merge(:phone => {:number => "98765432", :countryCode => "65"})])
138
+ end
139
+ end
140
+ end
141
+
142
+ describe "#to_json" do
143
+ subject { simple.to_json }
144
+
145
+ it "outputs json" do
146
+ subject.should eql("{\"name\":\"Peter\",\"email\":\"peter@spiderman.com\",\"number\":\"12345\",\"phone\":{\"number\":\"98765432\",\"countryCode\":\"65\"}}" )
147
+ end
148
+
149
+ context "with parameters" do
150
+ subject { simple.to_json(:name, :email) }
151
+
152
+ it "only outputs selected attributes" do
153
+ subject.should eql("{\"name\":\"Peter\",\"email\":\"peter@spiderman.com\"}" )
154
+ end
155
+ end
156
+ end
157
+ end