pagseguro-sdk 2.6.2

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 (324) hide show
  1. checksums.yaml +7 -0
  2. data/.github/.gitignore +204 -0
  3. data/.github/ISSUE_TEMPLATE/relatorio-de-bug.md +29 -0
  4. data/.github/workflows/codacy-analysis.yml +46 -0
  5. data/.gitignore +28 -0
  6. data/.rspec +1 -0
  7. data/.travis.yml +13 -0
  8. data/CHANGELOG.md +95 -0
  9. data/CONTRIBUTING.md +39 -0
  10. data/Dockerfile +20 -0
  11. data/Gemfile +2 -0
  12. data/LICENSE-2.0.txt +177 -0
  13. data/README.md +436 -0
  14. data/Rakefile +5 -0
  15. data/docker-compose.yml +5 -0
  16. data/docs/transparent_checkout.md +201 -0
  17. data/examples/authorization/create_authorization.rb +32 -0
  18. data/examples/authorization/create_authorization_with_account.rb +56 -0
  19. data/examples/authorization/search/search_authorization_by_code.rb +29 -0
  20. data/examples/authorization/search/search_authorization_by_date.rb +35 -0
  21. data/examples/authorization/search/search_authorization_by_notification_code.rb +29 -0
  22. data/examples/authorization/search/search_authorization_by_reference.rb +31 -0
  23. data/examples/boot.rb +26 -0
  24. data/examples/checkout/create_payment_request.rb +63 -0
  25. data/examples/checkout/search/search_abandoned_transactions.rb +41 -0
  26. data/examples/checkout/search/search_transaction_by_code.rb +76 -0
  27. data/examples/checkout/search/search_transaction_by_notification_code.rb +76 -0
  28. data/examples/checkout/search/search_transaction_by_reference.rb +36 -0
  29. data/examples/checkout/search/search_transactions_by_date.rb +45 -0
  30. data/examples/create_session.rb +19 -0
  31. data/examples/direct/create_transaction_using_boleto.rb +100 -0
  32. data/examples/direct/create_transaction_using_credit_card.rb +128 -0
  33. data/examples/direct/create_transaction_using_online_debit.rb +104 -0
  34. data/examples/get_installments.rb +40 -0
  35. data/examples/preapproval/cancel_preapproval.rb +26 -0
  36. data/examples/preapproval/change_preapproval_payment.rb +50 -0
  37. data/examples/preapproval/change_preapproval_status.rb +29 -0
  38. data/examples/preapproval/charge_preapproval.rb +36 -0
  39. data/examples/preapproval/create_preapproval.rb +68 -0
  40. data/examples/preapproval/create_preapproval_auto.rb +53 -0
  41. data/examples/preapproval/create_preapproval_discount.rb +30 -0
  42. data/examples/preapproval/create_preapproval_manual.rb +58 -0
  43. data/examples/preapproval/create_preapproval_transparent.rb +41 -0
  44. data/examples/preapproval/preapproval_retry.rb +29 -0
  45. data/examples/preapproval/search/search_by_date_interval.rb +45 -0
  46. data/examples/preapproval/search/search_by_days_interval.rb +46 -0
  47. data/examples/preapproval/search/search_by_notification_code.rb +50 -0
  48. data/examples/preapproval/search/search_by_subscription_code.rb +50 -0
  49. data/examples/preapproval/search/search_subscription_payment_orders.rb +53 -0
  50. data/examples/request_transaction_cancellation.rb +19 -0
  51. data/examples/split_payment/create_authorization.rb +32 -0
  52. data/examples/split_payment/create_payment_request.rb +71 -0
  53. data/examples/split_payment/create_transaction_using_boleto.rb +118 -0
  54. data/examples/split_payment/create_transaction_using_credit_card.rb +152 -0
  55. data/lib/pagseguro-oficial.rb +1 -0
  56. data/lib/pagseguro.rb +221 -0
  57. data/lib/pagseguro/account.rb +29 -0
  58. data/lib/pagseguro/account_credentials.rb +14 -0
  59. data/lib/pagseguro/address.rb +40 -0
  60. data/lib/pagseguro/application_credentials.rb +18 -0
  61. data/lib/pagseguro/authorization.rb +61 -0
  62. data/lib/pagseguro/authorization/collection.rb +28 -0
  63. data/lib/pagseguro/authorization/request_serializer.rb +24 -0
  64. data/lib/pagseguro/authorization/response.rb +49 -0
  65. data/lib/pagseguro/authorization/response_serializer.rb +40 -0
  66. data/lib/pagseguro/authorization_request.rb +84 -0
  67. data/lib/pagseguro/authorization_request/request_serializer.rb +142 -0
  68. data/lib/pagseguro/authorization_request/response.rb +26 -0
  69. data/lib/pagseguro/authorization_request/response_serializer.rb +18 -0
  70. data/lib/pagseguro/bank.rb +8 -0
  71. data/lib/pagseguro/boleto_transaction_request.rb +8 -0
  72. data/lib/pagseguro/company.rb +41 -0
  73. data/lib/pagseguro/config.rb +34 -0
  74. data/lib/pagseguro/credit_card_transaction_request.rb +39 -0
  75. data/lib/pagseguro/creditor_fee.rb +23 -0
  76. data/lib/pagseguro/document.rb +23 -0
  77. data/lib/pagseguro/documents.rb +5 -0
  78. data/lib/pagseguro/errors.rb +57 -0
  79. data/lib/pagseguro/exceptions.rb +3 -0
  80. data/lib/pagseguro/extensions/collection_object.rb +34 -0
  81. data/lib/pagseguro/extensions/credentiable.rb +17 -0
  82. data/lib/pagseguro/extensions/ensure_type.rb +9 -0
  83. data/lib/pagseguro/extensions/mass_assignment.rb +11 -0
  84. data/lib/pagseguro/holder.rb +36 -0
  85. data/lib/pagseguro/installment.rb +57 -0
  86. data/lib/pagseguro/installment/collection.rb +25 -0
  87. data/lib/pagseguro/installment/request_serializer.rb +24 -0
  88. data/lib/pagseguro/installment/response.rb +37 -0
  89. data/lib/pagseguro/installment/response_serializer.rb +22 -0
  90. data/lib/pagseguro/item.rb +34 -0
  91. data/lib/pagseguro/items.rb +23 -0
  92. data/lib/pagseguro/manual_subscription_charger.rb +59 -0
  93. data/lib/pagseguro/manual_subscription_charger/request_serializer.rb +50 -0
  94. data/lib/pagseguro/manual_subscription_charger/response.rb +36 -0
  95. data/lib/pagseguro/manual_subscription_charger/response_serializer.rb +17 -0
  96. data/lib/pagseguro/notification.rb +11 -0
  97. data/lib/pagseguro/notification/authorization.rb +15 -0
  98. data/lib/pagseguro/notification/transaction.rb +15 -0
  99. data/lib/pagseguro/online_debit_transaction_request.rb +17 -0
  100. data/lib/pagseguro/partner.rb +20 -0
  101. data/lib/pagseguro/payment_method.rb +39 -0
  102. data/lib/pagseguro/payment_release.rb +21 -0
  103. data/lib/pagseguro/payment_releases.rb +28 -0
  104. data/lib/pagseguro/payment_request.rb +117 -0
  105. data/lib/pagseguro/payment_request/request_serializer.rb +203 -0
  106. data/lib/pagseguro/payment_request/response.rb +35 -0
  107. data/lib/pagseguro/payment_status.rb +39 -0
  108. data/lib/pagseguro/permission.rb +13 -0
  109. data/lib/pagseguro/person.rb +40 -0
  110. data/lib/pagseguro/phone.rb +20 -0
  111. data/lib/pagseguro/phones.rb +5 -0
  112. data/lib/pagseguro/receiver.rb +20 -0
  113. data/lib/pagseguro/receiver_split.rb +15 -0
  114. data/lib/pagseguro/request.rb +170 -0
  115. data/lib/pagseguro/sender.rb +53 -0
  116. data/lib/pagseguro/session.rb +34 -0
  117. data/lib/pagseguro/session/response.rb +32 -0
  118. data/lib/pagseguro/session/response_serializer.rb +18 -0
  119. data/lib/pagseguro/shipping.rb +57 -0
  120. data/lib/pagseguro/subscription.rb +132 -0
  121. data/lib/pagseguro/subscription/request_serializer.rb +129 -0
  122. data/lib/pagseguro/subscription/response.rb +49 -0
  123. data/lib/pagseguro/subscription/response_serializer.rb +62 -0
  124. data/lib/pagseguro/subscription/subscription_search.rb +135 -0
  125. data/lib/pagseguro/subscription_canceller.rb +30 -0
  126. data/lib/pagseguro/subscription_canceller/response.rb +34 -0
  127. data/lib/pagseguro/subscription_change_payment.rb +46 -0
  128. data/lib/pagseguro/subscription_change_payment/request_serializer.rb +80 -0
  129. data/lib/pagseguro/subscription_change_payment/response.rb +26 -0
  130. data/lib/pagseguro/subscription_change_status.rb +50 -0
  131. data/lib/pagseguro/subscription_change_status/request_serializer.rb +28 -0
  132. data/lib/pagseguro/subscription_change_status/response.rb +26 -0
  133. data/lib/pagseguro/subscription_discount.rb +41 -0
  134. data/lib/pagseguro/subscription_discount/request_serializer.rb +34 -0
  135. data/lib/pagseguro/subscription_discount/response.rb +34 -0
  136. data/lib/pagseguro/subscription_payment_method.rb +21 -0
  137. data/lib/pagseguro/subscription_payment_order.rb +57 -0
  138. data/lib/pagseguro/subscription_payment_order/response.rb +37 -0
  139. data/lib/pagseguro/subscription_payment_order/response_serializer.rb +51 -0
  140. data/lib/pagseguro/subscription_plan.rb +69 -0
  141. data/lib/pagseguro/subscription_plan/request_serializer.rb +81 -0
  142. data/lib/pagseguro/subscription_plan/response.rb +36 -0
  143. data/lib/pagseguro/subscription_plan/response_serializer.rb +17 -0
  144. data/lib/pagseguro/subscription_retry.rb +35 -0
  145. data/lib/pagseguro/subscription_retry/response.rb +34 -0
  146. data/lib/pagseguro/subscription_search_payment_orders.rb +131 -0
  147. data/lib/pagseguro/subscription_transaction.rb +29 -0
  148. data/lib/pagseguro/subscription_transactions.rb +5 -0
  149. data/lib/pagseguro/transaction.rb +215 -0
  150. data/lib/pagseguro/transaction/collection.rb +20 -0
  151. data/lib/pagseguro/transaction/response.rb +45 -0
  152. data/lib/pagseguro/transaction/search.rb +121 -0
  153. data/lib/pagseguro/transaction/search/search_abandoned.rb +20 -0
  154. data/lib/pagseguro/transaction/search/search_by_date.rb +16 -0
  155. data/lib/pagseguro/transaction/search/search_by_reference.rb +13 -0
  156. data/lib/pagseguro/transaction/serializer.rb +181 -0
  157. data/lib/pagseguro/transaction_cancellation.rb +37 -0
  158. data/lib/pagseguro/transaction_cancellation/request_serializer.rb +18 -0
  159. data/lib/pagseguro/transaction_cancellation/response.rb +33 -0
  160. data/lib/pagseguro/transaction_cancellation/response_serializer.rb +17 -0
  161. data/lib/pagseguro/transaction_installment.rb +11 -0
  162. data/lib/pagseguro/transaction_refund.rb +44 -0
  163. data/lib/pagseguro/transaction_refund/request_serializer.rb +24 -0
  164. data/lib/pagseguro/transaction_refund/response.rb +33 -0
  165. data/lib/pagseguro/transaction_refund/response_serializer.rb +17 -0
  166. data/lib/pagseguro/transaction_request.rb +165 -0
  167. data/lib/pagseguro/transaction_request/request_serializer.rb +311 -0
  168. data/lib/pagseguro/transaction_request/response.rb +33 -0
  169. data/lib/pagseguro/transaction_request/response_serializer.rb +117 -0
  170. data/lib/pagseguro/transaction_status.rb +14 -0
  171. data/lib/pagseguro/version.rb +3 -0
  172. data/locales/pt-BR.yml +130 -0
  173. data/pagseguro-oficial.gemspec +31 -0
  174. data/spec/fixtures/authorization/find_authorization.xml +17 -0
  175. data/spec/fixtures/authorization/search_authorization.xml +47 -0
  176. data/spec/fixtures/authorization_request/authorization_request.xml +11 -0
  177. data/spec/fixtures/authorization_request/authorization_request_with_account.xml +47 -0
  178. data/spec/fixtures/authorization_request/success.xml +4 -0
  179. data/spec/fixtures/by_date/success.xml +85 -0
  180. data/spec/fixtures/installment/success.xml +24 -0
  181. data/spec/fixtures/invalid_code.xml +7 -0
  182. data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
  183. data/spec/fixtures/manual_subscription_charger/success.xml +4 -0
  184. data/spec/fixtures/payment_request/failure.xml +7 -0
  185. data/spec/fixtures/payment_request/success.xml +5 -0
  186. data/spec/fixtures/refund/success.xml +2 -0
  187. data/spec/fixtures/session/success.xml +4 -0
  188. data/spec/fixtures/subscription/fail.xml +6 -0
  189. data/spec/fixtures/subscription/find_success.xml +28 -0
  190. data/spec/fixtures/subscription/search_success.xml +18 -0
  191. data/spec/fixtures/subscription/success.xml +4 -0
  192. data/spec/fixtures/subscription_canceller/fail.xml +6 -0
  193. data/spec/fixtures/subscription_change_payment/fail.xml +7 -0
  194. data/spec/fixtures/subscription_change_status/fail.xml +7 -0
  195. data/spec/fixtures/subscription_discount/fail.xml +6 -0
  196. data/spec/fixtures/subscription_payment_order/success.xml +18 -0
  197. data/spec/fixtures/subscription_plan/fail.xml +6 -0
  198. data/spec/fixtures/subscription_plan/success.xml +4 -0
  199. data/spec/fixtures/subscription_retry/fail.xml +7 -0
  200. data/spec/fixtures/subscription_search_payment_orders/success.xml +43 -0
  201. data/spec/fixtures/transaction_cancellation/success.xml +2 -0
  202. data/spec/fixtures/transaction_request/success.xml +58 -0
  203. data/spec/fixtures/transactions/additional.xml +53 -0
  204. data/spec/fixtures/transactions/search.xml +40 -0
  205. data/spec/fixtures/transactions/success.xml +75 -0
  206. data/spec/fixtures/transactions/without_status_and_type.xml +71 -0
  207. data/spec/pagseguro/account_credentials_spec.rb +10 -0
  208. data/spec/pagseguro/account_spec.rb +27 -0
  209. data/spec/pagseguro/address_spec.rb +17 -0
  210. data/spec/pagseguro/application_credentials_spec.rb +11 -0
  211. data/spec/pagseguro/authorization/collection_spec.rb +49 -0
  212. data/spec/pagseguro/authorization/request_serializer_spec.rb +10 -0
  213. data/spec/pagseguro/authorization/response_serializer_spec.rb +19 -0
  214. data/spec/pagseguro/authorization/response_spec.rb +90 -0
  215. data/spec/pagseguro/authorization_request/request_serializer_spec.rb +323 -0
  216. data/spec/pagseguro/authorization_request/response_serializer_spec.rb +15 -0
  217. data/spec/pagseguro/authorization_request/response_spec.rb +36 -0
  218. data/spec/pagseguro/authorization_request_spec.rb +127 -0
  219. data/spec/pagseguro/authorization_spec.rb +111 -0
  220. data/spec/pagseguro/bank_spec.rb +5 -0
  221. data/spec/pagseguro/boleto_transaction_request_spec.rb +9 -0
  222. data/spec/pagseguro/company_spec.rb +12 -0
  223. data/spec/pagseguro/config_spec.rb +5 -0
  224. data/spec/pagseguro/credit_card_transaction_request_spec.rb +36 -0
  225. data/spec/pagseguro/creditor_fee_spec.rb +10 -0
  226. data/spec/pagseguro/document_spec.rb +21 -0
  227. data/spec/pagseguro/documents_spec.rb +37 -0
  228. data/spec/pagseguro/errors_spec.rb +145 -0
  229. data/spec/pagseguro/extensions/collection_object_spec.rb +77 -0
  230. data/spec/pagseguro/features/create_session_spec.rb +52 -0
  231. data/spec/pagseguro/features/create_transaction_request_spec.rb +58 -0
  232. data/spec/pagseguro/holder_spec.rb +10 -0
  233. data/spec/pagseguro/installment/collection_spec.rb +43 -0
  234. data/spec/pagseguro/installment/request_serializer_spec.rb +16 -0
  235. data/spec/pagseguro/installment/response_serializer_spec.rb +33 -0
  236. data/spec/pagseguro/installment/response_spec.rb +56 -0
  237. data/spec/pagseguro/installment_spec.rb +50 -0
  238. data/spec/pagseguro/item_spec.rb +20 -0
  239. data/spec/pagseguro/items_spec.rb +148 -0
  240. data/spec/pagseguro/manual_subscription_charger/request_serializer_spec.rb +79 -0
  241. data/spec/pagseguro/manual_subscription_charger/response_serializer_spec.rb +10 -0
  242. data/spec/pagseguro/manual_subscription_charger/response_spec.rb +65 -0
  243. data/spec/pagseguro/manual_subscription_charger_spec.rb +68 -0
  244. data/spec/pagseguro/notification_spec.rb +6 -0
  245. data/spec/pagseguro/online_debit_transaction_request_spec.rb +18 -0
  246. data/spec/pagseguro/pagseguro_spec.rb +82 -0
  247. data/spec/pagseguro/partner_spec.rb +8 -0
  248. data/spec/pagseguro/payment_method_spec.rb +42 -0
  249. data/spec/pagseguro/payment_release_spec.rb +9 -0
  250. data/spec/pagseguro/payment_releases_spec.rb +34 -0
  251. data/spec/pagseguro/payment_request/request_serializer_spec.rb +283 -0
  252. data/spec/pagseguro/payment_request/response_spec.rb +13 -0
  253. data/spec/pagseguro/payment_request_spec.rb +148 -0
  254. data/spec/pagseguro/payment_status_spec.rb +33 -0
  255. data/spec/pagseguro/permission_spec.rb +7 -0
  256. data/spec/pagseguro/person_spec.rb +10 -0
  257. data/spec/pagseguro/phone_spec.rb +6 -0
  258. data/spec/pagseguro/phones_spec.rb +38 -0
  259. data/spec/pagseguro/receiver_spec.rb +7 -0
  260. data/spec/pagseguro/receiver_split_spec.rb +7 -0
  261. data/spec/pagseguro/request_spec.rb +114 -0
  262. data/spec/pagseguro/sender_spec.rb +25 -0
  263. data/spec/pagseguro/session/response_serializer_spec.rb +12 -0
  264. data/spec/pagseguro/session/response_spec.rb +57 -0
  265. data/spec/pagseguro/session_spec.rb +45 -0
  266. data/spec/pagseguro/shipping_spec.rb +40 -0
  267. data/spec/pagseguro/subscription/request_serializer_spec.rb +233 -0
  268. data/spec/pagseguro/subscription/response_serializer_spec.rb +46 -0
  269. data/spec/pagseguro/subscription/response_spec.rb +79 -0
  270. data/spec/pagseguro/subscription/subscription_search_spec.rb +154 -0
  271. data/spec/pagseguro/subscription_canceller/response_spec.rb +58 -0
  272. data/spec/pagseguro/subscription_canceller_spec.rb +57 -0
  273. data/spec/pagseguro/subscription_change_payment/request_serializer_spec.rb +150 -0
  274. data/spec/pagseguro/subscription_change_payment/response_spec.rb +41 -0
  275. data/spec/pagseguro/subscription_change_payment_spec.rb +60 -0
  276. data/spec/pagseguro/subscription_change_status/request_serializer_spec.rb +19 -0
  277. data/spec/pagseguro/subscription_change_status/response_spec.rb +41 -0
  278. data/spec/pagseguro/subscription_change_status_spec.rb +53 -0
  279. data/spec/pagseguro/subscription_discount/request_serializer_spec.rb +27 -0
  280. data/spec/pagseguro/subscription_discount/response_spec.rb +58 -0
  281. data/spec/pagseguro/subscription_discount_spec.rb +60 -0
  282. data/spec/pagseguro/subscription_payment_method_spec.rb +10 -0
  283. data/spec/pagseguro/subscription_payment_order/response_serializer_spec.rb +24 -0
  284. data/spec/pagseguro/subscription_payment_order/response_spec.rb +55 -0
  285. data/spec/pagseguro/subscription_payment_order_spec.rb +27 -0
  286. data/spec/pagseguro/subscription_plan/request_serializer_spec.rb +253 -0
  287. data/spec/pagseguro/subscription_plan/response_serializer_spec.rb +10 -0
  288. data/spec/pagseguro/subscription_plan/response_spec.rb +65 -0
  289. data/spec/pagseguro/subscription_plan_spec.rb +118 -0
  290. data/spec/pagseguro/subscription_retry/response_spec.rb +58 -0
  291. data/spec/pagseguro/subscription_retry_spec.rb +62 -0
  292. data/spec/pagseguro/subscription_search_payment_order_spec.rb +129 -0
  293. data/spec/pagseguro/subscription_spec.rb +137 -0
  294. data/spec/pagseguro/subscription_transaction_spec.rb +24 -0
  295. data/spec/pagseguro/subscription_transactions_spec.rb +37 -0
  296. data/spec/pagseguro/transaction/collection_spec.rb +43 -0
  297. data/spec/pagseguro/transaction/response_spec.rb +60 -0
  298. data/spec/pagseguro/transaction/search/search_abandoned_spec.rb +55 -0
  299. data/spec/pagseguro/transaction/search/search_by_date_spec.rb +28 -0
  300. data/spec/pagseguro/transaction/search/search_by_reference_spec.rb +21 -0
  301. data/spec/pagseguro/transaction/search_spec.rb +133 -0
  302. data/spec/pagseguro/transaction/serializer_spec.rb +86 -0
  303. data/spec/pagseguro/transaction_cancellation/request_serializer_spec.rb +13 -0
  304. data/spec/pagseguro/transaction_cancellation/response_serializer_spec.rb +9 -0
  305. data/spec/pagseguro/transaction_cancellation/response_spec.rb +45 -0
  306. data/spec/pagseguro/transaction_cancellation_spec.rb +60 -0
  307. data/spec/pagseguro/transaction_installment_spec.rb +6 -0
  308. data/spec/pagseguro/transaction_refund/request_serializer_spec.rb +15 -0
  309. data/spec/pagseguro/transaction_refund/response_serializer_spec.rb +12 -0
  310. data/spec/pagseguro/transaction_refund/response_spec.rb +39 -0
  311. data/spec/pagseguro/transaction_refund_spec.rb +71 -0
  312. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +677 -0
  313. data/spec/pagseguro/transaction_request/response_serializer_spec.rb +52 -0
  314. data/spec/pagseguro/transaction_request/response_spec.rb +63 -0
  315. data/spec/pagseguro/transaction_request_spec.rb +156 -0
  316. data/spec/pagseguro/transaction_spec.rb +265 -0
  317. data/spec/pagseguro/transaction_status_spec.rb +7 -0
  318. data/spec/spec_helper.rb +35 -0
  319. data/spec/support/ensure_type_macro.rb +35 -0
  320. data/spec/support/helpers.rb +14 -0
  321. data/spec/support/mass_assignment_macro.rb +11 -0
  322. data/spec/support/shared_examples_for_configuration.rb +10 -0
  323. data/transaction/transaction_refund.rb +25 -0
  324. metadata +641 -0
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::AuthorizationRequest::ResponseSerializer do
4
+ context "when payment request is created" do
5
+ let(:source) { File.read("./spec/fixtures/authorization_request/success.xml") }
6
+ let(:xml) { Nokogiri::XML(source) }
7
+ let(:serializer) { described_class.new(xml.css("authorizationRequest").first) }
8
+
9
+ subject(:data) { serializer.serialize }
10
+
11
+ it { expect(data[:code]).to eql("D8DD848AC9C98D9EE44C5FB3A1E53913") }
12
+ it { expect(data[:date]).to eql(Time.parse("2011-02-25T11:40:50.000-03:00")) }
13
+ end
14
+ end
15
+
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::AuthorizationRequest::Response do
4
+ let(:http_response) do
5
+ response = double(body: "", code: 200, content_type: "text/xml", "[]" => nil)
6
+ Aitch::Response.new({xml_parser: Aitch::XMLParser}, response)
7
+ end
8
+
9
+ subject { described_class.new(http_response) }
10
+
11
+ describe "#serialize" do
12
+ context "when request succeeds" do
13
+ let(:serializer) { double(:serializer) }
14
+ let(:serialized_data) { double(:serialized_data) }
15
+
16
+ it "returns a hash with serialized response data" do
17
+ expect(PagSeguro::AuthorizationRequest::ResponseSerializer).to receive(:new)
18
+ .and_return(serializer)
19
+ expect(serializer).to receive(:serialize).and_return(serialized_data)
20
+
21
+ expect(subject.serialize).to eq(serialized_data)
22
+ end
23
+ end
24
+
25
+ context "when request fails" do
26
+ before do
27
+ expect(http_response).to receive(:success?).and_return(false)
28
+ end
29
+
30
+ it "returns a hash with an errors object" do
31
+ expect(subject.serialize[:errors]).to be_a(PagSeguro::Errors)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::AuthorizationRequest do
4
+ it_assigns_attribute :permissions
5
+ it_assigns_attribute :reference
6
+ it_assigns_attribute :notification_url
7
+ it_assigns_attribute :redirect_url
8
+
9
+ describe "#create" do
10
+ let(:request) { double(:request) }
11
+ let(:response) { double(:response) }
12
+ let(:credentials) { PagSeguro::ApplicationCredentials.new('app123', 'key123') }
13
+
14
+ before do
15
+ expect(PagSeguro::Request).to receive(:post_xml)
16
+ .with('authorizations/request', 'v2', credentials, data)
17
+ .and_return(request)
18
+
19
+ expect(PagSeguro::AuthorizationRequest::Response).to receive(:new)
20
+ .with(request)
21
+ .and_return(response)
22
+
23
+ expect(response).to receive(:serialize).and_return(serialized_data)
24
+ end
25
+
26
+ context "when an account is not given" do
27
+ let(:options) do
28
+ {
29
+ credentials: credentials,
30
+ notification_url: 'http://seusite.com.br/notification',
31
+ redirect_url: 'http://seusite.com.br/redirect',
32
+ permissions: [:checkouts, :searches, :notifications],
33
+ reference: '123'
34
+ }
35
+ end
36
+
37
+ let(:data) { File.read('./spec/fixtures/authorization_request/authorization_request.xml') }
38
+
39
+ subject { described_class.new(options) }
40
+
41
+ context "when request succeeds" do
42
+ let(:serialized_data) { {code: "123"} }
43
+
44
+ it "creates a transaction request" do
45
+ expect(response).to receive(:success?).and_return(true)
46
+
47
+ expect(subject.create).to be_truthy
48
+ expect(subject.code).to eq(serialized_data[:code])
49
+ end
50
+ end
51
+
52
+
53
+ context "when request fails" do
54
+ let(:serialized_data) { {errors: PagSeguro::Errors.new} }
55
+
56
+ it "does not create a transaction request" do
57
+ expect(response).to receive(:success?).and_return(false)
58
+
59
+ expect(subject.create).to be_falsey
60
+ expect(subject.code).to be_nil
61
+ end
62
+ end
63
+ end
64
+
65
+ context "when an account is given" do
66
+ let(:options) do
67
+ {
68
+ credentials: credentials,
69
+ permissions: [:checkouts, :searches, :notifications],
70
+ notification_url: 'http://seusite.com.br/notification',
71
+ redirect_url: 'http://seusite.com.br/redirect',
72
+ reference: '123',
73
+ account: {
74
+ email: 'usuario@seusite.com.br',
75
+ type: 'SELLER',
76
+ person: {
77
+ name: 'Antonio Carlos',
78
+ birth_date: '05/02/1982',
79
+ address: {
80
+ postal_code: 01452002,
81
+ street: 'Av. Brig. Faria Lima',
82
+ number: 1384,
83
+ complement: '5o andar',
84
+ district: 'Jardim Paulistano',
85
+ city: 'Sao Paulo',
86
+ state: 'SP',
87
+ country: 'BRA'
88
+ },
89
+ documents: [{type: 'CPF', value: 99988877766}],
90
+ phones: [
91
+ {type: 'HOME', area_code: 11, number: 30302323},
92
+ {type: 'MOBILE', area_code: 11, number: 976302323},
93
+ ]
94
+ }
95
+ }
96
+ }
97
+ end
98
+ let(:data) { File.read('./spec/fixtures/authorization_request/authorization_request_with_account.xml') }
99
+ let(:request) { double(:request) }
100
+ let(:response) { double(:response) }
101
+
102
+ subject { described_class.new(options) }
103
+
104
+ context "when request succeeds" do
105
+ let(:serialized_data) { {code: "123"} }
106
+
107
+ it "creates a transaction request send xml" do
108
+ expect(response).to receive(:success?).and_return(true)
109
+
110
+ expect(subject.create).to be_truthy
111
+ expect(subject.code).to eq(serialized_data[:code])
112
+ end
113
+ end
114
+
115
+ context "when request fails" do
116
+ let(:serialized_data) { {errors: PagSeguro::Errors.new} }
117
+
118
+ it "does not create a transaction request" do
119
+ expect(response).to receive(:success?).and_return(false)
120
+
121
+ expect(subject.create).to be_falsey
122
+ expect(subject.code).to be_nil
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::Authorization do
4
+ let(:code) { "1234" }
5
+ let(:notification_code) { "4321" }
6
+ let(:crendentials) { double(:crendentials) }
7
+ let(:options) { { crendentials: crendentials} }
8
+ let(:request) { double(:request) }
9
+ let(:response) { double(:response) }
10
+ let(:serialized_data) { { code: 1234 } }
11
+ let(:authorization) { double(:authorization) }
12
+ let(:collection) { double(:collection) }
13
+
14
+ describe ".find_by_notification_code" do
15
+ before do
16
+ expect(PagSeguro::Request).to receive(:get)
17
+ .with("authorizations/notifications/4321", 'v2', options)
18
+ .and_return(request)
19
+ expect(PagSeguro::Authorization).to receive(:new)
20
+ .and_return(authorization)
21
+ expect(PagSeguro::Authorization::Response).to receive(:new)
22
+ .with(request, authorization)
23
+ .and_return(response)
24
+ expect(response).to receive(:serialize)
25
+ end
26
+
27
+ it "finds authorization by the given notificationCode" do
28
+ expect(PagSeguro::Authorization.find_by_notification_code(notification_code, options))
29
+ .to eq(authorization)
30
+ end
31
+ end
32
+
33
+ describe ".find_by_code" do
34
+ before do
35
+ expect(PagSeguro::Request).to receive(:get)
36
+ .with("authorizations/1234", 'v2', options)
37
+ .and_return(request)
38
+ expect(PagSeguro::Authorization).to receive(:new)
39
+ .and_return(authorization)
40
+ expect(PagSeguro::Authorization::Response).to receive(:new)
41
+ .with(request, authorization)
42
+ .and_return(response)
43
+ expect(response).to receive(:serialize)
44
+ end
45
+
46
+ it "finds authorization by the given notificationCode" do
47
+ expect(PagSeguro::Authorization.find_by_code(code, options)).to eq(authorization)
48
+ end
49
+ end
50
+
51
+ describe "find_by" do
52
+ before do
53
+ allow(PagSeguro::Authorization::Collection).to receive(:new)
54
+ .and_return(collection)
55
+ allow(PagSeguro::Authorization::Response).to receive(:new)
56
+ .with(request, collection)
57
+ .and_return(response)
58
+ allow(response).to receive(:serialize_collection)
59
+ end
60
+
61
+ context "with reference" do
62
+ let(:reference) { 'REF1111' }
63
+
64
+ it 'finds authorizations' do
65
+ expect(PagSeguro::Request).to receive(:get)
66
+ .with("authorizations", 'v2', { reference: 'REF1111' })
67
+ .and_return(request)
68
+
69
+ PagSeguro::Authorization.find_by(reference: 'REF1111')
70
+ end
71
+ end
72
+
73
+ context "with initial_date" do
74
+ let(:initial_date) { Time.new(2015, 11, 1, 12, 0) }
75
+
76
+ it 'finds authorizations' do
77
+ expect(PagSeguro::Request).to receive(:get)
78
+ .with("authorizations", 'v2', { initialDate: initial_date.xmlschema })
79
+ .and_return(request)
80
+
81
+ PagSeguro::Authorization.find_by(initial_date: initial_date)
82
+ end
83
+ end
84
+
85
+ context "with final_date" do
86
+ let(:final_date) { Time.new(2015, 11, 1, 12, 0) }
87
+
88
+ it 'finds authorizations' do
89
+ expect(PagSeguro::Request).to receive(:get)
90
+ .with("authorizations", 'v2', { finalDate: final_date.xmlschema })
91
+ .and_return(request)
92
+
93
+ PagSeguro::Authorization.find_by(final_date: final_date)
94
+ end
95
+ end
96
+
97
+ context "with credentials" do
98
+ let(:credentials) do
99
+ PagSeguro::ApplicationCredentials.new('APP_ID', 'APP_KEY')
100
+ end
101
+
102
+ it 'passes' do
103
+ expect(PagSeguro::Request).to receive(:get)
104
+ .with("authorizations", 'v2', { credentials: credentials })
105
+ .and_return(request)
106
+
107
+ PagSeguro::Authorization.find_by(credentials: credentials)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Bank do
4
+ it_assigns_attribute :name
5
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::BoletoTransactionRequest do
4
+ describe "#payment_method" do
5
+ it "is boleto" do
6
+ expect(subject.payment_method).to eq("boleto")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PagSeguro::Company do
4
+ it_assigns_attribute :name
5
+ it_assigns_attribute :display_name
6
+ it_assigns_attribute :website_url
7
+
8
+ it_ensures_type PagSeguro::Address, :address
9
+ it_ensures_type PagSeguro::Partner, :partner
10
+ it_ensures_collection_type PagSeguro::Document, :documents, [{type: 'CPF', value: 12312312312}]
11
+ it_ensures_collection_type PagSeguro::Phone, :phones, [{type: 'HOME', area_code: 11, number: 12312312312}]
12
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Config do
4
+ it_behaves_like "a configuration"
5
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::CreditCardTransactionRequest do
4
+ it_assigns_attribute :credit_card_token
5
+
6
+ it_ensures_type PagSeguro::TransactionInstallment, :installment
7
+ it_ensures_type PagSeguro::Holder, :holder
8
+ it_ensures_type PagSeguro::Address, :billing_address
9
+
10
+ describe "#payment_method" do
11
+ it "is credit_card" do
12
+ expect(subject.payment_method).to eq("creditCard")
13
+ end
14
+ end
15
+
16
+ it "sets the transaction installment" do
17
+ installment = PagSeguro::TransactionInstallment.new
18
+ payment = described_class.new(installment: installment)
19
+
20
+ expect(payment.installment).to eql(installment)
21
+ end
22
+
23
+ it "sets the holder" do
24
+ holder = PagSeguro::Holder.new
25
+ payment = described_class.new(holder: holder)
26
+
27
+ expect(payment.holder).to eql(holder)
28
+ end
29
+
30
+ it "sets the billing address" do
31
+ address = PagSeguro::Address.new
32
+ payment = described_class.new(billing_address: address)
33
+
34
+ expect(payment.billing_address).to eql(address)
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::CreditorFee do
4
+ it_assigns_attribute :intermediation_rate_amount
5
+ it_assigns_attribute :intermediation_fee_amount
6
+ it_assigns_attribute :installment_fee_amount
7
+ it_assigns_attribute :operational_fee_amount
8
+ it_assigns_attribute :commission_fee_amount
9
+ it_assigns_attribute :efrete
10
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Document do
4
+ it_assigns_attribute :type
5
+ it_assigns_attribute :value
6
+
7
+ it '==' do
8
+ document = PagSeguro::Document.new(type: 'TYPE', value: 'VALUE')
9
+ expect(document).to eq PagSeguro::Document.new(type: 'TYPE', value: 'VALUE')
10
+ end
11
+
12
+ context 'helpers' do
13
+ it 'cpf?' do
14
+ expect{ subject.type = 'CPF' }.to change{ subject.cpf? }.to true
15
+ end
16
+
17
+ it 'cnpj?' do
18
+ expect{ subject.type = 'CNPJ' }.to change{ subject.cnpj? }.to true
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PagSeguro::Documents do
4
+ [
5
+ :size,
6
+ :clear,
7
+ :empty?,
8
+ :any?,
9
+ :each,
10
+ :map
11
+ ].each do |method|
12
+ it { is_expected.to respond_to(method) }
13
+ end
14
+
15
+ it 'should initialize empty' do
16
+ expect(subject).to be_empty
17
+ end
18
+
19
+ context 'adding a new document' do
20
+ let(:document) { { type: 'CPF', value: 11122233344 } }
21
+
22
+ it "shouldn't add the same document" do
23
+ subject << document
24
+ expect{ subject << document }.to_not change{ subject.size }
25
+ end
26
+
27
+ context 'ensures type the new document' do
28
+ it 'can be a hash' do
29
+ expect{ subject << document }.to change{ subject.size }.to(1)
30
+ end
31
+
32
+ it 'can be a PagSeguro::Document' do
33
+ expect{ subject << PagSeguro::Document.new(type: 'CPF', value: 11122233344) }.to change{ subject.size }.to(1)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,145 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe PagSeguro::Errors do
5
+ let(:response) { double }
6
+ let(:http_response) do
7
+ double(
8
+ :http_response,
9
+ error?: true,
10
+ error: Aitch::UnauthorizedError
11
+ )
12
+ end
13
+
14
+ context "when have no response" do
15
+ it "returns errors" do
16
+ errors = PagSeguro::Errors.new
17
+ expect(errors).to be_empty
18
+ end
19
+ end
20
+
21
+ context "when unauthorized" do
22
+ subject(:errors) { PagSeguro::Errors.new(response) }
23
+
24
+ before do
25
+ allow(response).to receive_messages(
26
+ error?: true,
27
+ error: Aitch::UnauthorizedError
28
+ )
29
+ errors.add(http_response)
30
+ end
31
+
32
+ it { expect(errors).not_to be_empty }
33
+ it { expect(errors).to include(I18n.t("pagseguro.errors.unauthorized")) }
34
+ end
35
+
36
+ context "when not found" do
37
+ subject(:errors) { PagSeguro::Errors.new(response) }
38
+
39
+ before do
40
+ allow(response).to receive_messages(
41
+ error?: true,
42
+ error: Aitch::NotFoundError
43
+ )
44
+ errors.add(http_response)
45
+ end
46
+
47
+ it { expect(errors).not_to be_empty }
48
+ it { expect(errors).to include(I18n.t("pagseguro.errors.not_found")) }
49
+ end
50
+
51
+ context 'when forbidden' do
52
+ subject(:errors) { PagSeguro::Errors.new(response) }
53
+
54
+ before do
55
+ allow(response).to receive_messages(
56
+ error?: true,
57
+ error: Aitch::ForbiddenError
58
+ )
59
+ errors.add(http_response)
60
+ end
61
+
62
+ it { expect(errors).not_to be_empty }
63
+ it { expect(errors).to include(I18n.t("pagseguro.errors.forbidden")) }
64
+ end
65
+
66
+ context "when message can't be translated" do
67
+ let(:error) {
68
+ <<-XML
69
+ <errors>
70
+ <error>
71
+ <code>1234</code>
72
+ <message>Sample message</message>
73
+ </error>
74
+ </errors>
75
+ XML
76
+ }
77
+
78
+ let(:xml) { Nokogiri::XML(error) }
79
+ subject(:errors) { PagSeguro::Errors.new(response) }
80
+
81
+ before do
82
+ allow(response).to receive_messages(
83
+ data: xml,
84
+ error?: true,
85
+ error: Aitch::BadRequestError
86
+ )
87
+ end
88
+
89
+ it { expect(errors).to include("Sample message") }
90
+ end
91
+
92
+ context "when message can be translated" do
93
+ let(:error) {
94
+ <<-XML
95
+ <errors>
96
+ <error>
97
+ <code>10001</code>
98
+ <message>Sample message</message>
99
+ </error>
100
+ </errors>
101
+ XML
102
+ }
103
+
104
+ let(:xml) { Nokogiri::XML(error) }
105
+ subject(:errors) { PagSeguro::Errors.new(response) }
106
+
107
+ before do
108
+ allow(response).to receive_messages(
109
+ data: xml,
110
+ error?: true,
111
+ error: Aitch::BadRequestError
112
+ )
113
+ end
114
+
115
+ it { expect(errors).to include("O parâmetro email deve ser informado.") }
116
+ end
117
+
118
+ context "when returning 404 status" do
119
+ let(:error) {
120
+ <<-XML
121
+ <?xml version="1.0" encoding="UTF-8"?>
122
+ <errors>
123
+ <error>
124
+ <code>Malformed request XML: {0}.</code>
125
+ <message>Malformed request XML: XML document structures must start and end within the same entity..</message>
126
+ </error>
127
+ </errors>
128
+ XML
129
+ }
130
+
131
+ let(:xml) { Nokogiri::XML(error) }
132
+ subject(:errors) { PagSeguro::Errors.new(response) }
133
+
134
+ before do
135
+ allow(response).to receive_messages(
136
+ data: xml,
137
+ error?: true,
138
+ error: Aitch::BadRequestError
139
+ )
140
+ errors.add(http_response)
141
+ end
142
+
143
+ it { expect(errors).to include("Malformed request XML: XML document structures must start and end within the same entity..") }
144
+ end
145
+ end