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,52 @@
1
+ module PayPal::AdaptivePayments
2
+ class Preapproval < PayPal::AdaptivePayments::Base
3
+
4
+ attr_accessor :preapproval_key
5
+ attr_accessor :client_details
6
+ attr_accessor :cancel_url
7
+ attr_accessor :currency_code
8
+ attr_accessor :date_of_month
9
+ attr_accessor :day_of_week
10
+ attr_accessor :ending_date
11
+ attr_accessor :max_amount_per_payment
12
+ attr_accessor :max_number_of_payments
13
+ attr_accessor :max_number_of_payments_per_period
14
+ attr_accessor :max_total_amount_of_all_payments
15
+ attr_accessor :payment_period
16
+ attr_accessor :return_url
17
+ attr_accessor :memo
18
+ attr_accessor :ipn_notification_url
19
+ attr_accessor :sender_email
20
+ attr_accessor :starting_date
21
+ attr_accessor :pin_type
22
+ attr_accessor :display_max_total_amount
23
+ attr_accessor :fees_payer
24
+ attr_accessor :require_instant_funding_source
25
+
26
+ def set_client_details(value)
27
+ self.client_details = build_value(ClientDetails, value)
28
+ end
29
+
30
+ def set_ending_date(value)
31
+ self.ending_date = build_datetime(value)
32
+ end
33
+
34
+ def set_starting_date(value)
35
+ self.starting_date = build_datetime(value)
36
+ end
37
+
38
+ def create
39
+ response = Response.process(:preapproval, request.run(:preapproval, self.to_hash))
40
+ self.preapproval_key = response.preapproval_key
41
+ response
42
+ end
43
+
44
+ def details
45
+ Response.process(:preapproval_details, request.run(:preapproval_details, self.to_hash(:preapproval_key)))
46
+ end
47
+
48
+ def cancel
49
+ Response.process(:cancel_preapproval, request.run(:cancel_preapproval, self.to_hash(:preapproval_key)))
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ module PayPal::AdaptivePayments
2
+ class Receiver
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :amount
6
+ attr_accessor :email
7
+ attr_accessor :invoice_id
8
+ attr_accessor :payment_type
9
+ attr_accessor :payment_sub_type
10
+ attr_accessor :phone
11
+ attr_accessor :primary
12
+
13
+ def set_phone(value)
14
+ self.phone = build_value(PayPal::AdaptivePayments::Phone, value)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,49 @@
1
+ module PayPal::AdaptivePayments
2
+ class ReceiverList
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :receiver
6
+
7
+ def after_initialize
8
+ super
9
+ @receiver ||= []
10
+ end
11
+
12
+ def receivers
13
+ @receiver
14
+ end
15
+
16
+ def receivers=(receivers)
17
+ @receiver = receivers
18
+ end
19
+
20
+ def first
21
+ self.receiver.first
22
+ end
23
+
24
+ # Set the only receiver
25
+ #
26
+ def only(user)
27
+ self.receiver = [user]
28
+ end
29
+
30
+ # Replace receiver in list. It will add receiver into the list if receiver is not already in the list.
31
+ #
32
+ def replace(user)
33
+ remove(user)
34
+ add(user)
35
+ end
36
+
37
+ # Add receiver to list. It will ignore if the receiver is already in the list.
38
+ #
39
+ def add(user)
40
+ self.receiver << user unless self.receivers.detect {|r| r.email == user.email }
41
+ end
42
+
43
+ # Remove receiver from list.
44
+ #
45
+ def remove(user)
46
+ self.receiver.delete_if{ |r| r.email == user.email }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ module PayPal::AdaptivePayments
2
+ class ReceiverOptions
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :description
6
+ attr_accessor :customer_id
7
+ attr_accessor :invoice_data
8
+ attr_accessor :receiver
9
+ attr_accessor :referred_code
10
+
11
+ def set_invoice_data(value)
12
+ self.invoice_data = build_value(InvoiceData, value)
13
+ end
14
+
15
+ def set_receiver(value)
16
+ self.receiver = build_value(Receiver, value)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ module PayPal::AdaptivePayments
2
+ class Request < PayPal::Common::Request
3
+
4
+ METHODS = {
5
+ :cancel_preapproval => 'CancelPreapproval',
6
+ :convert_currency => 'ConvertCurrency',
7
+ :execute_payment => 'ExecutePayment',
8
+ :funding_plans => 'GetFundingPlans',
9
+ :get_payment_options => 'GetPaymentOptions',
10
+ :shipping_addresses => 'GetShippingAddresses',
11
+ :pay => 'Pay',
12
+ :payment_details => 'PaymentDetails',
13
+ :preapproval => 'Preapproval',
14
+ :preapproval_details => 'PreapprovalDetails',
15
+ :refund => 'Refund',
16
+ :set_payment_options => 'SetPaymentOptions'
17
+ }
18
+
19
+ ACTION_TYPES = {
20
+ :pay => 'PAY',
21
+ :create => 'CREATE',
22
+ :pay_primary => 'PAY_PRIMARY'
23
+ }
24
+
25
+ PAYMENT_TYPES = {
26
+ :goods => 'GOODS',
27
+ :service => 'SERVICE',
28
+ :personal => 'PERSONAL',
29
+ :cash_advance => 'CASHADVANCE',
30
+ :digital_goods => 'DIGITALGOODS',
31
+ :bank_managed_withdrawal => 'BANK_MANAGED_WITHDRAWAL'
32
+ }
33
+
34
+ FEE_PAYERS = {
35
+ :sender => 'SENDER',
36
+ :primary_receiver => 'PRIMARYRECEIVER',
37
+ :each_receiver => 'EACHRECEIVER',
38
+ :secondary_only => 'SECONDARYONLY'
39
+ }
40
+
41
+ def api
42
+ PayPal::AdaptivePayments::Api
43
+ end
44
+
45
+ # Returns the actual api endpoint base on method
46
+ #
47
+ def method_endpoint(method)
48
+ "#{api.api_endpoint}/#{METHODS.fetch(method, method.to_s)}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ module PayPal::AdaptivePayments
2
+ module Response
3
+ require "paypal/adaptive_payments/response/pay"
4
+ require "paypal/adaptive_payments/response/pay_error_list"
5
+ require "paypal/adaptive_payments/response/pay_error"
6
+ require "paypal/adaptive_payments/response/preapproval"
7
+ require "paypal/adaptive_payments/response/address_list"
8
+ require "paypal/adaptive_payments/response/base_address"
9
+ require "paypal/adaptive_payments/response/address"
10
+ require "paypal/adaptive_payments/response/shipping_address"
11
+ require "paypal/adaptive_payments/response/error_list"
12
+ require "paypal/adaptive_payments/response/refund_info"
13
+ require "paypal/adaptive_payments/response/refund_info_list"
14
+ require "paypal/adaptive_payments/response/refund"
15
+ require "paypal/adaptive_payments/response/base_address"
16
+
17
+ RESPONDERS = {
18
+ :pay => "Pay",
19
+ :execute_payment => "Pay",
20
+ :payment_details => "Details",
21
+ :get_payment_options => "PayOptions",
22
+ :set_payment_options => "PayOptions",
23
+ :preapproval => "Preapproval",
24
+ :preapproval_details => "Preapproval",
25
+ :cancel_preapproval => "Preapproval",
26
+ :refund => "Refund",
27
+ :shipping_addresses => "ShippingAddress"
28
+ }
29
+
30
+ def self.process(method, response)
31
+ response_class = PayPal::AdaptivePayments::Response.const_get(RESPONDERS[method])
32
+ if response.respond_to?(:body_str)
33
+ response_class.new(MultiJson.load(response.body_str))
34
+ end
35
+ # rescue
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class Address
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :address_name
6
+ attr_accessor :base_address
7
+ attr_accessor :address_id
8
+
9
+ def set_base_address(value)
10
+ self.base_address = build_value(BaseAddress, value)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class AddressList
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :address
6
+
7
+ def set_address(value)
8
+ self.address = build_value(Address, value)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class BaseAddress
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :line1
6
+ attr_accessor :line2
7
+ attr_accessor :city
8
+ attr_accessor :state
9
+ attr_accessor :postal_code
10
+ attr_accessor :country_code
11
+ attr_accessor :type
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # include PayPal::AdaptivePayments::Response
2
+
3
+ module PayPal::AdaptivePayments::Response
4
+ class Details < PayPal::AdaptivePayments::Payment
5
+ include PayPal::Common::Response
6
+
7
+ def payment_info
8
+ @payment_info ||= (payment_info_list && payment_info_list.payment_info) || []
9
+ end
10
+
11
+ def receivers
12
+ @receivers ||= payment_info.map { |pi| pi.receiver }
13
+ end
14
+
15
+ def receiver
16
+ @receiver ||= receivers.first
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class ErrorList
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :error
6
+
7
+ def set_error(value)
8
+ self.error = build_value(ErrorData, value)
9
+ end
10
+
11
+ def errors
12
+ self.error
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class Pay
3
+ include PayPal::Common::Response
4
+
5
+ attr_accessor :pay_key
6
+ attr_accessor :pay_error_list
7
+ attr_accessor :payment_exec_status
8
+ attr_accessor :default_funding_plan
9
+ attr_accessor :warning_data_list
10
+
11
+ def set_pay_error_list(value)
12
+ self.pay_error_list = build_value(PayErrorList, value)
13
+ end
14
+
15
+ def pay_errors
16
+ (self.pay_error_list && self.pay_error_list.errors) || []
17
+ end
18
+
19
+ def errors
20
+ super + pay_errors
21
+ end
22
+
23
+ def payment_url
24
+ "#{PayPal::Api.site_endpoint}?cmd=_ap-payment&paykey=#{self.pay_key}"
25
+ end
26
+
27
+ def completed?
28
+ self.payment_exec_status == 'COMPLETED'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class PayError
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :error
6
+ attr_accessor :receiver
7
+
8
+ def set_error(value)
9
+ self.error = build_value(ErrorData, value)
10
+ end
11
+
12
+ def set_receiver(value)
13
+ self.receiver = build_value(Receiver, value)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class PayErrorList
3
+ include PayPal::Common::Base
4
+
5
+ attr_accessor :pay_error
6
+
7
+ def set_pay_error(value)
8
+ self.pay_error = build_value(PayError, value)
9
+ end
10
+
11
+ def errors
12
+ self.pay_error
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ include PayPal::AdaptivePayments::Response
2
+
3
+ module PayPal::AdaptivePayments::Response
4
+ class PayOptions < PayPal::AdaptivePayments::PaymentOptions
5
+ include PayPal::Common::Response
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class Preapproval
3
+ include PayPal::Common::Response
4
+
5
+ attr_accessor :preapproval_key
6
+ attr_accessor :approved
7
+ attr_accessor :cancel_url
8
+ attr_accessor :cur_payments
9
+ attr_accessor :cur_payments_amount
10
+ attr_accessor :currency_code
11
+ attr_accessor :date_of_month
12
+ attr_accessor :day_of_week
13
+ attr_accessor :ending_date
14
+ attr_accessor :ending_date
15
+ attr_accessor :max_amount_per_payment
16
+ attr_accessor :max_number_of_payments
17
+ attr_accessor :max_number_of_payments_per_period
18
+ attr_accessor :max_total_amount_of_all_payments
19
+ attr_accessor :payment_period
20
+ attr_accessor :return_url
21
+ attr_accessor :memo
22
+ attr_accessor :ipn_notification_url
23
+ attr_accessor :sender_email
24
+ attr_accessor :starting_date
25
+ attr_accessor :pin_type
26
+ attr_accessor :address_list
27
+ attr_accessor :fees_payer
28
+ attr_accessor :require_instant_funding_source
29
+ attr_accessor :status
30
+
31
+ def set_address_list(value)
32
+ self.address_list = build_value(AddressList, value)
33
+ end
34
+
35
+ def set_ending_date(value)
36
+ self.ending_date = build_datetime(value)
37
+ end
38
+
39
+ def set_starting_date(value)
40
+ self.starting_date = build_datetime(value)
41
+ end
42
+
43
+ def preapproval_url
44
+ "#{PayPal::Api.site_endpoint}?cmd=_ap-preapproval&preapprovalkey=#{self.preapproval_key}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ module PayPal::AdaptivePayments::Response
2
+ class Refund
3
+ include PayPal::Common::Response
4
+
5
+ attr_accessor :currency_code
6
+ attr_accessor :refund_info_list
7
+
8
+ def set_refund_info_list(value)
9
+ self.refund_info_list = build_value(RefundInfoList, value)
10
+ end
11
+
12
+ def refund_infos
13
+ (self.refund_info_list && self.refund_info_list.refund_info) || []
14
+ end
15
+ end
16
+ end