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,86 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe PagSeguro::Transaction::Serializer do
5
+ context "for existing transactions" do
6
+ let(:source) { File.read("./spec/fixtures/transactions/success.xml") }
7
+ let(:xml) { Nokogiri::XML(source) }
8
+ let(:serializer) { described_class.new(xml.css("transaction").first) }
9
+ subject(:data) { serializer.serialize }
10
+
11
+ it { expect(data).to include(created_at: Time.parse("2013-05-01T01:40:27.000-03:00")) }
12
+ it { expect(data).to include(updated_at: Time.parse("2013-05-01T01:41:20.000-03:00")) }
13
+ it { expect(data).to include(code: "667A3914-4F9F-4705-0EB6-CA6FA0DF8A19") }
14
+ it { expect(data).to include(reference: "REF1234") }
15
+ it { expect(data).to include(type_id: "1") }
16
+ it { expect(data).to include(status: "1") }
17
+ it { expect(data).to include(payment_method: {type_id: "2", code: "202"}) }
18
+ it { expect(data).to include(payment_link: "https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml?code=667D39144F9F47059FB6CA6FA0DF8A20") }
19
+ it { expect(data).to include(gross_amount: BigDecimal("459.50")) }
20
+ it { expect(data).to include(discount_amount: BigDecimal("0.00")) }
21
+ it { expect(data).to include(net_amount: BigDecimal("445.77")) }
22
+ it { expect(data).to include(extra_amount: BigDecimal("0.00")) }
23
+ it { expect(data).to include(installments: 1) }
24
+
25
+ it { expect(data.keys).not_to include(:cancellation_source) }
26
+ it { expect(data.keys).not_to include(:escrow_end_date) }
27
+
28
+ it { expect(data[:creditor_fees]).to include(intermediation_rate_amount: BigDecimal("0.40")) }
29
+ it { expect(data[:creditor_fees]).to include(intermediation_fee_amount: BigDecimal("1644.80")) }
30
+ it { expect(data[:creditor_fees]).to include(installment_fee_amount: BigDecimal("0.00")) }
31
+ it { expect(data[:creditor_fees]).to include(operational_fee_amount: BigDecimal("0.00")) }
32
+ it { expect(data[:creditor_fees]).to include(commission_fee_amount: BigDecimal("1.98")) }
33
+ it { expect(data[:creditor_fees]).to include(efrete: BigDecimal("1.98")) }
34
+
35
+ it { expect(data[:payment_releases].size).to eq(1) }
36
+ it { expect(data[:payment_releases].first).to include(installment: "1") }
37
+ it { expect(data[:payment_releases].first).to include(total_amount: BigDecimal("202.92")) }
38
+ it { expect(data[:payment_releases].first).to include(release_amount: BigDecimal("202.92")) }
39
+ it { expect(data[:payment_releases].first).to include(status: "OPENED") }
40
+ it { expect(data[:payment_releases].first).to include(release_date: Time.parse("2015-03-25T16:14:23-03:00")) }
41
+
42
+ it { expect(data[:items].size).to eq(1) }
43
+ it { expect(data[:items].first).to include(id: "1234") }
44
+ it { expect(data[:items].first).to include(description: "Some product") }
45
+ it { expect(data[:items].first).to include(quantity: 1) }
46
+ it { expect(data[:items].first).to include(amount: BigDecimal("459.50")) }
47
+
48
+ it { expect(data[:sender]).to include(name: "JOHN DOE") }
49
+ it { expect(data[:sender]).to include(email: "john@example.com") }
50
+ it { expect(data[:sender][:phone]).to include(area_code: "11") }
51
+ it { expect(data[:sender][:phone]).to include(number: "12345678") }
52
+ it { expect(data[:sender][:document]).to include(type: "CPF") }
53
+ it { expect(data[:sender][:document]).to include(value: "65647162142") }
54
+
55
+ it { expect(data[:shipping]).to include(type_id: "2") }
56
+
57
+ it { expect(data[:shipping][:address]).to include(street: "AV. BRIG. FARIA LIMA") }
58
+ it { expect(data[:shipping][:address]).to include(number: "1384") }
59
+ it { expect(data[:shipping][:address]).to include(complement: "5 ANDAR") }
60
+ it { expect(data[:shipping][:address]).to include(district: "JARDIM PAULISTANO") }
61
+ it { expect(data[:shipping][:address]).to include(city: "SAO PAULO") }
62
+ it { expect(data[:shipping][:address]).to include(state: "SP") }
63
+ it { expect(data[:shipping][:address]).to include(country: "BRA") }
64
+ it { expect(data[:shipping][:address]).to include(postal_code: "01452002") }
65
+ end
66
+
67
+ context "additional nodes" do
68
+ let(:source) { File.read("./spec/fixtures/transactions/additional.xml") }
69
+ let(:xml) { Nokogiri::XML(source) }
70
+ let(:serializer) { described_class.new(xml) }
71
+ subject(:data) { serializer.serialize }
72
+
73
+ it { expect(data).to include(cancellation_source: "PagSeguro") }
74
+ it { expect(data).to include(escrow_end_date: Time.parse("2013-06-01T01:41:20.000-03:00")) }
75
+ end
76
+
77
+ context "transaction without status and type" do
78
+ let(:source) { File.read("./spec/fixtures/transactions/without_status_and_type.xml") }
79
+ let(:xml) { Nokogiri::XML(source) }
80
+ let(:serializer) { described_class.new(xml) }
81
+ let(:data) { serializer.serialize }
82
+
83
+ it { expect(data[:status]).to be_nil }
84
+ it { expect(data[:type]).to be_nil }
85
+ end
86
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionCancellation::RequestSerializer do
4
+ subject do
5
+ PagSeguro::TransactionCancellation::RequestSerializer.new(cancellation)
6
+ end
7
+
8
+ let(:cancellation) do
9
+ PagSeguro::TransactionCancellation.new transaction_code: "1234"
10
+ end
11
+
12
+ it { expect(subject.to_params).to include(transactionCode: "1234") }
13
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionCancellation::ResponseSerializer do
4
+ let(:raw_xml) { File.read("./spec/fixtures/transaction_cancellation/success.xml") }
5
+ let(:xml) { Nokogiri::XML(raw_xml) }
6
+ subject { PagSeguro::TransactionCancellation::ResponseSerializer.new(xml) }
7
+
8
+ it { expect(subject.serialize).to include(result: "OK") }
9
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionCancellation::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
+ let(:cancellation) { PagSeguro::TransactionCancellation.new }
9
+
10
+ subject { PagSeguro::TransactionCancellation::Response.new(http_response, cancellation) }
11
+
12
+ describe "#serialize" do
13
+ context "when request succeeds" do
14
+ let(:raw_xml) { File.read("./spec/fixtures/transaction_cancellation/success.xml") }
15
+
16
+ it "returns PagSeguro::TransactionCancellation instance" do
17
+ expect(subject.serialize).to be_a(PagSeguro::TransactionCancellation)
18
+ end
19
+
20
+ it "not change cancellation errors" do
21
+ expect { subject.serialize }.not_to change { cancellation.errors.empty? }
22
+ end
23
+ end
24
+
25
+ context "when request fails" do
26
+ before do
27
+ allow(http_response).to receive_messages(
28
+ success?: false,
29
+ error?: true,
30
+ error: Aitch::BadRequestError,
31
+ body: raw_xml
32
+ )
33
+ end
34
+ let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
35
+
36
+ it "returns PagSeguro::TransactionCancellation instance" do
37
+ expect(subject.serialize).to be_a(PagSeguro::TransactionCancellation)
38
+ end
39
+
40
+ it "change cancellation errors" do
41
+ expect { subject.serialize }.to change { cancellation.errors.empty? }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionCancellation do
4
+ let(:xml_parsed) { Nokogiri::XML(raw_xml) }
5
+
6
+ it_assigns_attribute :transaction_code
7
+
8
+ describe "#register" do
9
+ subject { PagSeguro::TransactionCancellation.new }
10
+ let :http_request do
11
+ double(:ResponseRequest, success?: true, unauthorized?: false, bad_request?: false, data: xml_parsed, body: raw_xml, :xml? => true)
12
+ end
13
+
14
+ before do
15
+ allow(PagSeguro::Request).to receive(:post)
16
+ .with("transactions/cancels", "v2", {})
17
+ .and_return(http_request)
18
+ end
19
+
20
+ context "when request succeds" do
21
+ let(:raw_xml) { File.read("./spec/fixtures/transaction_cancellation/success.xml") }
22
+
23
+ it "returns a PagSeguro::TransactionCancellation" do
24
+ expect(subject.register).to be_a_kind_of PagSeguro::TransactionCancellation
25
+ end
26
+
27
+ it "does not add errors" do
28
+ expect { subject.register }.not_to change { subject.errors.empty? }
29
+ end
30
+
31
+ it "updates attributes" do
32
+ expect { subject.register }.to change { subject.result }
33
+ end
34
+ end
35
+
36
+ context "when request fails" do
37
+ before do
38
+ allow(http_request).to receive_messages(
39
+ success?: false,
40
+ error?: true,
41
+ error: Aitch::BadRequestError
42
+ )
43
+ end
44
+
45
+ let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
46
+
47
+ it "adds errors" do
48
+ expect { subject.register }.to change { subject.errors.empty? }
49
+ end
50
+ end
51
+ end
52
+
53
+ it '#update_attributes' do
54
+ cancellation = PagSeguro::TransactionCancellation.new
55
+
56
+ expect(cancellation).to receive(:result=).with("OK")
57
+
58
+ cancellation.update_attributes(result: "OK")
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionInstallment do
4
+ it_assigns_attribute :value
5
+ it_assigns_attribute :quantity
6
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionRefund::RequestSerializer do
4
+ subject(:serializer) { PagSeguro::TransactionRefund::RequestSerializer.new(refund) }
5
+
6
+ let(:refund) do
7
+ PagSeguro::TransactionRefund.new transaction_code: "1234",
8
+ value: "100.50"
9
+ end
10
+
11
+ let(:params) { serializer.to_params }
12
+
13
+ it { expect(params).to include(transactionCode: "1234") }
14
+ it { expect(params).to include(refundValue: "100.50") }
15
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionRefund::ResponseSerializer do
4
+ context "for existing refund response" do
5
+ let(:source) { File.read("./spec/fixtures/refund/success.xml") }
6
+ let(:xml) { Nokogiri::XML(source) }
7
+ let(:serializer) { described_class.new(xml) }
8
+ subject(:data) { serializer.serialize }
9
+
10
+ it { expect(data).to include(result: "OK") }
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionRefund::Response do
4
+ let(:refund) do
5
+ PagSeguro::TransactionRefund.new
6
+ end
7
+
8
+ subject { PagSeguro::TransactionRefund::Response.new(http_response, refund) }
9
+
10
+ context '#success?' do
11
+ let(:http_response) do
12
+ double(:HttpResponse, xml?: true)
13
+ end
14
+
15
+ it 'delegate to response' do
16
+ allow(http_response).to receive(:success?).and_return(true)
17
+ expect(subject).to be_success
18
+
19
+ allow(http_response).to receive(:success?).and_return(false)
20
+ expect(subject).not_to be_success
21
+ end
22
+ end
23
+
24
+ context '#serialize' do
25
+ let(:http_response) do
26
+ double(:HttpResponse, body: raw_xml, success?: true, xml?: true, unauthorized?: false, bad_request?: false)
27
+ end
28
+
29
+ let(:raw_xml) { File.read("./spec/fixtures/refund/success.xml") }
30
+
31
+ it 'return refund instance' do
32
+ expect(subject.serialize).to eq refund
33
+ end
34
+
35
+ it 'change result' do
36
+ expect { subject.serialize }.to change { refund.result }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionRefund do
4
+ let(:xml_parsed) { Nokogiri::XML(raw_xml) }
5
+
6
+ it_assigns_attribute :transaction_code
7
+ it_assigns_attribute :value
8
+
9
+ it "errors must be a instante of PagSeguro::Errors" do
10
+ expect(subject.errors).to be_a(PagSeguro::Errors)
11
+ end
12
+
13
+ describe "#register" do
14
+ let(:refund) { PagSeguro::TransactionRefund.new }
15
+
16
+ context 'a correct response' do
17
+ before { FakeWeb.register_uri :any, %r[.*?], body: raw_xml }
18
+
19
+ let(:raw_xml) { File.read("./spec/fixtures/refund/success.xml") }
20
+
21
+ let :response_request do
22
+ double(:ResponseRequest, success?: true, unauthorized?: false, bad_request?: false, data: xml_parsed, body: raw_xml, :xml? => true)
23
+ end
24
+
25
+ it "performs request" do
26
+ expect(PagSeguro::Request).to receive(:post)
27
+ .with("transactions/refunds", "v2", {})
28
+ .and_return(response_request)
29
+
30
+ refund.register
31
+ end
32
+
33
+ it "returns a PagSeguro::TransactionRefund" do
34
+ expect(refund.register).to be_a(PagSeguro::TransactionRefund)
35
+ end
36
+ end
37
+
38
+ context "a failure response" do
39
+ before do
40
+ allow(PagSeguro::Request).to receive(:post)
41
+ .and_return(response_request)
42
+ end
43
+
44
+ let(:raw_xml) { File.read("./spec/fixtures/invalid_code.xml") }
45
+
46
+ let :response_request do
47
+ double(
48
+ :ResponseRequest,
49
+ success?: false,
50
+ error?: true,
51
+ error: Aitch::ForbiddenError,
52
+ xml?: true,
53
+ data: xml_parsed,
54
+ body: raw_xml
55
+ )
56
+ end
57
+
58
+ it "returns a PagSeguro::TransactionRefund with errors" do
59
+ expect(refund.register.errors).not_to be_empty
60
+ end
61
+ end
62
+ end
63
+
64
+ it '#update_attributes' do
65
+ refund = PagSeguro::TransactionRefund.new
66
+
67
+ expect(refund).to receive(:result=).with("OK")
68
+
69
+ refund.update_attributes(result: "OK")
70
+ end
71
+ end
@@ -0,0 +1,677 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::TransactionRequest::RequestSerializer do
4
+ let(:transaction_request) { PagSeguro::BoletoTransactionRequest.new }
5
+
6
+ subject { described_class.new(transaction_request) }
7
+
8
+ context '#to_xml_params' do
9
+ let(:xml) { subject.to_xml_params }
10
+
11
+ it 'should serializer receivers' do
12
+ transaction_request.receivers = [
13
+ {
14
+ public_key: 'PUB1234ABC',
15
+ split: {
16
+ amount: 10,
17
+ fee_percent: 11,
18
+ rate_percent: 12
19
+ }
20
+ }
21
+ ]
22
+
23
+ expect(xml).to match %r[
24
+ <payment>
25
+ .*<receivers>
26
+ .*<receiver>
27
+ .*<publicKey>PUB1234ABC</publicKey>
28
+ .*<split>
29
+ .*<amount>10.00</amount>
30
+ .*<ratePercent>12.00</ratePercent>
31
+ .*<feePercent>11.00</feePercent>
32
+ ]xm
33
+ end
34
+
35
+ it 'should serializer mode' do
36
+ transaction_request.payment_mode = 'default'
37
+
38
+ expect(xml).to match %r[<payment>.*<mode>default</mode>]m
39
+ end
40
+
41
+ it 'should serializer method' do
42
+ allow(transaction_request).to receive(:payment_method).and_return('creditCard')
43
+
44
+ expect(xml).to match %r[<payment>.*<method>creditCard</method>]m
45
+ end
46
+
47
+ context "should serializer sender's" do
48
+ context 'when there is only the name' do
49
+ before do
50
+ transaction_request.sender = { name: 'Alice' }
51
+ end
52
+
53
+ it 'should render only the name' do
54
+ expect(xml).to match %r[
55
+ <payment>
56
+ .*<sender>
57
+ .*<name>Alice
58
+ ]xm
59
+ end
60
+ end
61
+
62
+ context 'when there is only cpf' do
63
+ before do
64
+ transaction_request.sender = { document: PagSeguro::Document.new(type: 'CPF', value: '12345') }
65
+ end
66
+
67
+ it 'document' do
68
+ expect(xml).to match %r[
69
+ <payment>
70
+ .*<sender>
71
+ .*<documents>
72
+ .*<document>
73
+ .*<type>CPF</type>
74
+ .*<value>12345</value>
75
+ ]xm
76
+ end
77
+ end
78
+
79
+ context 'when there is only cnpj' do
80
+ before do
81
+ transaction_request.sender = {
82
+ document: PagSeguro::Document.new(type: 'CNPJ', value: '62057673000135')
83
+ }
84
+ end
85
+
86
+ it 'should render only the name' do
87
+ expect(xml).to match %r[
88
+ <payment>
89
+ .*<sender>
90
+ .*<documents>
91
+ .*<document>
92
+ .*<type>CNPJ</type>
93
+ .*<value>62057673000135</value>
94
+ ]xm
95
+ end
96
+ end
97
+
98
+ context 'when there are all fields' do
99
+ before do
100
+ transaction_request.sender = {
101
+ name: 'Alice',
102
+ email: 'alice@example.com',
103
+ hash: 'hash1234',
104
+ phone: {
105
+ area_code: 12,
106
+ number: "23456789"
107
+ },
108
+ documents: [
109
+ { type: 'CNPJ', value: '62057673000135' },
110
+ { type: 'CPF', value: '00242866131' }
111
+ ]
112
+ }
113
+ end
114
+
115
+ it 'name' do
116
+ expect(xml).to match %r[
117
+ <payment>
118
+ .*<sender>
119
+ .*<name>Alice</name>
120
+ ]xm
121
+ end
122
+
123
+ it 'email' do
124
+ expect(xml).to match %r[
125
+ <payment>
126
+ .*<sender>
127
+ .*<email>alice@example.com</email>
128
+ ]xm
129
+ end
130
+
131
+ it 'phone' do
132
+ expect(xml).to match %r[
133
+ <payment>
134
+ .*<sender>
135
+ .*<phone>
136
+ .*<areaCode>12</areaCode>
137
+ .*<number>23456789</number>
138
+ ]xm
139
+ end
140
+
141
+ it 'cpf' do
142
+ expect(xml).to match %r[
143
+ <payment>
144
+ .*<sender>
145
+ .*<documents>
146
+ .*<document>
147
+ .*<type>CPF</type>
148
+ .*<value>00242866131</value>
149
+ ]xm
150
+ end
151
+
152
+ it 'other documents' do
153
+ expect(xml).to match %r[
154
+ <payment>
155
+ .*<sender>
156
+ .*<documents>
157
+ .*<document>
158
+ .*<type>CNPJ</type>
159
+ .*<value>62057673000135</value>
160
+ .*</document>
161
+ .*<document>
162
+ .*<type>CPF</type>
163
+ .*<value>00242866131</value>
164
+ ]xm
165
+ end
166
+
167
+ it 'hash' do
168
+ expect(xml).to match %r[
169
+ <payment>
170
+ .*<sender>
171
+ .*<hash>hash1234</hash>
172
+ ]xm
173
+ end
174
+ end
175
+ end
176
+
177
+ it 'should serialize currency' do
178
+ transaction_request.currency = 'BRL'
179
+
180
+ expect(xml).to match %r[
181
+ <payment>
182
+ .*<currency>BRL</currency>
183
+ ]xm
184
+ end
185
+
186
+ it 'should serialize notificationURL' do
187
+ transaction_request.notification_url = 'http://www1.example.com/'
188
+
189
+ expect(xml).to match %r[
190
+ <payment>
191
+ .*<notificationURL>http://www1.example.com/</notificationURL>
192
+ ]xm
193
+ end
194
+
195
+ context "should serialize item's" do
196
+ before do
197
+ transaction_request.items << {
198
+ id: 123,
199
+ description: 'TV',
200
+ quantity: 300,
201
+ amount: 150
202
+ }
203
+ end
204
+
205
+ it 'id' do
206
+ expect(xml).to match %r[
207
+ <payment>
208
+ .*<items>
209
+ .*<item>
210
+ .*<id>123</id>
211
+ ]xm
212
+ end
213
+
214
+ it 'description' do
215
+ expect(xml).to match %r[
216
+ <payment>
217
+ .*<items>
218
+ .*<item>
219
+ .*<description>TV</description>
220
+ ]xm
221
+ end
222
+
223
+ it 'quantity' do
224
+ expect(xml).to match %r[
225
+ <payment>
226
+ .*<items>
227
+ .*<item>
228
+ .*<quantity>300</quantity>
229
+ ]xm
230
+ end
231
+
232
+ it 'amount' do
233
+ expect(xml).to match %r[
234
+ <payment>
235
+ .*<items>
236
+ .*<item>
237
+ .*<amount>150.00</amount>
238
+ ]xm
239
+ end
240
+ end
241
+
242
+ it 'should serialize empty extraAmount' do
243
+ transaction_request.extra_amount = nil
244
+
245
+ expect(xml).to match %r[
246
+ <payment>
247
+ .*<extraAmount>0.00</extraAmount>
248
+ ]xm
249
+ end
250
+
251
+ it 'should serialize extraAmount' do
252
+ transaction_request.extra_amount = 100
253
+
254
+ expect(xml).to match %r[
255
+ <payment>
256
+ .*<extraAmount>100.00</extraAmount>
257
+ ]xm
258
+ end
259
+
260
+ it 'should serialize reference' do
261
+ transaction_request.reference = 'ref123'
262
+
263
+ expect(xml).to match %r[
264
+ <payment>
265
+ .*<reference>ref123</reference>
266
+ ]xm
267
+ end
268
+
269
+ context "should serialize address's" do
270
+ before do
271
+ transaction_request.shipping = PagSeguro::Shipping.new(
272
+ address: {
273
+ street: 'One Avenue',
274
+ number: 1234,
275
+ complement: '1st floor',
276
+ district: 'Somewhere',
277
+ city: 'Somewhere City',
278
+ state: 'ST',
279
+ country: 'BRA',
280
+ postal_code: '01234567'
281
+ }
282
+ )
283
+ end
284
+
285
+ it 'street' do
286
+ expect(xml).to match %r[
287
+ <payment>
288
+ .*<shipping>
289
+ .*<address>
290
+ .*<street>One.Avenue</street>
291
+ ]xm
292
+ end
293
+
294
+ it 'number' do
295
+ expect(xml).to match %r[
296
+ <payment>
297
+ .*<shipping>
298
+ .*<address>
299
+ .*<number>1234</number>
300
+ ]xm
301
+ end
302
+
303
+ it 'complement' do
304
+ expect(xml).to match %r[
305
+ <payment>
306
+ .*<shipping>
307
+ .*<address>
308
+ .*<complement>1st.floor</complement>
309
+ ]xm
310
+ end
311
+
312
+ it 'district' do
313
+ expect(xml).to match %r[
314
+ <payment>
315
+ .*<shipping>
316
+ .*<address>
317
+ .*<district>Somewhere</district>
318
+ ]xm
319
+ end
320
+
321
+ it 'city' do
322
+ expect(xml).to match %r[
323
+ <payment>
324
+ .*<shipping>
325
+ .*<address>
326
+ .*<city>Somewhere.City</city>
327
+ ]xm
328
+ end
329
+
330
+ it 'state' do
331
+ expect(xml).to match %r[
332
+ <payment>
333
+ .*<shipping>
334
+ .*<address>
335
+ .*<state>ST</state>
336
+ ]xm
337
+ end
338
+
339
+ it 'country' do
340
+ expect(xml).to match %r[
341
+ <payment>
342
+ .*<shipping>
343
+ .*<address>
344
+ .*<country>BRA</country>
345
+ ]xm
346
+ end
347
+
348
+ it 'postalCode' do
349
+ expect(xml).to match %r[
350
+ <payment>
351
+ .*<shipping>
352
+ .*<address>
353
+ .*<postalCode>01234567</postalCode>
354
+ ]xm
355
+ end
356
+ end
357
+
358
+ context "should serializer credit card info about" do
359
+ let(:transaction_request) do
360
+ PagSeguro::CreditCardTransactionRequest.new(
361
+ credit_card_token: 'tok123',
362
+ installment: {
363
+ quantity: 10,
364
+ value: 50
365
+ },
366
+ holder: {
367
+ name: 'John',
368
+ document: { type: 'CPF', value: '870' },
369
+ birth_date: '20/10/1980',
370
+ phone: { area_code: 11, number: 999991111 }
371
+ },
372
+ billing_address: {
373
+ street: 'Lima',
374
+ complement: '1 andar',
375
+ number: 1384,
376
+ district: 'Jardim Paulistano',
377
+ city: 'Sao Paulo',
378
+ state: 'SP',
379
+ country: 'BRA',
380
+ postal_code: '014',
381
+ }
382
+ )
383
+ end
384
+
385
+ before do
386
+ transaction_request.sender = { name: 'Alice' }
387
+ end
388
+
389
+ it 'token' do
390
+ expect(xml).to match %r[
391
+ <payment>
392
+ .*<creditCard>
393
+ .*<token>tok123</token>
394
+ ]xm
395
+ end
396
+
397
+ it 'installment' do
398
+ expect(xml).to match %r[
399
+ <payment>
400
+ .*<creditCard>
401
+ .*<installment>
402
+ .*<quantity>10</quantity>
403
+ .*<value>50.00
404
+ ]xm
405
+ end
406
+
407
+ it 'holder' do
408
+ expect(xml).to match %r[
409
+ <payment>
410
+ .*<creditCard>
411
+ .*<holder>
412
+ .*<name>John</name>
413
+ .*<documents>
414
+ .*<document>
415
+ .*<type>CPF</type>
416
+ .*<value>870</value>
417
+ .*</document>
418
+ .*</documents>
419
+ .*<birthDate>20/10/1980</birthDate>
420
+ .*<phone>
421
+ .*<areaCode>11</areaCode>
422
+ .*<number>999991111</number>
423
+ ]xm
424
+ end
425
+
426
+ it 'billingAddress' do
427
+ expect(xml).to match %r[
428
+ <payment>
429
+ .*<creditCard>
430
+ .*<billingAddress>
431
+ .*<street>Lima</street>
432
+ .*<number>1384</number>
433
+ .*<complement>1.andar</complement>
434
+ .*<district>Jardim.Paulistano</district>
435
+ .*<city>Sao.Paulo</city>
436
+ .*<state>SP</state>
437
+ .*<country>BRA</country>
438
+ .*<postalCode>014</postalCode>
439
+ ]xm
440
+ end
441
+ end
442
+ end
443
+
444
+ context '#to_params' do
445
+ let(:params) { subject.to_params }
446
+
447
+ before do
448
+ allow(transaction_request).to receive_messages({
449
+ payment_method: "creditCard",
450
+ credit_card_token: "4as56d4a56d456as456dsa"
451
+ })
452
+ end
453
+
454
+ context "global configuration serialization" do
455
+ before do
456
+ PagSeguro.configuration.receiver_email = "receiver@example.com"
457
+ end
458
+
459
+ it { expect(params).to include(receiverEmail: "receiver@example.com") }
460
+ end
461
+
462
+ context "generic attributes serialization" do
463
+ before do
464
+ allow(transaction_request).to receive_messages({
465
+ currency: "BRL",
466
+ reference: "REF123",
467
+ extra_amount: 1234.50,
468
+ notification_url: "NOTIFICATION_URL",
469
+ payment_mode: "default"
470
+ })
471
+ end
472
+
473
+ it { expect(params).to include(currency: "BRL") }
474
+ it { expect(params).to include(reference: "REF123") }
475
+ it { expect(params).to include(extraAmount: "1234.50") }
476
+ it { expect(params).to include(notificationURL: "NOTIFICATION_URL") }
477
+ it { expect(params).to include(paymentMethod: "creditCard") }
478
+ it { expect(params).to include(paymentMode: "default") }
479
+ it { expect(params).to include(creditCardToken: "4as56d4a56d456as456dsa") }
480
+ end
481
+
482
+ context "items serialization" do
483
+ def build_item(index)
484
+ PagSeguro::Item.new({
485
+ id: "ID#{index}",
486
+ description: "DESC#{index}",
487
+ quantity: "QTY#{index}",
488
+ amount: index * 100 + 0.12,
489
+ weight: "WEIGHT#{index}",
490
+ shipping_cost: index * 100 + 0.34
491
+ })
492
+ end
493
+
494
+ shared_examples_for "item serialization" do |index|
495
+ it { expect(params).to include("itemId#{index}" => "ID#{index}") }
496
+ it { expect(params).to include("itemDescription#{index}" => "DESC#{index}") }
497
+ it { expect(params).to include("itemAmount#{index}" => "#{index}00.12") }
498
+ it { expect(params).to include("itemShippingCost#{index}" => "#{index}00.34") }
499
+ it { expect(params).to include("itemQuantity#{index}" => "QTY#{index}") }
500
+ it { expect(params).to include("itemWeight#{index}" => "WEIGHT#{index}") }
501
+ end
502
+
503
+ before do
504
+ transaction_request.items << build_item(1)
505
+ transaction_request.items << build_item(2)
506
+ end
507
+
508
+ it_behaves_like "item serialization", 1
509
+ it_behaves_like "item serialization", 2
510
+ end
511
+
512
+ context "bank serialization" do
513
+ before do
514
+ allow(transaction_request).to receive(:bank) do
515
+ PagSeguro::Bank.new({name: "itau"})
516
+ end
517
+ end
518
+
519
+ it { expect(params).to include(bankName: "itau") }
520
+ end
521
+
522
+ context "holder serialization" do
523
+ before do
524
+ holder = PagSeguro::Holder.new({
525
+ name: "Jose Comprador",
526
+ birth_date: "27/10/1987",
527
+ document: {
528
+ type: "CPF",
529
+ value: "22111944785"
530
+ },
531
+ phone: {
532
+ area_code: "11",
533
+ number: "56273440"
534
+ }
535
+ })
536
+
537
+ allow(transaction_request).to receive(:holder).and_return(holder)
538
+ end
539
+
540
+ it { expect(params).to include(creditCardHolderName: "Jose Comprador") }
541
+ it { expect(params).to include(creditCardHolderBirthDate: "27/10/1987") }
542
+ it { expect(params).to include(creditCardHolderCPF: "22111944785") }
543
+ it { expect(params).to include(creditCardHolderAreaCode: "11") }
544
+ it { expect(params).to include(creditCardHolderPhone: "56273440") }
545
+ end
546
+
547
+ context "billing address serialization" do
548
+ before do
549
+ address = PagSeguro::Address.new({
550
+ street: "STREET",
551
+ state: "STATE",
552
+ city: "CITY",
553
+ postal_code: "POSTAL_CODE",
554
+ district: "DISTRICT",
555
+ number: "NUMBER",
556
+ complement: "COMPLEMENT"
557
+ })
558
+
559
+ allow(transaction_request).to receive(:billing_address).and_return(address)
560
+ end
561
+
562
+ it { expect(params).to include(billingAddressStreet: "STREET") }
563
+ it { expect(params).to include(billingAddressCountry: "BRA") }
564
+ it { expect(params).to include(billingAddressState: "STATE") }
565
+ it { expect(params).to include(billingAddressCity: "CITY") }
566
+ it { expect(params).to include(billingAddressPostalCode: "POSTAL_CODE") }
567
+ it { expect(params).to include(billingAddressDistrict: "DISTRICT") }
568
+ it { expect(params).to include(billingAddressNumber: "NUMBER") }
569
+ it { expect(params).to include(billingAddressComplement: "COMPLEMENT") }
570
+ end
571
+
572
+ context "sender serialization with CPF" do
573
+ before do
574
+ sender = PagSeguro::Sender.new({
575
+ hash: "HASH",
576
+ email: "EMAIL",
577
+ name: "NAME",
578
+ document: { type: "CPF", value: "CPF" },
579
+ phone: {
580
+ area_code: "AREA_CODE",
581
+ number: "NUMBER"
582
+ }
583
+ })
584
+
585
+ allow(transaction_request).to receive(:sender).and_return(sender)
586
+ end
587
+
588
+ it { expect(params).to include(senderHash: "HASH") }
589
+ it { expect(params).to include(senderEmail: "EMAIL") }
590
+ it { expect(params).to include(senderName: "NAME") }
591
+ it { expect(params).to include(senderCPF: "CPF") }
592
+ it { expect(params).to include(senderAreaCode: "AREA_CODE") }
593
+ it { expect(params).to include(senderPhone: "NUMBER") }
594
+ end
595
+
596
+ context "sender serialization with CNPJ" do
597
+ before do
598
+ sender = PagSeguro::Sender.new({
599
+ hash: "HASH",
600
+ email: "EMAIL",
601
+ name: "NAME",
602
+ document: { type: "CNPJ", value: "CNPJ" },
603
+ phone: {
604
+ area_code: "AREA_CODE",
605
+ number: "NUMBER"
606
+ }
607
+ })
608
+
609
+ allow(transaction_request).to receive(:sender).and_return(sender)
610
+ end
611
+
612
+ it { expect(params).to include(senderHash: "HASH") }
613
+ it { expect(params).to include(senderEmail: "EMAIL") }
614
+ it { expect(params).to include(senderName: "NAME") }
615
+ it { expect(params).to include(senderCNPJ: "CNPJ") }
616
+ it { expect(params).to include(senderAreaCode: "AREA_CODE") }
617
+ it { expect(params).to include(senderPhone: "NUMBER") }
618
+ end
619
+
620
+ context "shipping serialization" do
621
+ before do
622
+ transaction_request.shipping = PagSeguro::Shipping.new({
623
+ type_id: 1,
624
+ cost: 1234.56,
625
+ address: {
626
+ street: "STREET",
627
+ state: "STATE",
628
+ city: "CITY",
629
+ postal_code: "POSTAL_CODE",
630
+ district: "DISTRICT",
631
+ number: "NUMBER",
632
+ complement: "COMPLEMENT"
633
+ }
634
+ })
635
+ end
636
+
637
+ it { expect(params).to include(shippingType: 1) }
638
+ it { expect(params).to include(shippingCost: "1234.56") }
639
+ it { expect(params).to include(shippingAddressStreet: "STREET") }
640
+ it { expect(params).to include(shippingAddressCountry: "BRA") }
641
+ it { expect(params).to include(shippingAddressState: "STATE") }
642
+ it { expect(params).to include(shippingAddressCity: "CITY") }
643
+ it { expect(params).to include(shippingAddressPostalCode: "POSTAL_CODE") }
644
+ it { expect(params).to include(shippingAddressDistrict: "DISTRICT") }
645
+ it { expect(params).to include(shippingAddressNumber: "NUMBER") }
646
+ it { expect(params).to include(shippingAddressComplement: "COMPLEMENT") }
647
+ end
648
+
649
+ context "installment serialization" do
650
+ before do
651
+ installment = PagSeguro::TransactionInstallment.new({
652
+ value: "459.50",
653
+ quantity: "1"
654
+ })
655
+
656
+ allow(transaction_request).to receive(:installment).and_return(installment)
657
+ end
658
+
659
+ it { expect(params).to include(installmentValue: "459.50") }
660
+ it { expect(params).to include(installmentQuantity: "1") }
661
+ end
662
+
663
+ context "extra params serialization" do
664
+ before do
665
+ allow(transaction_request).to receive_messages({
666
+ extra_params: [
667
+ { extraParam: 'param_value' },
668
+ { newExtraParam: 'extra_param_value' }
669
+ ]
670
+ })
671
+ end
672
+
673
+ it { expect(params).to include(extraParam: 'param_value') }
674
+ it { expect(params).to include(newExtraParam: 'extra_param_value') }
675
+ end
676
+ end
677
+ end