solidus_bolt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +41 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +20 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +11 -0
  9. data/CHANGELOG.md +1 -0
  10. data/Gemfile +33 -0
  11. data/LICENSE +26 -0
  12. data/README.md +175 -0
  13. data/Rakefile +6 -0
  14. data/app/assets/images/bolt_logo_standard.png +0 -0
  15. data/app/assets/javascripts/authorize_account.js +74 -0
  16. data/app/assets/javascripts/solidus_bolt.js +91 -0
  17. data/app/assets/javascripts/spree/backend/solidus_bolt.js +4 -0
  18. data/app/assets/javascripts/spree/frontend/solidus_bolt.js +18 -0
  19. data/app/assets/stylesheets/spree/backend/solidus_bolt.css +4 -0
  20. data/app/assets/stylesheets/spree/frontend/solidus_bolt.css +4 -0
  21. data/app/controllers/solidus_bolt/accounts_controller.rb +17 -0
  22. data/app/controllers/solidus_bolt/base_controller.rb +21 -0
  23. data/app/controllers/solidus_bolt/webhooks_controller.rb +21 -0
  24. data/app/controllers/spree/admin/bolt_webhooks_controller.rb +34 -0
  25. data/app/controllers/spree/admin/bolts_controller.rb +43 -0
  26. data/app/decorators/controllers/solidus_bolt/spree_checkout_controller/add_addresses_to_bolt.rb +23 -0
  27. data/app/decorators/controllers/solidus_bolt/spree_checkout_controller/refresh_bolt_addresses.rb +17 -0
  28. data/app/decorators/controllers/solidus_bolt/spree_checkout_controller/refresh_bolt_payment_source.rb +17 -0
  29. data/app/decorators/models/solidus_bolt/address_decorator.rb +22 -0
  30. data/app/decorators/models/solidus_bolt/log_entry_decorator.rb +11 -0
  31. data/app/decorators/models/solidus_bolt/order_decorator.rb +44 -0
  32. data/app/decorators/models/solidus_bolt/payment_decorator.rb +11 -0
  33. data/app/decorators/omniauth/strategies/bolt_decorator.rb +16 -0
  34. data/app/jobs/solidus_bolt/add_address_job.rb +11 -0
  35. data/app/models/solidus_bolt/bolt_configuration.rb +74 -0
  36. data/app/models/solidus_bolt/gateway.rb +133 -0
  37. data/app/models/solidus_bolt/payment_method.rb +35 -0
  38. data/app/models/solidus_bolt/payment_source.rb +13 -0
  39. data/app/models/solidus_bolt.rb +7 -0
  40. data/app/overrides/spree/shared/_head/add_bolt_embed_script.html.erb.deface +6 -0
  41. data/app/services/solidus_bolt/accounts/add_address_service.rb +55 -0
  42. data/app/services/solidus_bolt/accounts/add_payment_method_service.rb +45 -0
  43. data/app/services/solidus_bolt/accounts/detail_service.rb +38 -0
  44. data/app/services/solidus_bolt/accounts/detect_account_service.rb +34 -0
  45. data/app/services/solidus_bolt/base_service.rb +55 -0
  46. data/app/services/solidus_bolt/oauth/token_service.rb +43 -0
  47. data/app/services/solidus_bolt/payments/capture_sync_service.rb +24 -0
  48. data/app/services/solidus_bolt/payments/credit_sync_service.rb +44 -0
  49. data/app/services/solidus_bolt/payments/void_sync_service.rb +18 -0
  50. data/app/services/solidus_bolt/server_error.rb +6 -0
  51. data/app/services/solidus_bolt/transactions/authorize_service.rb +72 -0
  52. data/app/services/solidus_bolt/transactions/base_service.rb +28 -0
  53. data/app/services/solidus_bolt/transactions/capture_service.rb +46 -0
  54. data/app/services/solidus_bolt/transactions/detail_service.rb +38 -0
  55. data/app/services/solidus_bolt/transactions/refund_service.rb +46 -0
  56. data/app/services/solidus_bolt/transactions/void_service.rb +44 -0
  57. data/app/services/solidus_bolt/users/refresh_access_token_service.rb +44 -0
  58. data/app/services/solidus_bolt/users/sync_addresses_service.rb +49 -0
  59. data/app/services/solidus_bolt/users/sync_payment_sources_service.rb +50 -0
  60. data/app/services/solidus_bolt/webhooks/create_service.rb +52 -0
  61. data/app/views/spree/admin/bolt_webhooks/new.html.erb +22 -0
  62. data/app/views/spree/admin/bolts/_configuration.html.erb +32 -0
  63. data/app/views/spree/admin/bolts/_form.html.erb +29 -0
  64. data/app/views/spree/admin/bolts/edit.html.erb +6 -0
  65. data/app/views/spree/admin/bolts/show.html.erb +21 -0
  66. data/app/views/spree/admin/payments/source_forms/_bolt.html.erb +1 -0
  67. data/app/views/spree/admin/payments/source_views/_bolt.html.erb +2 -0
  68. data/app/views/spree/api/payments/source_views/_bolt.json.jbuilder +4 -0
  69. data/app/views/spree/checkout/existing_payment/_bolt.html.erb +7 -0
  70. data/app/views/spree/checkout/payment/_bolt.html.erb +1 -0
  71. data/app/views/spree/shared/payment/_bolt.html.erb +19 -0
  72. data/app/webhooks/solidus_bolt/handlers/base_handler.rb +27 -0
  73. data/app/webhooks/solidus_bolt/handlers/capture_handler.rb +13 -0
  74. data/app/webhooks/solidus_bolt/handlers/credit_handler.rb +18 -0
  75. data/app/webhooks/solidus_bolt/handlers/void_handler.rb +11 -0
  76. data/app/webhooks/solidus_bolt/sorter.rb +33 -0
  77. data/bin/console +17 -0
  78. data/bin/rails +7 -0
  79. data/bin/rails-engine +13 -0
  80. data/bin/rails-sandbox +16 -0
  81. data/bin/rake +7 -0
  82. data/bin/sandbox +86 -0
  83. data/bin/setup +8 -0
  84. data/config/initializers/menu_items.rb +14 -0
  85. data/config/locales/en.yml +17 -0
  86. data/config/routes.rb +11 -0
  87. data/db/migrate/20220330094232_create_solidus_bolt_payment_sources.rb +16 -0
  88. data/db/migrate/20220413063328_create_solidus_bolt_bolt_configurations.rb +14 -0
  89. data/db/migrate/20220502005041_swap_url_for_env_boolean_in_bolt_configuration.rb +6 -0
  90. data/db/migrate/20220509102309_rework_solidus_bolt_payment_sources.rb +19 -0
  91. data/db/migrate/20220510075227_add_create_bolt_account_to_solidus_bolt_payment_source.rb +5 -0
  92. data/db/migrate/20220519233043_add_user_to_solidus_bolt_payment_source.rb +5 -0
  93. data/db/migrate/20220526005619_remove_user_id_from_solidus_bolt_payment_source.rb +5 -0
  94. data/db/migrate/20220530102107_rename_bolt_configuration_merchant_id_to_division_public_id.rb +5 -0
  95. data/db/migrate/20220531075527_update_bolt_configuration_environment_column_restrictions.rb +6 -0
  96. data/db/seeds.rb +30 -0
  97. data/lib/generators/solidus_bolt/install/install_generator.rb +78 -0
  98. data/lib/generators/solidus_bolt/install/templates/initializer.rb +8 -0
  99. data/lib/solidus_bolt/configuration.rb +19 -0
  100. data/lib/solidus_bolt/engine.rb +62 -0
  101. data/lib/solidus_bolt/testing_support/factories.rb +32 -0
  102. data/lib/solidus_bolt/version.rb +5 -0
  103. data/lib/solidus_bolt.rb +9 -0
  104. data/lib/tasks/db/seed/solidus_bolt.rake +14 -0
  105. data/lib/views/frontend/spree/shared/_login_bar_items.html.erb +18 -0
  106. data/solidus_bolt.gemspec +46 -0
  107. data/spec/decorators/models/solidus_bolt/address_decorator_spec.rb +24 -0
  108. data/spec/decorators/models/solidus_bolt/order_decorator_spec.rb +36 -0
  109. data/spec/decorators/models/solidus_bolt/payment_decorator_spec.rb +30 -0
  110. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_correct_access_token/receives_a_successful_response.yml +137 -0
  111. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_existing_address/skips_the_add_address_call.yml +82 -0
  112. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_wrong_access_token/gives_an_error.yml +55 -0
  113. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddPaymentMethodService/_call/with_correct_access_token/receives_a_successful_response.yml +186 -0
  114. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddPaymentMethodService/_call/with_wrong_access_token/gives_an_error.yml +179 -0
  115. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetailService/_call/with_correct_access_token/receives_a_successful_response.yml +55 -0
  116. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetailService/_call/with_wrong_access_token/gives_an_error.yml +55 -0
  117. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/receives_the_correct_response.yml +50 -0
  118. data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/returns_status_200.yml +50 -0
  119. data/spec/fixtures/vcr_cassettes/SolidusBolt_Oauth_TokenService/_call/makes_the_API_call.yml +59 -0
  120. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/when_repeat_payment/_call/makes_the_API_call.yml +305 -0
  121. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/with_auto_capture/_call/makes_the_API_call.yml +307 -0
  122. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/without_auto_capture/_call/makes_the_API_call.yml +252 -0
  123. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_CaptureService/_call/makes_the_API_call.yml +242 -0
  124. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_DetailService/_call/makes_the_API_call.yml +244 -0
  125. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_RefundService/_call/makes_the_API_call.yml +296 -0
  126. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_VoidService/_call/makes_the_API_call.yml +242 -0
  127. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_VoidService/_call/when_transaction_id_is_missing/makes_the_API_call.yml +242 -0
  128. data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_VoidService/_call/when_transaction_reference_is_missing/makes_the_API_call.yml +242 -0
  129. data/spec/fixtures/vcr_cassettes/SolidusBolt_Users_SyncAddressesService/_call/adds_the_bill_address_to_the_user.yml +165 -0
  130. data/spec/fixtures/vcr_cassettes/SolidusBolt_Users_SyncAddressesService/_call/adds_the_ship_address_to_the_user.yml +165 -0
  131. data/spec/fixtures/vcr_cassettes/SolidusBolt_Users_SyncPaymentSourcesService/_call/creates_a_new_payment_source_with_card_ID.yml +55 -0
  132. data/spec/fixtures/vcr_cassettes/SolidusBolt_Webhooks_CreateService/_call/with_all_event/returns_a_webhook_id.yml +54 -0
  133. data/spec/fixtures/vcr_cassettes/SolidusBolt_Webhooks_CreateService/_call/with_an_event/returns_a_webhook_id.yml +54 -0
  134. data/spec/fixtures/vcr_cassettes/SolidusBolt_Webhooks_CreateService/_call/with_empty_event/raises_a_server_error.yml +57 -0
  135. data/spec/jobs/solidus_bolt/add_address_job_spec.rb +18 -0
  136. data/spec/models/solidus_bolt/bolt_configuration_spec.rb +173 -0
  137. data/spec/models/solidus_bolt/gateway_spec.rb +130 -0
  138. data/spec/models/solidus_bolt/payment_method_spec.rb +21 -0
  139. data/spec/models/solidus_bolt/payment_source_spec.rb +22 -0
  140. data/spec/requests/solidus_bolt/accounts_controller_spec.rb +41 -0
  141. data/spec/requests/solidus_bolt/webhooks_controller_spec.rb +122 -0
  142. data/spec/requests/spree/admin/bolt_spec.rb +71 -0
  143. data/spec/requests/spree/admin/bolt_webhook_spec.rb +35 -0
  144. data/spec/requests/spree/checkout_controller_spec.rb +117 -0
  145. data/spec/services/solidus_bolt/accounts/add_address_service_spec.rb +45 -0
  146. data/spec/services/solidus_bolt/accounts/add_payment_method_service_spec.rb +47 -0
  147. data/spec/services/solidus_bolt/accounts/detail_service_spec.rb +32 -0
  148. data/spec/services/solidus_bolt/accounts/detect_account_service_spec.rb +15 -0
  149. data/spec/services/solidus_bolt/base_service_spec.rb +49 -0
  150. data/spec/services/solidus_bolt/oauth/token_service_spec.rb +15 -0
  151. data/spec/services/solidus_bolt/payments/capture_sync_service_spec.rb +27 -0
  152. data/spec/services/solidus_bolt/payments/credit_sync_service_spec.rb +38 -0
  153. data/spec/services/solidus_bolt/payments/void_sync_service_spec.rb +25 -0
  154. data/spec/services/solidus_bolt/transactions/authorize_service_spec.rb +117 -0
  155. data/spec/services/solidus_bolt/transactions/base_service_spec.rb +38 -0
  156. data/spec/services/solidus_bolt/transactions/capture_service_spec.rb +37 -0
  157. data/spec/services/solidus_bolt/transactions/detail_service_spec.rb +31 -0
  158. data/spec/services/solidus_bolt/transactions/refund_service_spec.rb +42 -0
  159. data/spec/services/solidus_bolt/transactions/void_service_spec.rb +70 -0
  160. data/spec/services/solidus_bolt/users/refresh_access_token_service_spec.rb +45 -0
  161. data/spec/services/solidus_bolt/users/sync_addresses_service_spec.rb +74 -0
  162. data/spec/services/solidus_bolt/users/sync_payment_sources_service_spec.rb +25 -0
  163. data/spec/services/solidus_bolt/webhooks/create_service_spec.rb +33 -0
  164. data/spec/spec_helper.rb +37 -0
  165. data/spec/support/bolt_configuration.rb +26 -0
  166. data/spec/support/bolt_helper.rb +66 -0
  167. data/spec/support/vcr.rb +29 -0
  168. data/spec/webhooks/solidus_bolt/handlers/base_handler_spec.rb +13 -0
  169. data/spec/webhooks/solidus_bolt/handlers/capture_handler_spec.rb +24 -0
  170. data/spec/webhooks/solidus_bolt/handlers/credit_handler_spec.rb +32 -0
  171. data/spec/webhooks/solidus_bolt/handlers/void_handler_spec.rb +19 -0
  172. data/spec/webhooks/solidus_bolt/sorter_spec.rb +39 -0
  173. metadata +492 -0
