dpay 0.1.0

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 (137) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +29 -0
  3. data/LICENSE +201 -0
  4. data/README.md +191 -0
  5. data/lib/dpay/bank/bank.rb +28 -0
  6. data/lib/dpay/bank/bank_service.rb +28 -0
  7. data/lib/dpay/blik/blik_alias.rb +27 -0
  8. data/lib/dpay/blik/blik_alias_registration.rb +21 -0
  9. data/lib/dpay/blik/blik_alias_type.rb +18 -0
  10. data/lib/dpay/blik/blik_app.rb +17 -0
  11. data/lib/dpay/blik/blik_recurring_registration.rb +74 -0
  12. data/lib/dpay/blik/blik_recurring_registration_info.rb +26 -0
  13. data/lib/dpay/blik/blik_recurring_status.rb +28 -0
  14. data/lib/dpay/blik/blik_service.rb +51 -0
  15. data/lib/dpay/card/apple_pay_request.rb +38 -0
  16. data/lib/dpay/card/card_data.rb +30 -0
  17. data/lib/dpay/card/card_encryptor.rb +27 -0
  18. data/lib/dpay/card/card_payment_request.rb +59 -0
  19. data/lib/dpay/card/card_payment_result.rb +58 -0
  20. data/lib/dpay/card/card_recurring_frequency.rb +23 -0
  21. data/lib/dpay/card/card_recurring_operation.rb +19 -0
  22. data/lib/dpay/card/card_recurring_registration.rb +69 -0
  23. data/lib/dpay/card/card_service.rb +47 -0
  24. data/lib/dpay/card/dcc_decision.rb +18 -0
  25. data/lib/dpay/card/dcc_markup.rb +18 -0
  26. data/lib/dpay/card/dcc_offer.rb +36 -0
  27. data/lib/dpay/card/google_pay_request.rb +35 -0
  28. data/lib/dpay/card/redirect_type.rb +20 -0
  29. data/lib/dpay/client.rb +26 -0
  30. data/lib/dpay/config.rb +39 -0
  31. data/lib/dpay/currency.rb +19 -0
  32. data/lib/dpay/errors.rb +77 -0
  33. data/lib/dpay/http/client.rb +11 -0
  34. data/lib/dpay/http/net_http_client.rb +52 -0
  35. data/lib/dpay/http/request.rb +17 -0
  36. data/lib/dpay/http/response.rb +29 -0
  37. data/lib/dpay/internal/api_requestor.rb +65 -0
  38. data/lib/dpay/internal/base_urls.rb +38 -0
  39. data/lib/dpay/internal/checksum_calculator.rb +26 -0
  40. data/lib/dpay/internal/coerce.rb +46 -0
  41. data/lib/dpay/internal/error_mapper.rb +90 -0
  42. data/lib/dpay/internal/php.rb +71 -0
  43. data/lib/dpay/ipn/ipn_event.rb +84 -0
  44. data/lib/dpay/ipn/ipn_type.rb +19 -0
  45. data/lib/dpay/ipn/ipn_verifier.rb +57 -0
  46. data/lib/dpay/money.rb +85 -0
  47. data/lib/dpay/payment/device_info.rb +42 -0
  48. data/lib/dpay/payment/invoice_details.rb +48 -0
  49. data/lib/dpay/payment/payer.rb +26 -0
  50. data/lib/dpay/payment/payment_service.rb +35 -0
  51. data/lib/dpay/payment/payout_fee_mode.rb +18 -0
  52. data/lib/dpay/payment/payout_instruction.rb +26 -0
  53. data/lib/dpay/payment/payout_position.rb +23 -0
  54. data/lib/dpay/payment/register_payment_request.rb +246 -0
  55. data/lib/dpay/payment/registered_payment.rb +42 -0
  56. data/lib/dpay/payment/return_urls.rb +20 -0
  57. data/lib/dpay/payment/transaction.rb +54 -0
  58. data/lib/dpay/payment/transaction_refund.rb +21 -0
  59. data/lib/dpay/payment/transaction_status.rb +21 -0
  60. data/lib/dpay/payment/transaction_type.rb +23 -0
  61. data/lib/dpay/payout/payout_details.rb +50 -0
  62. data/lib/dpay/payout/payout_receiver.rb +22 -0
  63. data/lib/dpay/payout/payout_service.rb +23 -0
  64. data/lib/dpay/refund/refund.rb +22 -0
  65. data/lib/dpay/refund/refund_availability.rb +23 -0
  66. data/lib/dpay/refund/refund_service.rb +46 -0
  67. data/lib/dpay/testing/mock_http_client.rb +51 -0
  68. data/lib/dpay/testing.rb +4 -0
  69. data/lib/dpay/version.rb +5 -0
  70. data/lib/dpay.rb +68 -0
  71. data/sig/dpay/bank/bank.rbs +17 -0
  72. data/sig/dpay/bank/bank_service.rbs +13 -0
  73. data/sig/dpay/blik/blik_alias.rbs +17 -0
  74. data/sig/dpay/blik/blik_alias_registration.rbs +6 -0
  75. data/sig/dpay/blik/blik_alias_type.rbs +11 -0
  76. data/sig/dpay/blik/blik_app.rbs +10 -0
  77. data/sig/dpay/blik/blik_recurring_registration.rbs +24 -0
  78. data/sig/dpay/blik/blik_recurring_registration_info.rbs +17 -0
  79. data/sig/dpay/blik/blik_recurring_status.rbs +17 -0
  80. data/sig/dpay/blik/blik_service.rbs +13 -0
  81. data/sig/dpay/card/apple_pay_request.rbs +13 -0
  82. data/sig/dpay/card/card_data.rbs +15 -0
  83. data/sig/dpay/card/card_encryptor.rbs +9 -0
  84. data/sig/dpay/card/card_payment_request.rbs +17 -0
  85. data/sig/dpay/card/card_payment_result.rbs +22 -0
  86. data/sig/dpay/card/card_recurring_frequency.rbs +16 -0
  87. data/sig/dpay/card/card_recurring_operation.rbs +12 -0
  88. data/sig/dpay/card/card_recurring_registration.rbs +22 -0
  89. data/sig/dpay/card/card_service.rbs +16 -0
  90. data/sig/dpay/card/dcc_decision.rbs +11 -0
  91. data/sig/dpay/card/dcc_markup.rbs +10 -0
  92. data/sig/dpay/card/dcc_offer.rbs +21 -0
  93. data/sig/dpay/card/google_pay_request.rbs +12 -0
  94. data/sig/dpay/card/redirect_type.rbs +13 -0
  95. data/sig/dpay/client.rbs +21 -0
  96. data/sig/dpay/config.rbs +25 -0
  97. data/sig/dpay/currency.rbs +11 -0
  98. data/sig/dpay/errors.rbs +86 -0
  99. data/sig/dpay/http/client.rbs +7 -0
  100. data/sig/dpay/http/net_http_client.rbs +15 -0
  101. data/sig/dpay/http/request.rbs +12 -0
  102. data/sig/dpay/http/response.rbs +15 -0
  103. data/sig/dpay/internal/api_requestor.rbs +23 -0
  104. data/sig/dpay/internal/base_urls.rbs +13 -0
  105. data/sig/dpay/internal/checksum_calculator.rbs +9 -0
  106. data/sig/dpay/internal/coerce.rbs +12 -0
  107. data/sig/dpay/internal/error_mapper.rbs +16 -0
  108. data/sig/dpay/internal/php.rbs +16 -0
  109. data/sig/dpay/ipn/ipn_event.rbs +28 -0
  110. data/sig/dpay/ipn/ipn_type.rbs +12 -0
  111. data/sig/dpay/ipn/ipn_verifier.rbs +11 -0
  112. data/sig/dpay/money.rbs +25 -0
  113. data/sig/dpay/payment/device_info.rbs +25 -0
  114. data/sig/dpay/payment/invoice_details.rbs +17 -0
  115. data/sig/dpay/payment/payer.rbs +14 -0
  116. data/sig/dpay/payment/payment_service.rbs +11 -0
  117. data/sig/dpay/payment/payout_fee_mode.rbs +11 -0
  118. data/sig/dpay/payment/payout_instruction.rbs +8 -0
  119. data/sig/dpay/payment/payout_position.rbs +10 -0
  120. data/sig/dpay/payment/register_payment_request.rbs +56 -0
  121. data/sig/dpay/payment/registered_payment.rbs +20 -0
  122. data/sig/dpay/payment/return_urls.rbs +11 -0
  123. data/sig/dpay/payment/transaction.rbs +25 -0
  124. data/sig/dpay/payment/transaction_refund.rbs +14 -0
  125. data/sig/dpay/payment/transaction_status.rbs +14 -0
  126. data/sig/dpay/payment/transaction_type.rbs +16 -0
  127. data/sig/dpay/payout/payout_details.rbs +24 -0
  128. data/sig/dpay/payout/payout_receiver.rbs +15 -0
  129. data/sig/dpay/payout/payout_service.rbs +6 -0
  130. data/sig/dpay/refund/refund.rbs +11 -0
  131. data/sig/dpay/refund/refund_availability.rbs +12 -0
  132. data/sig/dpay/refund/refund_service.rbs +14 -0
  133. data/sig/dpay/testing/mock_http_client.rbs +16 -0
  134. data/sig/dpay/testing.rbs +4 -0
  135. data/sig/dpay/version.rbs +3 -0
  136. data/sig/dpay.rbs +2 -0
  137. metadata +180 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1f660bb376f9c3a692b0fcd3b243384fb4265a826afb4bce089928687c2ac7e
4
+ data.tar.gz: ac17460ac4601eb85224609d373a45870eed71a38f129fdf94098fc1d31361d7
5
+ SHA512:
6
+ metadata.gz: 3ac8bf1585647900f6723835332ededbaa0b3b6e2901ffe9c23e55fa6688cc448d7c3d4eb7bcc62bcaf4a08f9b4728ddf103a20094801cbd06ce4a3f69e28a1c
7
+ data.tar.gz: 493b7bf534857df4fc6dcbebbba508ad58b1ea91770bfaf424b67bd02728229f79ab9354532ccca9be078c49d3ad0edfd62c71a08680ace6672e199080038abd
data/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ Wszystkie istotne zmiany w tym projekcie są dokumentowane w tym pliku.
4
+
5
+ Format oparty na [Keep a Changelog](https://keepachangelog.com/pl/1.1.0/),
6
+ projekt stosuje [Semantic Versioning](https://semver.org/lang/pl/).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-07-23
11
+
12
+ ### Added
13
+
14
+ - Klient `DPay::Client` z serwisami `payments`, `refunds`, `banks`, `blik`, `cards`, `payouts`.
15
+ - Rejestracja płatności i szczegóły transakcji.
16
+ - Zwroty pełne i częściowe oraz sprawdzanie dostępności zwrotu.
17
+ - Lista banków globalna i dla punktu płatności.
18
+ - Aliasy BLIK: rejestracja, wyrejestrowanie, status cykliczności.
19
+ - Płatności kartowe S2S: klucz publiczny, OTP, preautoryzacja, capture, anulowanie, Google Pay, Apple Pay, DCC.
20
+ - Szczegóły wypłat.
21
+ - Weryfikacja IPN (`DPay::IpnVerifier`) z `DPay::IpnEvent::ACK`.
22
+ - Wartości `DPay::Money` i `DPay::Currency` oraz pełna hierarchia błędów z markerem `DPay::Error`.
23
+ - `DPay::Testing::MockHttpClient` do testów integracji.
24
+ - Sygnatury RBS w `sig/`.
25
+
26
+ ### Notes
27
+
28
+ - Zero zależności runtime; transport domyślny oparty na `net/http`.
29
+ - Parytet wire-protocol z rodziną SDK dpay potwierdzony golden vectors.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # dpay Ruby SDK
2
+
3
+ Oficjalna biblioteka Ruby do integracji z API płatności [dpay.pl](https://dpay.pl).
4
+
5
+ ## Wymagania
6
+
7
+ - Ruby 3.1 lub nowszy
8
+ - Zero zależności runtime
9
+
10
+ ## Instalacja
11
+
12
+ ```bash
13
+ gem install dpay
14
+ ```
15
+
16
+ Lub dopisz w `Gemfile`:
17
+
18
+ ```ruby
19
+ gem "dpay"
20
+ ```
21
+
22
+ ## Szybki start
23
+
24
+ ```ruby
25
+ require "dpay"
26
+
27
+ dpay = DPay::Client.new(service: "nazwa_serwisu", secret_hash: "twoj_secret_hash")
28
+
29
+ payment = dpay.payments.register(
30
+ DPay::RegisterPaymentRequest
31
+ .create(
32
+ DPay::Money.pln(1050),
33
+ DPay::TransactionType::TRANSFERS,
34
+ DPay::ReturnUrls.new(
35
+ "https://twojsklep.pl/sukces",
36
+ "https://twojsklep.pl/blad",
37
+ "https://twojsklep.pl/ipn"
38
+ )
39
+ )
40
+ .with_description("Zamówienie #1234")
41
+ .with_custom("order-1234")
42
+ )
43
+
44
+ redirect_to payment.redirect_url if payment.redirect_url
45
+ ```
46
+
47
+ `DPay::Money.pln(1050)` przyjmuje kwotę w groszach (najmniejszej jednostce), czyli 10,50 PLN.
48
+ `RegisterPaymentRequest` to budowniczy: każda metoda `with_*` zwraca `self`, więc wywołania można łączyć w łańcuch.
49
+
50
+ ## Obsługa IPN
51
+
52
+ Brama traktuje jako potwierdzenie dokładnie treść odpowiedzi, nie kod HTTP. Musi to być dokładnie napis
53
+ `"OK"` (dostępny jako stała `DPay::IpnEvent::ACK`) - jakikolwiek inna treść w body oznacza dla dpay.pl,
54
+ że powiadomienie nie zostało obsłużone i zostanie wysłane ponownie.
55
+
56
+ ```ruby
57
+ begin
58
+ event = DPay::IpnVerifier.construct_event(request.raw_post, "twoj_secret_hash")
59
+ rescue DPay::SignatureVerificationError
60
+ return render plain: "Invalid signature", status: :bad_request
61
+ end
62
+
63
+ mark_order_as_paid(event.id, event.amount) if event.transfer? || event.capture?
64
+
65
+ render plain: DPay::IpnEvent::ACK
66
+ ```
67
+
68
+ `event.amount` to surowy string dziesiętny, a nie `DPay::Money` - payload IPN nie niesie informacji
69
+ o walucie. Zawsze porównaj tę wartość z kwotą własnego zamówienia przed oznaczeniem go jako opłacone,
70
+ zamiast ufać wyłącznie faktowi otrzymania powiadomienia.
71
+
72
+ ## Zwroty
73
+
74
+ ```ruby
75
+ dpay.refunds.create("identyfikator-transakcji")
76
+ dpay.refunds.create("identyfikator-transakcji", DPay::Money.pln(500), "reklamacja")
77
+
78
+ availability = dpay.refunds.check_availability("identyfikator-transakcji")
79
+ availability.available?
80
+ ```
81
+
82
+ ## Szczegóły transakcji i banki
83
+
84
+ ```ruby
85
+ transaction = dpay.payments.details("identyfikator-transakcji")
86
+ transaction.paid?
87
+ transaction.available_refund_amount.to_decimal
88
+ transaction.refunds
89
+
90
+ banks = dpay.banks.for_service
91
+ ```
92
+
93
+ ## Karty S2S
94
+
95
+ ```ruby
96
+ public_key = dpay.cards.public_key
97
+
98
+ encrypted = DPay::CardEncryptor.new.encrypt(
99
+ DPay::CardData.new("4111111111111111", "123", "12/28"),
100
+ "identyfikator-transakcji",
101
+ public_key
102
+ )
103
+
104
+ device_info = DPay::DeviceInfo.create(
105
+ browser_accept_header: "text/html", browser_language: "pl-PL", browser_color_depth: 24,
106
+ browser_screen_height: 1080, browser_screen_width: 1920, browser_tz: -60,
107
+ browser_user_agent: "Mozilla/5.0", system_family: "Windows", geo_localization: "52.2297,21.0122",
108
+ device_id: "device-1", application_name: "sklep"
109
+ )
110
+
111
+ result = dpay.cards.pay_otp(
112
+ "identyfikator-transakcji",
113
+ DPay::CardPaymentRequest.create(device_info).with_encrypted_card_data(encrypted)
114
+ )
115
+
116
+ return render_html(result.three_ds_form_html) if result.three_ds_form?
117
+ offer = result.dcc_offer if result.dcc_offer?
118
+ ```
119
+
120
+ Klucz publiczny jest rotowany - pobieraj go przed każdą próbą płatności, nie przechowuj go u siebie.
121
+
122
+ ## Obsługa błędów
123
+
124
+ Wszystkie wyjątki SDK dołączają moduł `DPay::Error`, więc `rescue DPay::Error` łapie każdy z nich.
125
+
126
+ ```ruby
127
+ begin
128
+ payment = dpay.payments.register(request)
129
+ rescue DPay::InvalidRequestError => e
130
+ e.field_errors
131
+ rescue DPay::ApiError => e
132
+ e.http_status
133
+ e.error_code
134
+ rescue DPay::TransportError
135
+ # błąd sieci - status płatności jest nieznany, sprawdź go przez payments.details()
136
+ rescue DPay::Error => e
137
+ # dowolny inny błąd SDK, np. DPay::InvalidArgumentError
138
+ end
139
+ ```
140
+
141
+ | Wyjątek | Kiedy |
142
+ |---|---|
143
+ | `DPay::AuthenticationError` | HTTP 401 - niepoprawny checksum |
144
+ | `DPay::InvalidRequestError` | HTTP 400 lub 422 - błędne dane wejściowe, patrz `field_errors` |
145
+ | `DPay::AccessDeniedError` | HTTP 403 |
146
+ | `DPay::NotFoundError` | HTTP 404 |
147
+ | `DPay::RateLimitError` | HTTP 429, dodatkowo `retry_after`, `limit`, `remaining` |
148
+ | `DPay::ApiServerError` | HTTP 5xx |
149
+ | `DPay::PaymentRejectedError` | rejestracja płatności odrzucona mimo HTTP 200 |
150
+ | `DPay::CardPaymentError` | płatność kartą odrzucona mimo HTTP 200 |
151
+ | `DPay::SignatureVerificationError` | niepoprawny lub brakujący podpis IPN |
152
+ | `DPay::TransportError` | błąd sieci lub transportu HTTP |
153
+ | `DPay::InvalidArgumentError` | niepoprawny argument przekazany do SDK |
154
+
155
+ ## Konfiguracja
156
+
157
+ | Opcja | Typ | Opis |
158
+ |---|---|---|
159
+ | `service` | `String` | Nazwa Punktu Płatności z panelu dpay.pl (wymagane) |
160
+ | `secret_hash` | `String` | Klucz Secret Hash z panelu dpay.pl (wymagane) |
161
+ | `timeout` | `Integer` | Timeout HTTP w sekundach (domyślnie `30`) |
162
+ | `http_client` | obiekt z metodą `#request` | Własny transport, np. proxy, retry albo testy |
163
+ | `base_urls` | `Hash` | Nadpisanie hostów API: `api_payments`, `panel`, `gateway` |
164
+
165
+ ## Testowanie integracji
166
+
167
+ ```ruby
168
+ require "dpay/testing"
169
+
170
+ transport = DPay::Testing::MockHttpClient.new
171
+ transport.queue_json(200, { "transactionId" => "tx-1", "msg" => "https://secure.dpay.pl/pay/1" })
172
+
173
+ dpay = DPay::Client.new(service: "test", secret_hash: "test", http_client: transport)
174
+
175
+ request = DPay::RegisterPaymentRequest.create(
176
+ DPay::Money.pln(1050),
177
+ DPay::TransactionType::TRANSFERS,
178
+ DPay::ReturnUrls.new("https://twojsklep.pl/sukces", "https://twojsklep.pl/blad", "https://twojsklep.pl/ipn")
179
+ )
180
+
181
+ payment = dpay.payments.register(request)
182
+
183
+ transport.last_request_body["value"] # => "10.50"
184
+ ```
185
+
186
+ `DPay::Testing::MockHttpClient` implementuje ten sam interfejs co domyślny transport (`#request`), więc
187
+ można go podać jako `http_client:` bez żadnych innych zmian w kodzie testowanym.
188
+
189
+ ## Licencja
190
+
191
+ Apache-2.0
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class Bank
5
+ attr_reader :id, :name, :image, :on_from, :on_to, :iterator, :type, :raw
6
+
7
+ def self.from_api(data)
8
+ new(data)
9
+ end
10
+
11
+ def initialize(data)
12
+ @raw = data
13
+ @id = Internal::Coerce.string(data["id"]) || ""
14
+ @name = Internal::Coerce.string(data["name"]) || ""
15
+ @image = data["image"].is_a?(String) ? data["image"] : nil
16
+ @on_from = Internal::Coerce.integer(data["on_from"])
17
+ @on_to = Internal::Coerce.integer(data["on_to"])
18
+ @iterator = data["iterator"].nil? ? nil : Internal::Coerce.integer(data["iterator"])
19
+ @test = Internal::Coerce.boolean(data["test"])
20
+ @type = data["type"].is_a?(String) ? data["type"] : nil
21
+ freeze
22
+ end
23
+
24
+ def test?
25
+ @test
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class BankService
5
+ PATH = "/api/v1/pbl/banks"
6
+
7
+ def initialize(api)
8
+ @api = api
9
+ end
10
+
11
+ def all
12
+ map_banks(@api.get_json(Internal::BaseUrls::PANEL, PATH))
13
+ end
14
+
15
+ def for_service(timestamp = nil)
16
+ body = { "service" => @api.service, "timestamp" => timestamp || Time.now.to_i }
17
+ body["checksum"] = @api.checksum.ordered_body(body.values)
18
+
19
+ map_banks(@api.post_json(Internal::BaseUrls::PANEL, PATH, body))
20
+ end
21
+
22
+ private
23
+
24
+ def map_banks(data)
25
+ Internal::Coerce.list(data).map { |bank| Bank.from_api(bank) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class BlikAlias
5
+ ACTIVE = "ACTIVE"
6
+
7
+ attr_reader :alias_value, :alias_type, :status, :expiration_date, :apps, :raw
8
+
9
+ def self.from_api(data)
10
+ new(data)
11
+ end
12
+
13
+ def initialize(data)
14
+ @raw = data
15
+ @alias_value = Internal::Coerce.string(data["alias_value"]) || ""
16
+ @alias_type = Internal::Coerce.string(data["alias_type"]) || BlikAliasType::UID
17
+ @status = data["status"].is_a?(String) ? data["status"] : nil
18
+ @expiration_date = data["expiration_date"].is_a?(String) ? data["expiration_date"] : nil
19
+ @apps = Internal::Coerce.list(data["apps"]).map { |app| BlikApp.from_api(app) }
20
+ freeze
21
+ end
22
+
23
+ def active?
24
+ @status == ACTIVE
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class BlikAliasRegistration
5
+ def initialize(label, type = BlikAliasType::UID)
6
+ unless label.is_a?(String) && !label.empty? && label.length <= 50
7
+ raise InvalidArgumentError, "Alias label must be 1-50 characters"
8
+ end
9
+
10
+ BlikAliasType.assert_valid(type)
11
+
12
+ @label = label
13
+ @type = type
14
+ freeze
15
+ end
16
+
17
+ def to_h
18
+ { "label" => @label, "type" => @type }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ module BlikAliasType
5
+ UID = "UID"
6
+ PAYID = "PAYID"
7
+
8
+ ALL = [UID, PAYID].freeze
9
+
10
+ def self.valid?(value)
11
+ ALL.include?(value)
12
+ end
13
+
14
+ def self.assert_valid(value)
15
+ raise InvalidArgumentError, %(Invalid BLIK alias type "#{value}") unless valid?(value)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class BlikApp
5
+ attr_reader :key, :label
6
+
7
+ def self.from_api(data)
8
+ new(data)
9
+ end
10
+
11
+ def initialize(data)
12
+ @key = data["key"].is_a?(String) ? data["key"] : nil
13
+ @label = data["label"].is_a?(String) ? data["label"] : nil
14
+ freeze
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class BlikRecurringRegistration
5
+ MODELS = %w[A M O].freeze
6
+ FREQUENCY = /\A[1-9][0-9]{0,2}[DWMQY]\z/
7
+ DATE = /\A\d{4}-\d{2}-\d{2}\z/
8
+
9
+ def self.create(label, model, frequency)
10
+ new(label, model, frequency)
11
+ end
12
+
13
+ def initialize(label, model, frequency)
14
+ unless label.is_a?(String) && !label.empty? && label.length <= 50
15
+ raise InvalidArgumentError, "Alias label must be 1-50 characters"
16
+ end
17
+ raise InvalidArgumentError, %(Invalid recurring model "#{model}") unless MODELS.include?(model)
18
+ raise InvalidArgumentError, %(Invalid recurring frequency "#{frequency}") unless FREQUENCY.match?(frequency.to_s)
19
+
20
+ @label = label
21
+ @model = model
22
+ @frequency = frequency
23
+ @optional = {}
24
+ end
25
+
26
+ def with_value(value)
27
+ @optional["value"] = value.to_decimal
28
+ self
29
+ end
30
+
31
+ def with_limit_amt(limit_amt)
32
+ @optional["limit_amt"] = limit_amt
33
+ self
34
+ end
35
+
36
+ def with_tot_limit_amt(tot_limit_amt)
37
+ @optional["tot_limit_amt"] = tot_limit_amt
38
+ self
39
+ end
40
+
41
+ def with_limit_amt_fixed(fixed)
42
+ @optional["is_limit_amt_fixed"] = fixed
43
+ self
44
+ end
45
+
46
+ def with_expiration_date(expiration_date)
47
+ @optional["expiration_date"] = assert_date(expiration_date)
48
+ self
49
+ end
50
+
51
+ def with_init_date(init_date)
52
+ @optional["init_date"] = assert_date(init_date)
53
+ self
54
+ end
55
+
56
+ def to_h
57
+ base = { "label" => @label, "type" => BlikAliasType::PAYID, "model" => @model, "frequency" => @frequency }
58
+
59
+ %w[value limit_amt tot_limit_amt is_limit_amt_fixed expiration_date init_date].each do |key|
60
+ base[key] = @optional[key] if @optional.key?(key)
61
+ end
62
+
63
+ base
64
+ end
65
+
66
+ private
67
+
68
+ def assert_date(date)
69
+ raise InvalidArgumentError, %(Date "#{date}" must be in YYYY-MM-DD format) unless DATE.match?(date.to_s)
70
+
71
+ date
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DPay
4
+ class BlikRecurringRegistrationInfo
5
+ attr_reader :model, :frequency, :limit_amt, :tot_limit_amt, :limit_amt_fixed, :init_date, :label,
6
+ :registered_at, :raw
7
+
8
+ def self.from_api(data)
9
+ new(data)
10
+ end
11
+
12
+ def initialize(data)
13
+ @raw = data
14
+ @model = data["model"].is_a?(String) ? data["model"] : nil
15
+ @frequency = data["frequency"].is_a?(String) ? data["frequency"] : nil
16
+ @limit_amt = data["limit_amt"].is_a?(Integer) ? data["limit_amt"] : nil
17
+ @tot_limit_amt = data["tot_limit_amt"].is_a?(Integer) ? data["tot_limit_amt"] : nil
18
+ fixed = data["is_limit_amt_fixed"]
19
+ @limit_amt_fixed = fixed.is_a?(TrueClass) || fixed.is_a?(FalseClass) ? fixed : nil
20
+ @init_date = data["init_date"].is_a?(String) ? data["init_date"] : nil
21
+ @label = data["label"].is_a?(String) ? data["label"] : nil
22
+ @registered_at = data["registered_at"].is_a?(String) ? data["registered_at"] : nil
23
+ freeze
24
+ end
25
+ end
26
+ end