@@ -0,0 +1,165 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api-sandbox.bolt.com/v1/account
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - "<BEARER AUTHORIZATION>"
12
+ X-Api-Key:
13
+ - "<API_KEY>"
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Fri, 20 May 2022 11:28:41 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '568'
31
+ Connection:
32
+ - keep-alive
33
+ Public-Key-Pins-Report-Only:
34
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
35
+ Set-Cookie:
36
+ - trk=cf6cb9b6-d933-4f78-8e5d-f2d19950f19a; Path=/; Max-Age=31536000; HttpOnly;
37
+ Secure; SameSite=None
38
+ Strict-Transport-Security:
39
+ - max-age=31536000; includeSubDomains; preload
40
+ X-Bolt-Api-Version:
41
+ - '2022-01-01'
42
+ X-Bolt-Trace-Id:
43
+ - Root=1-62877b69-482e58ce1eedfd33280bc676
44
+ X-Device-Id:
45
+ - 232d6cca3392e0cae61de13548ef4414540876c1554215312b6303539da28439
46
+ X-Envoy-Upstream-Service-Time:
47
+ - '20'
48
+ Server:
49
+ - envoy
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"profile":{"first_name":"Danny","last_name":"dove","email":"dannydove+bolt3@gmail.com","phone":"987654321","name":"Danny
53
+ dove"},"addresses":[{"id":"SA98t82gH2Grd","street_address1":"380 DEGRAW
54
+ ST","locality":"Brooklyn","region":"NEW YORK","region_code":"NY","postal_code":"11231","country_code":"US","name":"Danny
55
+ dove","first_name":"Danny","last_name":"dove","default":true}],"payment_methods":[{"id":"CA3tqG8Xg2RwS","type":"card","last4":"1111","network":"visa","default":true,"exp_month":11,"exp_year":2022}],"has_bolt_account":true}'
56
+ recorded_at: Fri, 20 May 2022 11:28:41 GMT
57
+ - request:
58
+ method: get
59
+ uri: https://api-sandbox.bolt.com/v1/account
60
+ body:
61
+ encoding: US-ASCII
62
+ string: ''
63
+ headers:
64
+ Authorization:
65
+ - "<BEARER AUTHORIZATION>"
66
+ X-Api-Key:
67
+ - "<API_KEY>"
68
+ Accept-Encoding:
69
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
70
+ Accept:
71
+ - "*/*"
72
+ User-Agent:
73
+ - Ruby
74
+ response:
75
+ status:
76
+ code: 200
77
+ message: OK
78
+ headers:
79
+ Date:
80
+ - Fri, 20 May 2022 11:28:42 GMT
81
+ Content-Type:
82
+ - application/json; charset=UTF-8
83
+ Content-Length:
84
+ - '568'
85
+ Connection:
86
+ - keep-alive
87
+ Public-Key-Pins-Report-Only:
88
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
89
+ Set-Cookie:
90
+ - trk=86009b52-071c-4a79-86fe-5e4bfc1b409f; Path=/; Max-Age=31536000; HttpOnly;
91
+ Secure; SameSite=None
92
+ Strict-Transport-Security:
93
+ - max-age=31536000; includeSubDomains; preload
94
+ X-Bolt-Api-Version:
95
+ - '2022-01-01'
96
+ X-Bolt-Trace-Id:
97
+ - Root=1-62877b6a-05e806ee316c5e56744992b0
98
+ X-Device-Id:
99
+ - 153b3dee1dbffff3eaae03a6d0f112b66dc4fd00ab84744e1f5c7d6d5cfd9638
100
+ X-Envoy-Upstream-Service-Time:
101
+ - '18'
102
+ Server:
103
+ - envoy
104
+ body:
105
+ encoding: UTF-8
106
+ string: '{"profile":{"first_name":"Danny","last_name":"dove","email":"dannydove+bolt3@gmail.com","phone":"987654321","name":"Danny
107
+ dove"},"addresses":[{"id":"SA98t82gH2Grd","street_address1":"380 DEGRAW
108
+ ST","locality":"Brooklyn","region":"NEW YORK","region_code":"NY","postal_code":"11231","country_code":"US","name":"Danny
109
+ dove","first_name":"Danny","last_name":"dove","default":true}],"payment_methods":[{"id":"CA3tqG8Xg2RwS","type":"card","last4":"1111","network":"visa","default":true,"exp_month":11,"exp_year":2022}],"has_bolt_account":true}'
110
+ recorded_at: Fri, 20 May 2022 11:28:42 GMT
111
+ - request:
112
+ method: get
113
+ uri: https://api-sandbox.bolt.com/v1/account
114
+ body:
115
+ encoding: US-ASCII
116
+ string: ''
117
+ headers:
118
+ Authorization:
119
+ - "<BEARER AUTHORIZATION>"
120
+ X-Api-Key:
121
+ - "<API_KEY>"
122
+ Accept-Encoding:
123
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
124
+ Accept:
125
+ - "*/*"
126
+ User-Agent:
127
+ - Ruby
128
+ response:
129
+ status:
130
+ code: 200
131
+ message: OK
132
+ headers:
133
+ Date:
134
+ - Fri, 20 May 2022 11:28:43 GMT
135
+ Content-Type:
136
+ - application/json; charset=UTF-8
137
+ Content-Length:
138
+ - '568'
139
+ Connection:
140
+ - keep-alive
141
+ Public-Key-Pins-Report-Only:
142
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
143
+ Set-Cookie:
144
+ - trk=55c667e7-7b06-43c8-a906-833e8f45dfd3; Path=/; Max-Age=31536000; HttpOnly;
145
+ Secure; SameSite=None
146
+ Strict-Transport-Security:
147
+ - max-age=31536000; includeSubDomains; preload
148
+ X-Bolt-Api-Version:
149
+ - '2022-01-01'
150
+ X-Bolt-Trace-Id:
151
+ - Root=1-62877b6b-6bc426ab5c474b924918d47f
152
+ X-Device-Id:
153
+ - bd3005f3649758fc88a8be35bac4386cd0496fa234aa1850ccc4886a88636192
154
+ X-Envoy-Upstream-Service-Time:
155
+ - '74'
156
+ Server:
157
+ - envoy
158
+ body:
159
+ encoding: UTF-8
160
+ string: '{"profile":{"first_name":"Danny","last_name":"dove","email":"dannydove+bolt3@gmail.com","phone":"987654321","name":"Danny
161
+ dove"},"addresses":[{"id":"SA98t82gH2Grd","street_address1":"380 DEGRAW
162
+ ST","locality":"Brooklyn","region":"NEW YORK","region_code":"NY","postal_code":"11231","country_code":"US","name":"Danny
163
+ dove","first_name":"Danny","last_name":"dove","default":true}],"payment_methods":[{"id":"CA3tqG8Xg2RwS","type":"card","last4":"1111","network":"visa","default":true,"exp_month":11,"exp_year":2022}],"has_bolt_account":true}'
164
+ recorded_at: Fri, 20 May 2022 11:28:43 GMT
165
+ recorded_with: VCR 6.1.0
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api-sandbox.bolt.com/v1/account
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - "<BEARER AUTHORIZATION>"
12
+ X-Api-Key:
13
+ - "<API_KEY>"
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Fri, 20 May 2022 00:52:42 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '301'
31
+ Connection:
32
+ - keep-alive
33
+ Public-Key-Pins-Report-Only:
34
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
35
+ Set-Cookie:
36
+ - trk=9f69895b-8b34-4f62-a508-f09650d5c4d2; Path=/; Max-Age=31536000; HttpOnly;
37
+ Secure; SameSite=None
38
+ Strict-Transport-Security:
39
+ - max-age=31536000; includeSubDomains; preload
40
+ X-Bolt-Api-Version:
41
+ - '2022-01-01'
42
+ X-Bolt-Trace-Id:
43
+ - Root=1-6286e65a-60b62fbb00698d3507bec285
44
+ X-Device-Id:
45
+ - b14d37786ac06e9df121d6418689d1ee7f8472e4116cd32892f2e29ad103bc71
46
+ X-Envoy-Upstream-Service-Time:
47
+ - '73'
48
+ Server:
49
+ - envoy
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"profile":{"first_name":"asdasd","last_name":"fsfasdf","email":"paulodalberti@nebulab.com","phone":"","name":"asdasd
53
+ fsfasdf"},"addresses":[],"payment_methods":[{"id":"CAgP9uNSEZBNL","type":"card","last4":"1111","network":"visa","default":true,"exp_month":4,"exp_year":2098}],"has_bolt_account":true}'
54
+ recorded_at: Fri, 20 May 2022 00:52:44 GMT
55
+ recorded_with: VCR 6.1.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api-sandbox.bolt.com/v1/webhooks
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"division_id":"<DIVISION_ID>","url":"https://solidus-test.com/webhook","event_group":"all"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ X-Api-Key:
13
+ - "<API_KEY>"
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Mon, 30 May 2022 06:40:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '42'
31
+ Connection:
32
+ - keep-alive
33
+ Public-Key-Pins-Report-Only:
34
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
35
+ Set-Cookie:
36
+ - trk=9742bdaf-7e16-43c2-b7c3-a12cce85e013; Path=/; Max-Age=31536000; HttpOnly;
37
+ Secure; SameSite=None
38
+ Strict-Transport-Security:
39
+ - max-age=31536000; includeSubDomains; preload
40
+ X-Bolt-Api-Version:
41
+ - '2022-01-01'
42
+ X-Bolt-Trace-Id:
43
+ - Root=1-629466fa-37572ceb2fe4e9703b906e26
44
+ X-Device-Id:
45
+ - 542aff933313830b6744d12044d88da43f24e0b8340d27cba2b20042b8db573e
46
+ X-Envoy-Upstream-Service-Time:
47
+ - '32'
48
+ Server:
49
+ - envoy
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"webhook_id":"wh_gZ66XAVPSCCtT1RoyfsfmQ"}'
53
+ recorded_at: Mon, 30 May 2022 06:40:58 GMT
54
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api-sandbox.bolt.com/v1/webhooks
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"division_id":"<DIVISION_ID>","url":"https://solidus-test.com/webhook","events":["payment"]}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ X-Api-Key:
13
+ - "<API_KEY>"
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Mon, 30 May 2022 06:41:00 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '42'
31
+ Connection:
32
+ - keep-alive
33
+ Public-Key-Pins-Report-Only:
34
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
35
+ Set-Cookie:
36
+ - trk=3caa327c-713b-4181-bb44-c70b2bd28879; Path=/; Max-Age=31536000; HttpOnly;
37
+ Secure; SameSite=None
38
+ Strict-Transport-Security:
39
+ - max-age=31536000; includeSubDomains; preload
40
+ X-Bolt-Api-Version:
41
+ - '2022-01-01'
42
+ X-Bolt-Trace-Id:
43
+ - Root=1-629466fc-6a1a26e62e7eba6d1e9fd926
44
+ X-Device-Id:
45
+ - ed5e4fe47f4b0686fc249cfe6f9f08243e143eba2c60368002d0101c80daf6aa
46
+ X-Envoy-Upstream-Service-Time:
47
+ - '14'
48
+ Server:
49
+ - envoy
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"webhook_id":"wh_B6Lj6FMNQUCHNuC4UP0AOA"}'
53
+ recorded_at: Mon, 30 May 2022 06:41:00 GMT
54
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api-sandbox.bolt.com/v1/webhooks
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"division_id":"<DIVISION_ID>","url":"https://solidus-test.com/webhook","events":[""]}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ X-Api-Key:
13
+ - "<API_KEY>"
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 500
23
+ message: Internal Server Error
24
+ headers:
25
+ Date:
26
+ - Mon, 30 May 2022 06:49:56 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '78'
31
+ Connection:
32
+ - keep-alive
33
+ Public-Key-Pins-Report-Only:
34
+ - max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
35
+ Set-Cookie:
36
+ - trk=a1dcbe7a-d888-44ae-9df2-b47a4cb8d16c; Path=/; Max-Age=31536000; HttpOnly;
37
+ Secure; SameSite=None
38
+ Strict-Transport-Security:
39
+ - max-age=31536000; includeSubDomains; preload
40
+ X-Bolt-Api-Version:
41
+ - '2022-01-01'
42
+ X-Bolt-Error-Code:
43
+ - '46'
44
+ X-Bolt-Trace-Id:
45
+ - Root=1-62946914-0bc27d70587a2f0b31b3cf53
46
+ X-Device-Id:
47
+ - b55bddc15664c262f06e79dc80b7b430f020049b23c99d1b3a9220dea1d12d8b
48
+ X-Envoy-Upstream-Service-Time:
49
+ - '10'
50
+ Server:
51
+ - envoy
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"result":{"success":false},"errors":[{"code":46,"message":"Internal
55
+ error"}]}'
56
+ recorded_at: Mon, 30 May 2022 06:49:56 GMT
57
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SolidusBolt::AddAddressJob do
4
+ subject(:add_address_job) { described_class.perform_now(order: order, access_token: access_token, address: address) }
5
+
6
+ let(:order) { build(:order) }
7
+ let(:address) { build(:address) }
8
+ let(:access_token) { 'accesstoken' }
9
+
10
+ before { allow(SolidusBolt::Accounts::AddAddressService).to receive(:call) }
11
+
12
+ it 'calls the AddAddressService' do
13
+ add_address_job
14
+ expect(SolidusBolt::Accounts::AddAddressService).to have_received(:call).with(
15
+ order: order, access_token: access_token, address: address
16
+ )
17
+ end
18
+ end
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SolidusBolt::BoltConfiguration, type: :model do
4
+ let(:column_list) {
5
+ [
6
+ 'id',
7
+ 'bearer_token',
8
+ 'environment',
9
+ 'merchant_public_id',
10
+ 'division_public_id',
11
+ 'api_key',
12
+ 'signing_secret',
13
+ 'publishable_key',
14
+ 'created_at',
15
+ 'updated_at'
16
+ ]
17
+ }
18
+
19
+ describe '.fetch' do
20
+ it 'fetches the correct record' do
21
+ bolt_configuration = create(:bolt_configuration)
22
+ expect(described_class.fetch).to eq(bolt_configuration)
23
+ end
24
+
25
+ it 'creates a bolt record when no record is present' do
26
+ expect { described_class.fetch }.to change(described_class, :count).by(1)
27
+ end
28
+ end
29
+
30
+ describe '.can_create?' do
31
+ it 'returns true when no records are present' do
32
+ expect(described_class).to be_can_create
33
+ end
34
+
35
+ it 'returns false when records are present' do
36
+ create(:bolt_configuration)
37
+ expect(described_class).not_to be_can_create
38
+ end
39
+ end
40
+
41
+ describe '.config_empty?' do
42
+ it 'is true for a new empty record' do
43
+ described_class.fetch
44
+ expect(described_class).to be_config_empty
45
+ end
46
+
47
+ it 'is true for a record with empty fields' do
48
+ create(
49
+ :bolt_configuration,
50
+ bearer_token: '',
51
+ merchant_public_id: '',
52
+ division_public_id: '',
53
+ api_key: '',
54
+ signing_secret: '',
55
+ publishable_key: ''
56
+ )
57
+ expect(described_class).to be_config_empty
58
+ end
59
+
60
+ it 'is false for a record with data' do
61
+ create(:bolt_configuration)
62
+ expect(described_class).not_to be_config_empty
63
+ end
64
+ end
65
+
66
+ describe '#environment_url' do
67
+ context 'when production envornment' do
68
+ let(:config) { create(:bolt_configuration, environment: 'production') }
69
+
70
+ it { expect(config.environment_url).to eq('https://api.bolt.com') }
71
+ end
72
+
73
+ context 'when sandbox envornment' do
74
+ let(:config) { create(:bolt_configuration) }
75
+
76
+ it { expect(config.environment_url).to eq('https://api-sandbox.bolt.com') }
77
+ end
78
+
79
+ context 'when staging envornment' do
80
+ let(:config) { create(:bolt_configuration, environment: 'staging') }
81
+
82
+ it { expect(config.environment_url).to eq('https://api-staging.bolt.com') }
83
+ end
84
+ end
85
+
86
+ describe '#embed_js' do
87
+ context 'when production envornment' do
88
+ let(:config) { create(:bolt_configuration, environment: 'production') }
89
+
90
+ it { expect(config.embed_js).to eq('https://connect.bolt.com/embed.js') }
91
+ end
92
+
93
+ context 'when sandbox envornment' do
94
+ let(:config) { create(:bolt_configuration) }
95
+
96
+ it { expect(config.embed_js).to eq('https://connect-sandbox.bolt.com/embed.js') }
97
+ end
98
+
99
+ context 'when staging envornment' do
100
+ let(:config) { create(:bolt_configuration, environment: 'staging') }
101
+
102
+ it { expect(config.embed_js).to eq('https://connect-sandbox.bolt.com/embed.js') }
103
+ end
104
+
105
+ context 'when initialized for the first time' do
106
+ described_class.destroy_all
107
+ let(:config) { described_class.fetch }
108
+
109
+ it { expect(config.embed_js).to eq('https://connect-sandbox.bolt.com/embed.js') }
110
+ end
111
+ end
112
+
113
+ describe '#account_js' do
114
+ context 'when production environment' do
115
+ let(:config) { create(:bolt_configuration, environment: 'production') }
116
+
117
+ it { expect(config.account_js).to eq('https://connect.bolt.com/account.js') }
118
+ end
119
+
120
+ context 'when sandbox environment' do
121
+ let(:config) { create(:bolt_configuration) }
122
+
123
+ it { expect(config.account_js).to eq('https://connect-sandbox.bolt.com/account.js') }
124
+ end
125
+
126
+ context 'when staging environment' do
127
+ let(:config) { create(:bolt_configuration, environment: 'staging') }
128
+
129
+ it { expect(config.account_js).to eq('https://connect-sandbox.bolt.com/account.js') }
130
+ end
131
+ end
132
+
133
+ describe 'validations' do
134
+ it 'raises an error when there is an existing record and a new record is created' do
135
+ create(:bolt_configuration)
136
+
137
+ expect {
138
+ create(:bolt_configuration)
139
+ }.to raise_error(ActiveRecord::RecordInvalid,
140
+ 'Validation failed: Can create only one record for this Model')
141
+ end
142
+
143
+ it 'adds an error on :base when there is an existing record and a new record is created' do
144
+ create(:bolt_configuration)
145
+
146
+ expect(described_class.create.errors).to include(:base)
147
+ end
148
+
149
+ it 'gives a specific error message when there is an existing record and a new record is created' do
150
+ create(:bolt_configuration)
151
+
152
+ expect(described_class.create.errors[:base]).to include('Can create only one record for this Model')
153
+ end
154
+
155
+ it 'successfully creates a new record when no records are present' do
156
+ expect { create(:bolt_configuration) }.to change(described_class, :count).by(1)
157
+ end
158
+ end
159
+
160
+ describe 'after commit actions' do
161
+ let(:config) {
162
+ Spree::Config.static_model_preferences.for_class(SolidusBolt::PaymentMethod)['bolt_config_credentials']
163
+ }
164
+
165
+ it 'updates the Static Preferences of SolidusBolt::PaymentMethod' do
166
+ create(:bolt_configuration)
167
+ expect(config.fetch(:bolt_api_key)).to eq described_class.fetch.api_key
168
+
169
+ described_class.fetch.update(environment: 'production')
170
+ expect(config.fetch(:bolt_api_key)).to eq described_class.fetch.api_key
171
+ end
172
+ end
173
+ end