braintree 2.98.0 → 4.23.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 (308) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree/account_updater_daily_report.rb +4 -4
  5. data/lib/braintree/ach_mandate.rb +1 -1
  6. data/lib/braintree/add_on_gateway.rb +1 -1
  7. data/lib/braintree/address.rb +7 -27
  8. data/lib/braintree/address_gateway.rb +8 -7
  9. data/lib/braintree/advanced_search.rb +11 -12
  10. data/lib/braintree/apple_pay.rb +4 -4
  11. data/lib/braintree/apple_pay_card.rb +18 -4
  12. data/lib/braintree/apple_pay_options.rb +4 -4
  13. data/lib/braintree/authorization_adjustment.rb +4 -4
  14. data/lib/braintree/base_module.rb +11 -1
  15. data/lib/braintree/bin_data.rb +10 -3
  16. data/lib/braintree/client_token.rb +1 -1
  17. data/lib/braintree/client_token_gateway.rb +4 -3
  18. data/lib/braintree/configuration.rb +35 -35
  19. data/lib/braintree/connected_merchant_paypal_status_changed.rb +2 -2
  20. data/lib/braintree/connected_merchant_status_transitioned.rb +2 -2
  21. data/lib/braintree/credit_card.rb +40 -86
  22. data/lib/braintree/credit_card_gateway.rb +58 -44
  23. data/lib/braintree/credit_card_verification.rb +39 -20
  24. data/lib/braintree/credit_card_verification_gateway.rb +35 -5
  25. data/lib/braintree/credit_card_verification_search.rb +2 -2
  26. data/lib/braintree/customer.rb +23 -88
  27. data/lib/braintree/customer_gateway.rb +17 -32
  28. data/lib/braintree/customer_search.rb +2 -2
  29. data/lib/braintree/descriptor.rb +1 -1
  30. data/lib/braintree/digest.rb +1 -1
  31. data/lib/braintree/disbursement.rb +7 -7
  32. data/lib/braintree/discount_gateway.rb +1 -1
  33. data/lib/braintree/dispute/evidence.rb +1 -1
  34. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  35. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  36. data/lib/braintree/dispute/transaction.rb +3 -1
  37. data/lib/braintree/dispute/transaction_details.rb +1 -1
  38. data/lib/braintree/dispute.rb +47 -6
  39. data/lib/braintree/dispute_gateway.rb +5 -10
  40. data/lib/braintree/dispute_search.rb +8 -4
  41. data/lib/braintree/document_upload.rb +3 -3
  42. data/lib/braintree/document_upload_gateway.rb +3 -3
  43. data/lib/braintree/enriched_customer_data.rb +21 -0
  44. data/lib/braintree/error_codes.rb +217 -175
  45. data/lib/braintree/error_result.rb +2 -3
  46. data/lib/braintree/errors.rb +3 -3
  47. data/lib/braintree/exceptions.rb +6 -5
  48. data/lib/braintree/exchange_rate.rb +13 -0
  49. data/lib/braintree/exchange_rate_quote.rb +24 -0
  50. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  51. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  52. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  53. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  54. data/lib/braintree/facilitated_details.rb +1 -1
  55. data/lib/braintree/facilitator_details.rb +1 -1
  56. data/lib/braintree/gateway.rb +6 -12
  57. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +18 -5
  58. data/lib/braintree/granted_payment_instrument_update.rb +2 -2
  59. data/lib/braintree/graphql_client.rb +14 -8
  60. data/lib/braintree/http.rb +9 -10
  61. data/lib/braintree/local_payment_completed/blik_alias.rb +23 -0
  62. data/lib/braintree/local_payment_completed.rb +10 -5
  63. data/lib/braintree/local_payment_expired.rb +21 -0
  64. data/lib/braintree/local_payment_funded.rb +22 -0
  65. data/lib/braintree/local_payment_reversed.rb +19 -0
  66. data/lib/braintree/merchant.rb +4 -4
  67. data/lib/braintree/merchant_account.rb +3 -3
  68. data/lib/braintree/merchant_account_gateway.rb +10 -8
  69. data/lib/braintree/merchant_gateway.rb +1 -1
  70. data/lib/braintree/meta_checkout_card.rb +89 -0
  71. data/lib/braintree/meta_checkout_token.rb +88 -0
  72. data/lib/braintree/modification.rb +4 -4
  73. data/lib/braintree/oauth_credentials.rb +4 -4
  74. data/lib/braintree/oauth_gateway.rb +5 -5
  75. data/lib/braintree/paginated_collection.rb +2 -2
  76. data/lib/braintree/paginated_result.rb +1 -1
  77. data/lib/braintree/payment_instrument_type.rb +14 -13
  78. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  79. data/lib/braintree/payment_method_gateway.rb +52 -22
  80. data/lib/braintree/payment_method_nonce.rb +12 -7
  81. data/lib/braintree/payment_method_nonce_details.rb +40 -0
  82. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  83. data/lib/braintree/payment_method_nonce_gateway.rb +14 -3
  84. data/lib/braintree/payment_method_parser.rb +4 -7
  85. data/lib/braintree/paypal_account.rb +3 -2
  86. data/lib/braintree/paypal_account_gateway.rb +5 -5
  87. data/lib/braintree/plan.rb +22 -2
  88. data/lib/braintree/plan_gateway.rb +101 -1
  89. data/lib/braintree/processor_response_types.rb +3 -3
  90. data/lib/braintree/resource_collection.rb +10 -5
  91. data/lib/braintree/revoked_payment_method_metadata.rb +2 -2
  92. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  93. data/lib/braintree/risk_data.rb +10 -3
  94. data/lib/braintree/samsung_pay_card.rb +8 -6
  95. data/lib/braintree/sepa_direct_debit_account.rb +60 -0
  96. data/lib/braintree/sepa_direct_debit_account_gateway.rb +25 -0
  97. data/lib/braintree/sepa_direct_debit_account_nonce_details.rb +28 -0
  98. data/lib/braintree/settlement_batch_summary.rb +2 -2
  99. data/lib/braintree/settlement_batch_summary_gateway.rb +1 -1
  100. data/lib/braintree/sha256_digest.rb +1 -1
  101. data/lib/braintree/subscription/status_details.rb +1 -1
  102. data/lib/braintree/subscription.rb +13 -13
  103. data/lib/braintree/subscription_gateway.rb +6 -6
  104. data/lib/braintree/subscription_search.rb +1 -1
  105. data/lib/braintree/successful_result.rb +5 -4
  106. data/lib/braintree/test/authentication_id.rb +21 -0
  107. data/lib/braintree/test/credit_card.rb +9 -10
  108. data/lib/braintree/test/merchant_account.rb +1 -1
  109. data/lib/braintree/test/nonce.rb +27 -20
  110. data/lib/braintree/test/transaction_amounts.rb +2 -3
  111. data/lib/braintree/test/venmo_sdk.rb +2 -0
  112. data/lib/braintree/testing_gateway.rb +1 -1
  113. data/lib/braintree/three_d_secure_info.rb +23 -11
  114. data/lib/braintree/transaction/address_details.rb +14 -1
  115. data/lib/braintree/transaction/apple_pay_details.rb +13 -10
  116. data/lib/braintree/transaction/credit_card_details.rb +8 -1
  117. data/lib/braintree/transaction/customer_details.rb +3 -2
  118. data/lib/braintree/transaction/disbursement_details.rb +2 -1
  119. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +6 -1
  120. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  121. data/lib/braintree/transaction/installment.rb +28 -0
  122. data/lib/braintree/transaction/local_payment_details.rb +3 -0
  123. data/lib/braintree/transaction/meta_checkout_card_details.rb +52 -0
  124. data/lib/braintree/transaction/meta_checkout_token_details.rb +54 -0
  125. data/lib/braintree/transaction/package_details.rb +19 -0
  126. data/lib/braintree/transaction/payment_receipt/card_present_data.rb +36 -0
  127. data/lib/braintree/transaction/payment_receipt/merchant_address.rb +19 -0
  128. data/lib/braintree/transaction/payment_receipt.rb +31 -0
  129. data/lib/braintree/transaction/paypal_details.rb +5 -0
  130. data/lib/braintree/transaction/samsung_pay_card_details.rb +3 -1
  131. data/lib/braintree/transaction/sepa_direct_debit_account_details.rb +27 -0
  132. data/lib/braintree/transaction/status_details.rb +1 -1
  133. data/lib/braintree/transaction/subscription_details.rb +3 -1
  134. data/lib/braintree/transaction/us_bank_account_details.rb +2 -1
  135. data/lib/braintree/transaction/visa_checkout_card_details.rb +1 -1
  136. data/lib/braintree/transaction.rb +119 -128
  137. data/lib/braintree/transaction_gateway.rb +138 -64
  138. data/lib/braintree/transaction_line_item.rb +14 -11
  139. data/lib/braintree/transaction_line_item_gateway.rb +1 -1
  140. data/lib/braintree/transaction_review.rb +18 -0
  141. data/lib/braintree/transaction_search.rb +11 -7
  142. data/lib/braintree/unknown_payment_method.rb +2 -2
  143. data/lib/braintree/us_bank_account.rb +5 -5
  144. data/lib/braintree/us_bank_account_verification.rb +24 -16
  145. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  146. data/lib/braintree/us_bank_account_verification_search.rb +1 -1
  147. data/lib/braintree/util.rb +25 -10
  148. data/lib/braintree/validation_error.rb +1 -1
  149. data/lib/braintree/validation_error_collection.rb +3 -3
  150. data/lib/braintree/venmo_account.rb +4 -4
  151. data/lib/braintree/venmo_profile_data.rb +25 -0
  152. data/lib/braintree/version.rb +2 -2
  153. data/lib/braintree/visa_checkout_card.rb +8 -8
  154. data/lib/braintree/webhook_notification.rb +55 -33
  155. data/lib/braintree/webhook_notification_gateway.rb +9 -9
  156. data/lib/braintree/webhook_testing.rb +1 -1
  157. data/lib/braintree/webhook_testing_gateway.rb +569 -46
  158. data/lib/braintree/xml/generator.rb +6 -5
  159. data/lib/braintree/xml/libxml.rb +1 -1
  160. data/lib/braintree/xml/parser.rb +24 -37
  161. data/lib/braintree/xml/rexml.rb +6 -7
  162. data/lib/braintree/xml.rb +1 -1
  163. data/lib/braintree.rb +41 -24
  164. data/lib/ssl/api_braintreegateway_com.ca.crt +401 -168
  165. data/spec/integration/braintree/add_on_spec.rb +10 -10
  166. data/spec/integration/braintree/address_spec.rb +101 -178
  167. data/spec/integration/braintree/advanced_search_spec.rb +93 -93
  168. data/spec/integration/braintree/apple_pay_spec.rb +12 -12
  169. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  170. data/spec/integration/braintree/client_api/client_token_spec.rb +279 -62
  171. data/spec/integration/braintree/client_api/spec_helper.rb +99 -73
  172. data/spec/integration/braintree/credit_card_spec.rb +522 -821
  173. data/spec/integration/braintree/credit_card_verification_search_spec.rb +18 -18
  174. data/spec/integration/braintree/credit_card_verification_spec.rb +219 -30
  175. data/spec/integration/braintree/customer_search_spec.rb +28 -28
  176. data/spec/integration/braintree/customer_spec.rb +840 -757
  177. data/spec/integration/braintree/disbursement_spec.rb +2 -2
  178. data/spec/integration/braintree/discount_spec.rb +9 -9
  179. data/spec/integration/braintree/dispute_search_spec.rb +45 -9
  180. data/spec/integration/braintree/dispute_spec.rb +109 -82
  181. data/spec/integration/braintree/document_upload_spec.rb +29 -17
  182. data/spec/integration/braintree/error_codes_spec.rb +3 -3
  183. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  184. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  185. data/spec/integration/braintree/http_spec.rb +31 -33
  186. data/spec/integration/braintree/merchant_account_spec.rb +155 -156
  187. data/spec/integration/braintree/merchant_spec.rb +71 -192
  188. data/spec/integration/braintree/oauth_spec.rb +72 -72
  189. data/spec/integration/braintree/package_tracking_spec.rb +130 -0
  190. data/spec/integration/braintree/payment_method_nonce_spec.rb +173 -78
  191. data/spec/integration/braintree/payment_method_spec.rb +953 -501
  192. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +147 -234
  193. data/spec/integration/braintree/paypal_account_spec.rb +74 -72
  194. data/spec/integration/braintree/plan_spec.rb +96 -15
  195. data/spec/integration/braintree/samsung_pay_card_spec.rb +75 -73
  196. data/spec/integration/braintree/sepa_direct_debit_account_spec.rb +194 -0
  197. data/spec/integration/braintree/settlement_batch_summary_spec.rb +18 -18
  198. data/spec/integration/braintree/subscription_spec.rb +507 -513
  199. data/spec/integration/braintree/test/transaction_amounts_spec.rb +4 -4
  200. data/spec/integration/braintree/test_transaction_spec.rb +29 -29
  201. data/spec/integration/braintree/transaction_line_item_spec.rb +12 -6
  202. data/spec/integration/braintree/transaction_search_spec.rb +410 -217
  203. data/spec/integration/braintree/transaction_spec.rb +3252 -2102
  204. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +42 -278
  205. data/spec/integration/braintree/us_bank_account_spec.rb +36 -36
  206. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +25 -25
  207. data/spec/integration/braintree/us_bank_account_verification_spec.rb +41 -41
  208. data/spec/integration/braintree/visa_checkout_card_spec.rb +62 -62
  209. data/spec/integration/spec_helper.rb +22 -7
  210. data/spec/oauth_test_helper.rb +1 -1
  211. data/spec/script/httpsd.rb +6 -6
  212. data/spec/spec_helper.rb +15 -20
  213. data/spec/unit/braintree/address_spec.rb +9 -17
  214. data/spec/unit/braintree/apple_pay_card_spec.rb +110 -7
  215. data/spec/unit/braintree/base_module_spec.rb +4 -4
  216. data/spec/unit/braintree/client_token_spec.rb +6 -6
  217. data/spec/unit/braintree/configuration_spec.rb +84 -84
  218. data/spec/unit/braintree/credentials_parser_spec.rb +6 -6
  219. data/spec/unit/braintree/credit_card_spec.rb +91 -58
  220. data/spec/unit/braintree/credit_card_verification_gateway_spec.rb +56 -0
  221. data/spec/unit/braintree/credit_card_verification_search_spec.rb +10 -10
  222. data/spec/unit/braintree/credit_card_verification_spec.rb +40 -18
  223. data/spec/unit/braintree/customer_spec.rb +102 -57
  224. data/spec/unit/braintree/digest_spec.rb +5 -6
  225. data/spec/unit/braintree/disbursement_spec.rb +14 -14
  226. data/spec/unit/braintree/dispute_search_spec.rb +6 -2
  227. data/spec/unit/braintree/dispute_spec.rb +144 -66
  228. data/spec/unit/braintree/document_upload_spec.rb +8 -8
  229. data/spec/unit/braintree/enriched_customer_data_spec.rb +41 -0
  230. data/spec/unit/braintree/error_result_spec.rb +11 -11
  231. data/spec/unit/braintree/errors_spec.rb +17 -17
  232. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  233. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  234. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  235. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  236. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  237. data/spec/unit/braintree/http_spec.rb +19 -17
  238. data/spec/unit/braintree/local_payment_completed_spec.rb +62 -8
  239. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  240. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  241. data/spec/unit/braintree/merchant_account_spec.rb +5 -5
  242. data/spec/unit/braintree/meta_checkout_card_details_spec.rb +60 -0
  243. data/spec/unit/braintree/meta_checkout_card_spec.rb +60 -0
  244. data/spec/unit/braintree/meta_checkout_token_details_spec.rb +63 -0
  245. data/spec/unit/braintree/meta_checkout_token_spec.rb +63 -0
  246. data/spec/unit/braintree/modification_spec.rb +1 -1
  247. data/spec/unit/braintree/package_tracking_spec.rb +77 -0
  248. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  249. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  250. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +51 -0
  251. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  252. data/spec/unit/braintree/payment_method_spec.rb +20 -20
  253. data/spec/unit/braintree/paypal_account_spec.rb +16 -7
  254. data/spec/unit/braintree/resource_collection_spec.rb +34 -5
  255. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  256. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  257. data/spec/unit/braintree/sepa_debit_account_nonce_details_spec.rb +29 -0
  258. data/spec/unit/braintree/sepa_debit_account_spec.rb +86 -0
  259. data/spec/unit/braintree/sha256_digest_spec.rb +1 -1
  260. data/spec/unit/braintree/signature_service_spec.rb +2 -2
  261. data/spec/unit/braintree/subscription_search_spec.rb +18 -18
  262. data/spec/unit/braintree/subscription_spec.rb +8 -8
  263. data/spec/unit/braintree/successful_result_spec.rb +6 -6
  264. data/spec/unit/braintree/three_d_secure_info_spec.rb +37 -17
  265. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +22 -6
  266. data/spec/unit/braintree/transaction/customer_details_spec.rb +3 -2
  267. data/spec/unit/braintree/transaction/deposit_details_spec.rb +4 -4
  268. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  269. data/spec/unit/braintree/transaction/local_payment_details_spec.rb +36 -0
  270. data/spec/unit/braintree/transaction/payment_receipt_spec.rb +73 -0
  271. data/spec/unit/braintree/transaction/paypal_details_spec.rb +63 -0
  272. data/spec/unit/braintree/transaction/sepa_direct_debit_account_details_spec.rb +33 -0
  273. data/spec/unit/braintree/transaction_gateway_spec.rb +150 -0
  274. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  275. data/spec/unit/braintree/transaction_spec.rb +221 -124
  276. data/spec/unit/braintree/unknown_payment_method_spec.rb +4 -4
  277. data/spec/unit/braintree/us_bank_account_spec.rb +2 -2
  278. data/spec/unit/braintree/us_bank_account_verification_search_spec.rb +7 -7
  279. data/spec/unit/braintree/us_bank_account_verification_spec.rb +12 -7
  280. data/spec/unit/braintree/util_spec.rb +78 -44
  281. data/spec/unit/braintree/validation_error_collection_spec.rb +62 -62
  282. data/spec/unit/braintree/validation_error_spec.rb +4 -4
  283. data/spec/unit/braintree/venmo_profile_data_spec.rb +43 -0
  284. data/spec/unit/braintree/webhook_notification_spec.rb +434 -197
  285. data/spec/unit/braintree/xml/libxml_spec.rb +5 -5
  286. data/spec/unit/braintree/xml/parser_spec.rb +27 -22
  287. data/spec/unit/braintree/xml/rexml_spec.rb +5 -5
  288. data/spec/unit/braintree/xml_spec.rb +38 -38
  289. data/spec/unit/braintree_spec.rb +2 -2
  290. metadata +91 -30
  291. data/lib/braintree/amex_express_checkout_card.rb +0 -38
  292. data/lib/braintree/coinbase_account.rb +0 -34
  293. data/lib/braintree/europe_bank_account.rb +0 -36
  294. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  295. data/lib/braintree/ideal_payment.rb +0 -61
  296. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  297. data/lib/braintree/masterpass_card.rb +0 -81
  298. data/lib/braintree/settlement_batch.rb +0 -0
  299. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  300. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  301. data/lib/braintree/transaction/masterpass_card_details.rb +0 -47
  302. data/lib/braintree/transparent_redirect.rb +0 -40
  303. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  304. data/spec/hacks/tcp_socket.rb +0 -18
  305. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  306. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  307. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  308. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -5,129 +5,129 @@ describe Braintree::WebhookNotification do
5
5
  it "builds a sample notification and signature given an identifier and kind" do
6
6
  sample_notification = Braintree::WebhookTesting.sample_notification(
7
7
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
8
- "my_id"
8
+ "my_id",
9
9
  )
10
10
 
11
11
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
12
12
 
13
- notification.kind.should == Braintree::WebhookNotification::Kind::SubscriptionWentPastDue
14
- notification.subscription.id.should == "my_id"
15
- notification.timestamp.should be_within(10).of(Time.now.utc)
13
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubscriptionWentPastDue)
14
+ expect(notification.subscription.id).to eq("my_id")
15
+ expect(notification.timestamp).to be_within(10).of(Time.now.utc)
16
16
  end
17
17
 
18
18
  it "builds a sample notification for a partner merchant connected webhook" do
19
19
  sample_notification = Braintree::WebhookTesting.sample_notification(
20
20
  Braintree::WebhookNotification::Kind::PartnerMerchantConnected,
21
- "my_id"
21
+ "my_id",
22
22
  )
23
23
 
24
24
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
25
25
 
26
- notification.kind.should == Braintree::WebhookNotification::Kind::PartnerMerchantConnected
27
- notification.partner_merchant.merchant_public_id.should == "public_id"
28
- notification.partner_merchant.public_key.should == "public_key"
29
- notification.partner_merchant.private_key.should == "private_key"
30
- notification.partner_merchant.partner_merchant_id.should == "abc123"
31
- notification.partner_merchant.client_side_encryption_key.should == "cse_key"
32
- notification.timestamp.should be_within(10).of(Time.now.utc)
26
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::PartnerMerchantConnected)
27
+ expect(notification.partner_merchant.merchant_public_id).to eq("public_id")
28
+ expect(notification.partner_merchant.public_key).to eq("public_key")
29
+ expect(notification.partner_merchant.private_key).to eq("private_key")
30
+ expect(notification.partner_merchant.partner_merchant_id).to eq("abc123")
31
+ expect(notification.partner_merchant.client_side_encryption_key).to eq("cse_key")
32
+ expect(notification.timestamp).to be_within(10).of(Time.now.utc)
33
33
  end
34
34
 
35
35
  it "builds a sample notification for a partner merchant disconnected webhook" do
36
36
  sample_notification = Braintree::WebhookTesting.sample_notification(
37
37
  Braintree::WebhookNotification::Kind::PartnerMerchantDisconnected,
38
- "my_id"
38
+ "my_id",
39
39
  )
40
40
 
41
41
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
42
42
 
43
- notification.kind.should == Braintree::WebhookNotification::Kind::PartnerMerchantDisconnected
44
- notification.partner_merchant.partner_merchant_id.should == "abc123"
45
- notification.timestamp.should be_within(10).of(Time.now.utc)
43
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::PartnerMerchantDisconnected)
44
+ expect(notification.partner_merchant.partner_merchant_id).to eq("abc123")
45
+ expect(notification.timestamp).to be_within(10).of(Time.now.utc)
46
46
  end
47
47
 
48
48
  it "builds a sample notification for a partner merchant declined webhook" do
49
49
  sample_notification = Braintree::WebhookTesting.sample_notification(
50
50
  Braintree::WebhookNotification::Kind::PartnerMerchantDeclined,
51
- "my_id"
51
+ "my_id",
52
52
  )
53
53
 
54
54
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
55
55
 
56
- notification.kind.should == Braintree::WebhookNotification::Kind::PartnerMerchantDeclined
57
- notification.partner_merchant.partner_merchant_id.should == "abc123"
58
- notification.timestamp.should be_within(10).of(Time.now.utc)
56
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::PartnerMerchantDeclined)
57
+ expect(notification.partner_merchant.partner_merchant_id).to eq("abc123")
58
+ expect(notification.timestamp).to be_within(10).of(Time.now.utc)
59
59
  end
60
60
 
61
61
  it "builds a sample notification with a source merchant ID" do
62
62
  sample_notification = Braintree::WebhookTesting.sample_notification(
63
63
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
64
64
  "my_id",
65
- "my_source_merchant_id"
65
+ "my_source_merchant_id",
66
66
  )
67
67
 
68
68
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
69
69
 
70
- notification.source_merchant_id.should == "my_source_merchant_id"
70
+ expect(notification.source_merchant_id).to eq("my_source_merchant_id")
71
71
  end
72
72
 
73
73
  it "doesn't include source merchant IDs if not supplied" do
74
74
  sample_notification = Braintree::WebhookTesting.sample_notification(
75
75
  Braintree::WebhookNotification::Kind::PartnerMerchantDeclined,
76
- "my_id"
76
+ "my_id",
77
77
  )
78
78
 
79
79
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
80
80
 
81
- notification.source_merchant_id.should be_nil
81
+ expect(notification.source_merchant_id).to be_nil
82
82
  end
83
83
 
84
84
  context "auth" do
85
85
  it "builds a sample notification for a status transitioned webhook" do
86
86
  sample_notification = Braintree::WebhookTesting.sample_notification(
87
87
  Braintree::WebhookNotification::Kind::ConnectedMerchantStatusTransitioned,
88
- "my_id"
88
+ "my_id",
89
89
  )
90
90
 
91
91
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
92
92
 
93
- notification.kind.should == Braintree::WebhookNotification::Kind::ConnectedMerchantStatusTransitioned
93
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::ConnectedMerchantStatusTransitioned)
94
94
 
95
95
  status_transitioned = notification.connected_merchant_status_transitioned
96
- status_transitioned.merchant_public_id.should == "my_id"
97
- status_transitioned.merchant_id.should == "my_id"
98
- status_transitioned.oauth_application_client_id.should == "oauth_application_client_id"
99
- status_transitioned.status.should == "new_status"
96
+ expect(status_transitioned.merchant_public_id).to eq("my_id")
97
+ expect(status_transitioned.merchant_id).to eq("my_id")
98
+ expect(status_transitioned.oauth_application_client_id).to eq("oauth_application_client_id")
99
+ expect(status_transitioned.status).to eq("new_status")
100
100
  end
101
101
 
102
102
  it "builds a sample notification for a paypal status changed webhook" do
103
103
  sample_notification = Braintree::WebhookTesting.sample_notification(
104
104
  Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged,
105
- "my_id"
105
+ "my_id",
106
106
  )
107
107
 
108
108
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
109
109
 
110
- notification.kind.should == Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged
110
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged)
111
111
 
112
112
  paypal_status_changed = notification.connected_merchant_paypal_status_changed
113
- paypal_status_changed.merchant_public_id.should == "my_id"
114
- paypal_status_changed.merchant_id.should == "my_id"
115
- paypal_status_changed.oauth_application_client_id.should == "oauth_application_client_id"
116
- paypal_status_changed.action.should == "link"
113
+ expect(paypal_status_changed.merchant_public_id).to eq("my_id")
114
+ expect(paypal_status_changed.merchant_id).to eq("my_id")
115
+ expect(paypal_status_changed.oauth_application_client_id).to eq("oauth_application_client_id")
116
+ expect(paypal_status_changed.action).to eq("link")
117
117
  end
118
118
 
119
- it 'builds a sample notification for OAuth application revocation' do
119
+ it "builds a sample notification for OAuth application revocation" do
120
120
  sample_notification = Braintree::WebhookTesting.sample_notification(
121
121
  Braintree::WebhookNotification::Kind::OAuthAccessRevoked,
122
- 'my_id'
122
+ "my_id",
123
123
  )
124
124
 
125
125
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
126
126
 
127
- notification.kind.should == Braintree::WebhookNotification::Kind::OAuthAccessRevoked
128
- notification.oauth_access_revocation.merchant_id.should == "my_id"
129
- notification.oauth_access_revocation.oauth_application_client_id.should == "oauth_application_client_id"
130
- notification.timestamp.should be_within(10).of(Time.now.utc)
127
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::OAuthAccessRevoked)
128
+ expect(notification.oauth_access_revocation.merchant_id).to eq("my_id")
129
+ expect(notification.oauth_access_revocation.oauth_application_client_id).to eq("oauth_application_client_id")
130
+ expect(notification.timestamp).to be_within(10).of(Time.now.utc)
131
131
  end
132
132
 
133
133
  end
@@ -139,68 +139,148 @@ describe Braintree::WebhookNotification do
139
139
  it "builds a sample notification for a dispute opened webhook" do
140
140
  sample_notification = Braintree::WebhookTesting.sample_notification(
141
141
  Braintree::WebhookNotification::Kind::DisputeOpened,
142
- dispute_id
142
+ dispute_id,
143
143
  )
144
144
 
145
145
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
146
146
 
147
- notification.kind.should == Braintree::WebhookNotification::Kind::DisputeOpened
147
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeOpened)
148
148
 
149
149
  dispute = notification.dispute
150
- dispute.status.should == Braintree::Dispute::Status::Open
151
- dispute.id.should == dispute_id
152
- dispute.kind.should == Braintree::Dispute::Kind::Chargeback
150
+ expect(dispute.status).to eq(Braintree::Dispute::Status::Open)
151
+ expect(dispute.id).to eq(dispute_id)
152
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
153
153
  end
154
154
 
155
155
  it "builds a sample notification for a dispute lost webhook" do
156
156
  sample_notification = Braintree::WebhookTesting.sample_notification(
157
157
  Braintree::WebhookNotification::Kind::DisputeLost,
158
- dispute_id
158
+ dispute_id,
159
+ )
160
+
161
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
162
+
163
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeLost)
164
+
165
+ dispute = notification.dispute
166
+ expect(dispute.status).to eq(Braintree::Dispute::Status::Lost)
167
+ expect(dispute.id).to eq(dispute_id)
168
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
169
+ end
170
+
171
+ it "builds a sample notification for a dispute under_review webhook" do
172
+ sample_notification = Braintree::WebhookTesting.sample_notification(
173
+ Braintree::WebhookNotification::Kind::DisputeUnderReview,
174
+ dispute_id,
159
175
  )
160
176
 
161
177
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
162
178
 
163
- notification.kind.should == Braintree::WebhookNotification::Kind::DisputeLost
179
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeUnderReview)
164
180
 
165
181
  dispute = notification.dispute
166
- dispute.status.should == Braintree::Dispute::Status::Lost
167
- dispute.id.should == dispute_id
168
- dispute.kind.should == Braintree::Dispute::Kind::Chargeback
182
+ expect(dispute.status).to eq(Braintree::Dispute::Status::UnderReview)
183
+ expect(dispute.id).to eq(dispute_id)
184
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
169
185
  end
170
186
 
171
187
  it "builds a sample notification for a dispute won webhook" do
172
188
  sample_notification = Braintree::WebhookTesting.sample_notification(
173
189
  Braintree::WebhookNotification::Kind::DisputeWon,
174
- dispute_id
190
+ dispute_id,
175
191
  )
176
192
 
177
193
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
178
194
 
179
- notification.kind.should == Braintree::WebhookNotification::Kind::DisputeWon
195
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeWon)
180
196
 
181
197
  dispute = notification.dispute
182
- dispute.status.should == Braintree::Dispute::Status::Won
183
- dispute.id.should == dispute_id
184
- dispute.kind.should == Braintree::Dispute::Kind::Chargeback
198
+ expect(dispute.status).to eq(Braintree::Dispute::Status::Won)
199
+ expect(dispute.id).to eq(dispute_id)
200
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
201
+ end
202
+
203
+ it "builds a sample notification for a dispute accepted webhook" do
204
+ sample_notification = Braintree::WebhookTesting.sample_notification(
205
+ Braintree::WebhookNotification::Kind::DisputeAccepted,
206
+ dispute_id,
207
+ )
208
+
209
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
210
+
211
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeAccepted)
212
+
213
+ dispute = notification.dispute
214
+ expect(dispute.status).to eq(Braintree::Dispute::Status::Accepted)
215
+ expect(dispute.id).to eq(dispute_id)
216
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
217
+ end
218
+
219
+ it "builds a sample notification for a dispute auto_accepted webhook" do
220
+ sample_notification = Braintree::WebhookTesting.sample_notification(
221
+ Braintree::WebhookNotification::Kind::DisputeAutoAccepted,
222
+ dispute_id,
223
+ )
224
+
225
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
226
+
227
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeAutoAccepted)
228
+
229
+ dispute = notification.dispute
230
+ expect(dispute.status).to eq(Braintree::Dispute::Status::AutoAccepted)
231
+ expect(dispute.id).to eq(dispute_id)
232
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
233
+ end
234
+
235
+ it "builds a sample notification for a dispute disputed webhook" do
236
+ sample_notification = Braintree::WebhookTesting.sample_notification(
237
+ Braintree::WebhookNotification::Kind::DisputeDisputed,
238
+ dispute_id,
239
+ )
240
+
241
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
242
+
243
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeDisputed)
244
+
245
+ dispute = notification.dispute
246
+ expect(dispute.status).to eq(Braintree::Dispute::Status::Disputed)
247
+ expect(dispute.id).to eq(dispute_id)
248
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
249
+ end
250
+
251
+ it "builds a sample notification for a dispute expired webhook" do
252
+ sample_notification = Braintree::WebhookTesting.sample_notification(
253
+ Braintree::WebhookNotification::Kind::DisputeExpired,
254
+ dispute_id,
255
+ )
256
+
257
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
258
+
259
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeExpired)
260
+
261
+ dispute = notification.dispute
262
+ expect(dispute.status).to eq(Braintree::Dispute::Status::Expired)
263
+ expect(dispute.id).to eq(dispute_id)
264
+ expect(dispute.kind).to eq(Braintree::Dispute::Kind::Chargeback)
185
265
  end
186
266
 
187
267
  it "is compatible with the previous dispute won webhook interface" do
188
268
  sample_notification = Braintree::WebhookTesting.sample_notification(
189
269
  Braintree::WebhookNotification::Kind::DisputeWon,
190
- dispute_id
270
+ dispute_id,
191
271
  )
192
272
 
193
273
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
194
274
 
195
- notification.kind.should == Braintree::WebhookNotification::Kind::DisputeWon
275
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisputeWon)
196
276
 
197
277
  dispute = notification.dispute
198
- dispute.amount.should == 100.00
199
- dispute.id.should == dispute_id
200
- dispute.date_opened.should == Date.new(2014, 3, 21)
201
- dispute.date_won.should == Date.new(2014, 3, 22)
202
- dispute.transaction_details.amount.should == 100.00
203
- dispute.transaction_details.id.should == dispute_id
278
+ expect(dispute.amount).to eq(100.00)
279
+ expect(dispute.id).to eq(dispute_id)
280
+ expect(dispute.date_opened).to eq(Date.new(2014, 3, 21))
281
+ expect(dispute.date_won).to eq(Date.new(2014, 3, 22))
282
+ expect(dispute.transaction_details.amount).to eq(100.00)
283
+ expect(dispute.transaction_details.id).to eq(dispute_id)
204
284
  end
205
285
  end
206
286
 
@@ -219,53 +299,71 @@ describe Braintree::WebhookNotification do
219
299
  it "builds a sample notification for a transaction disbursed webhook" do
220
300
  sample_notification = Braintree::WebhookTesting.sample_notification(
221
301
  Braintree::WebhookNotification::Kind::TransactionDisbursed,
222
- "my_id"
302
+ "my_id",
223
303
  )
224
304
 
225
305
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
226
306
 
227
- notification.kind.should == Braintree::WebhookNotification::Kind::TransactionDisbursed
228
- notification.transaction.id.should == "my_id"
229
- notification.transaction.amount.should == 1_00
230
- notification.transaction.disbursement_details.disbursement_date.should == "2013-07-09"
307
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::TransactionDisbursed)
308
+ expect(notification.transaction.id).to eq("my_id")
309
+ expect(notification.transaction.amount).to eq(1_00)
310
+ expect(notification.transaction.disbursement_details.disbursement_date).to eq(Date.parse("2013-07-09"))
231
311
  end
232
312
 
233
313
  it "builds a sample notification for a disbursement_exception webhook" do
234
314
  sample_notification = Braintree::WebhookTesting.sample_notification(
235
315
  Braintree::WebhookNotification::Kind::DisbursementException,
236
- "my_id"
316
+ "my_id",
237
317
  )
238
318
 
239
319
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
240
320
 
241
- notification.kind.should == Braintree::WebhookNotification::Kind::DisbursementException
242
- notification.disbursement.id.should == "my_id"
243
- notification.disbursement.transaction_ids.should == %W{ afv56j kj8hjk }
244
- notification.disbursement.retry.should be(false)
245
- notification.disbursement.success.should be(false)
246
- notification.disbursement.exception_message.should == "bank_rejected"
247
- notification.disbursement.disbursement_date.should == Date.parse("2014-02-10")
248
- notification.disbursement.follow_up_action.should == "update_funding_information"
249
- notification.disbursement.merchant_account.id.should == "merchant_account_token"
321
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::DisbursementException)
322
+ expect(notification.disbursement.id).to eq("my_id")
323
+ expect(notification.disbursement.transaction_ids).to eq(%W{ afv56j kj8hjk })
324
+ expect(notification.disbursement.retry).to be(false)
325
+ expect(notification.disbursement.success).to be(false)
326
+ expect(notification.disbursement.exception_message).to eq("bank_rejected")
327
+ expect(notification.disbursement.disbursement_date).to eq(Date.parse("2014-02-10"))
328
+ expect(notification.disbursement.follow_up_action).to eq("update_funding_information")
329
+ expect(notification.disbursement.merchant_account.id).to eq("merchant_account_token")
250
330
  end
251
331
 
252
332
  it "builds a sample notification for a disbursement webhook" do
253
333
  sample_notification = Braintree::WebhookTesting.sample_notification(
254
334
  Braintree::WebhookNotification::Kind::Disbursement,
255
- "my_id"
335
+ "my_id",
336
+ )
337
+
338
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
339
+
340
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::Disbursement)
341
+ expect(notification.disbursement.id).to eq("my_id")
342
+ expect(notification.disbursement.transaction_ids).to eq(%W{ afv56j kj8hjk })
343
+ expect(notification.disbursement.retry).to be(false)
344
+ expect(notification.disbursement.success).to be(true)
345
+ expect(notification.disbursement.exception_message).to be_nil
346
+ expect(notification.disbursement.disbursement_date).to eq(Date.parse("2014-02-10"))
347
+ expect(notification.disbursement.follow_up_action).to be_nil
348
+ expect(notification.disbursement.merchant_account.id).to eq("merchant_account_token")
349
+ end
350
+ end
351
+
352
+ context "transaction review" do
353
+ it " builds a sample notification for a transaction reviewed webhook" do
354
+ sample_notification = Braintree::WebhookTesting.sample_notification(
355
+ Braintree::WebhookNotification::Kind::TransactionReviewed,
356
+ "my_id",
256
357
  )
257
358
 
258
359
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
259
360
 
260
- notification.kind.should == Braintree::WebhookNotification::Kind::Disbursement
261
- notification.disbursement.id.should == "my_id"
262
- notification.disbursement.transaction_ids.should == %W{ afv56j kj8hjk }
263
- notification.disbursement.retry.should be(false)
264
- notification.disbursement.success.should be(true)
265
- notification.disbursement.exception_message.should be_nil
266
- notification.disbursement.disbursement_date.should == Date.parse("2014-02-10")
267
- notification.disbursement.follow_up_action.should be_nil
268
- notification.disbursement.merchant_account.id.should == "merchant_account_token"
361
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::TransactionReviewed)
362
+ expect(notification.transaction_review.transaction_id).to eq("my_id")
363
+ expect(notification.transaction_review.decision).to eq("decision")
364
+ expect(notification.transaction_review.reviewer_email).to eq("hey@girl.com")
365
+ expect(notification.transaction_review.reviewer_note).to eq("i reviewed this")
366
+ expect(notification.transaction_review.reviewed_time).to_not be_nil
269
367
  end
270
368
  end
271
369
 
@@ -273,35 +371,35 @@ describe Braintree::WebhookNotification do
273
371
  it "builds a sample notification for a settlement webhook" do
274
372
  sample_notification = Braintree::WebhookTesting.sample_notification(
275
373
  Braintree::WebhookNotification::Kind::TransactionSettled,
276
- "my_id"
374
+ "my_id",
277
375
  )
278
376
 
279
377
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
280
378
 
281
- notification.kind.should == Braintree::WebhookNotification::Kind::TransactionSettled
379
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::TransactionSettled)
282
380
 
283
- notification.transaction.status.should == "settled"
284
- notification.transaction.us_bank_account_details.account_type.should == "checking"
285
- notification.transaction.us_bank_account_details.account_holder_name.should == "Dan Schulman"
286
- notification.transaction.us_bank_account_details.routing_number.should == "123456789"
287
- notification.transaction.us_bank_account_details.last_4.should == "1234"
381
+ expect(notification.transaction.status).to eq("settled")
382
+ expect(notification.transaction.us_bank_account_details.account_type).to eq("checking")
383
+ expect(notification.transaction.us_bank_account_details.account_holder_name).to eq("Dan Schulman")
384
+ expect(notification.transaction.us_bank_account_details.routing_number).to eq("123456789")
385
+ expect(notification.transaction.us_bank_account_details.last_4).to eq("1234")
288
386
  end
289
387
 
290
388
  it "builds a sample notification for a settlement declined webhook" do
291
389
  sample_notification = Braintree::WebhookTesting.sample_notification(
292
390
  Braintree::WebhookNotification::Kind::TransactionSettlementDeclined,
293
- "my_id"
391
+ "my_id",
294
392
  )
295
393
 
296
394
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
297
395
 
298
- notification.kind.should == Braintree::WebhookNotification::Kind::TransactionSettlementDeclined
396
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::TransactionSettlementDeclined)
299
397
 
300
- notification.transaction.status.should == "settlement_declined"
301
- notification.transaction.us_bank_account_details.account_type.should == "checking"
302
- notification.transaction.us_bank_account_details.account_holder_name.should == "Dan Schulman"
303
- notification.transaction.us_bank_account_details.routing_number.should == "123456789"
304
- notification.transaction.us_bank_account_details.last_4.should == "1234"
398
+ expect(notification.transaction.status).to eq("settlement_declined")
399
+ expect(notification.transaction.us_bank_account_details.account_type).to eq("checking")
400
+ expect(notification.transaction.us_bank_account_details.account_holder_name).to eq("Dan Schulman")
401
+ expect(notification.transaction.us_bank_account_details.routing_number).to eq("123456789")
402
+ expect(notification.transaction.us_bank_account_details.last_4).to eq("1234")
305
403
  end
306
404
  end
307
405
 
@@ -309,76 +407,91 @@ describe Braintree::WebhookNotification do
309
407
  it "builds a sample notification for a merchant account approved webhook" do
310
408
  sample_notification = Braintree::WebhookTesting.sample_notification(
311
409
  Braintree::WebhookNotification::Kind::SubMerchantAccountApproved,
312
- "my_id"
410
+ "my_id",
313
411
  )
314
412
 
315
413
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
316
414
 
317
- notification.kind.should == Braintree::WebhookNotification::Kind::SubMerchantAccountApproved
318
- notification.merchant_account.id.should == "my_id"
319
- notification.merchant_account.status.should == Braintree::MerchantAccount::Status::Active
320
- notification.merchant_account.master_merchant_account.id.should == "master_ma_for_my_id"
321
- notification.merchant_account.master_merchant_account.status.should == Braintree::MerchantAccount::Status::Active
415
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubMerchantAccountApproved)
416
+ expect(notification.merchant_account.id).to eq("my_id")
417
+ expect(notification.merchant_account.status).to eq(Braintree::MerchantAccount::Status::Active)
418
+ expect(notification.merchant_account.master_merchant_account.id).to eq("master_ma_for_my_id")
419
+ expect(notification.merchant_account.master_merchant_account.status).to eq(Braintree::MerchantAccount::Status::Active)
322
420
  end
323
421
 
324
422
  it "builds a sample notification for a merchant account declined webhook" do
325
423
  sample_notification = Braintree::WebhookTesting.sample_notification(
326
424
  Braintree::WebhookNotification::Kind::SubMerchantAccountDeclined,
327
- "my_id"
425
+ "my_id",
328
426
  )
329
427
 
330
428
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
331
429
 
332
- notification.kind.should == Braintree::WebhookNotification::Kind::SubMerchantAccountDeclined
333
- notification.merchant_account.id.should == "my_id"
334
- notification.merchant_account.status.should == Braintree::MerchantAccount::Status::Suspended
335
- notification.merchant_account.master_merchant_account.id.should == "master_ma_for_my_id"
336
- notification.merchant_account.master_merchant_account.status.should == Braintree::MerchantAccount::Status::Suspended
337
- notification.message.should == "Credit score is too low"
338
- notification.errors.for(:merchant_account).on(:base).first.code.should == Braintree::ErrorCodes::MerchantAccount::DeclinedOFAC
430
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubMerchantAccountDeclined)
431
+ expect(notification.merchant_account.id).to eq("my_id")
432
+ expect(notification.merchant_account.status).to eq(Braintree::MerchantAccount::Status::Suspended)
433
+ expect(notification.merchant_account.master_merchant_account.id).to eq("master_ma_for_my_id")
434
+ expect(notification.merchant_account.master_merchant_account.status).to eq(Braintree::MerchantAccount::Status::Suspended)
435
+ expect(notification.message).to eq("Credit score is too low")
436
+ expect(notification.errors.for(:merchant_account).on(:base).first.code).to eq(Braintree::ErrorCodes::MerchantAccount::DeclinedOFAC)
339
437
  end
340
438
  end
341
439
 
342
440
  context "subscription" do
441
+ it "builds a sample notification for a subscription billing skipped webhook" do
442
+ sample_notification = Braintree::WebhookTesting.sample_notification(
443
+ Braintree::WebhookNotification::Kind::SubscriptionBillingSkipped,
444
+ "my_id",
445
+ )
446
+
447
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
448
+
449
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubscriptionBillingSkipped)
450
+ expect(notification.subscription.id).to eq("my_id")
451
+ expect(notification.subscription.transactions.size).to eq(0)
452
+ expect(notification.subscription.discounts.size).to eq(0)
453
+ expect(notification.subscription.add_ons.size).to eq(0)
454
+ end
455
+
343
456
  it "builds a sample notification for a subscription charged successfully webhook" do
344
457
  sample_notification = Braintree::WebhookTesting.sample_notification(
345
458
  Braintree::WebhookNotification::Kind::SubscriptionChargedSuccessfully,
346
- "my_id"
459
+ "my_id",
347
460
  )
348
461
 
349
462
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
350
463
 
351
- notification.kind.should == Braintree::WebhookNotification::Kind::SubscriptionChargedSuccessfully
352
- notification.subscription.id.should == "my_id"
353
- notification.subscription.transactions.size.should == 1
354
- notification.subscription.transactions.first.status.should == Braintree::Transaction::Status::SubmittedForSettlement
355
- notification.subscription.transactions.first.amount.should == BigDecimal("49.99")
464
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubscriptionChargedSuccessfully)
465
+ expect(notification.subscription.id).to eq("my_id")
466
+ expect(notification.subscription.transactions.size).to eq(1)
467
+ expect(notification.subscription.transactions.first.status).to eq(Braintree::Transaction::Status::SubmittedForSettlement)
468
+ expect(notification.subscription.transactions.first.amount).to eq(BigDecimal("49.99"))
356
469
  end
357
470
 
358
471
  it "builds a sample notification for a subscription charged unsuccessfully webhook" do
359
472
  sample_notification = Braintree::WebhookTesting.sample_notification(
360
473
  Braintree::WebhookNotification::Kind::SubscriptionChargedUnsuccessfully,
361
- "my_id"
474
+ "my_id",
362
475
  )
363
476
 
364
477
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
365
478
 
366
- notification.kind.should == Braintree::WebhookNotification::Kind::SubscriptionChargedUnsuccessfully
367
- notification.subscription.id.should == "my_id"
368
- notification.subscription.transactions.size.should == 1
369
- notification.subscription.transactions.first.status.should == Braintree::Transaction::Status::Failed
370
- notification.subscription.transactions.first.amount.should == BigDecimal("49.99")
479
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubscriptionChargedUnsuccessfully)
480
+ expect(notification.subscription.id).to eq("my_id")
481
+ expect(notification.subscription.transactions.size).to eq(1)
482
+ expect(notification.subscription.transactions.first.status).to eq(Braintree::Transaction::Status::Failed)
483
+ expect(notification.subscription.transactions.first.amount).to eq(BigDecimal("49.99"))
371
484
  end
372
485
  end
373
486
 
374
487
  it "includes a valid signature" do
375
488
  sample_notification = Braintree::WebhookTesting.sample_notification(
376
489
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
377
- "my_id"
490
+ "my_id",
378
491
  )
379
492
  expected_signature = Braintree::Digest.hexdigest(Braintree::Configuration.private_key, sample_notification[:bt_payload])
380
493
 
381
- sample_notification[:bt_signature].should == "#{Braintree::Configuration.public_key}|#{expected_signature}"
494
+ expect(sample_notification[:bt_signature]).to eq("#{Braintree::Configuration.public_key}|#{expected_signature}")
382
495
  end
383
496
  end
384
497
 
@@ -386,14 +499,14 @@ describe Braintree::WebhookNotification do
386
499
  it "builds a sample notification for an account_updater_daily_report webhook" do
387
500
  sample_notification = Braintree::WebhookTesting.sample_notification(
388
501
  Braintree::WebhookNotification::Kind::AccountUpdaterDailyReport,
389
- "my_id"
502
+ "my_id",
390
503
  )
391
504
 
392
505
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
393
506
 
394
- notification.kind.should == Braintree::WebhookNotification::Kind::AccountUpdaterDailyReport
395
- notification.account_updater_daily_report.report_url.should == "link-to-csv-report"
396
- notification.account_updater_daily_report.report_date.should == Date.parse("2016-01-14")
507
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::AccountUpdaterDailyReport)
508
+ expect(notification.account_updater_daily_report.report_url).to eq("link-to-csv-report")
509
+ expect(notification.account_updater_daily_report.report_date).to eq(Date.parse("2016-01-14"))
397
510
  end
398
511
  end
399
512
 
@@ -401,44 +514,44 @@ describe Braintree::WebhookNotification do
401
514
  it "builds a sample notification for a GrantorUpdatedGrantedPaymentMethod webhook" do
402
515
  sample_notification = Braintree::WebhookTesting.sample_notification(
403
516
  Braintree::WebhookNotification::Kind::GrantorUpdatedGrantedPaymentMethod,
404
- "my_id"
517
+ "my_id",
405
518
  )
406
519
 
407
520
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
408
521
  update = notification.granted_payment_instrument_update
409
522
 
410
- notification.kind.should == Braintree::WebhookNotification::Kind::GrantorUpdatedGrantedPaymentMethod
411
- update.grant_owner_merchant_id.should == 'vczo7jqrpwrsi2px'
412
- update.grant_recipient_merchant_id.should == 'cf0i8wgarszuy6hc'
413
- update.payment_method_nonce.should == 'ee257d98-de40-47e8-96b3-a6954ea7a9a4'
414
- update.token.should == 'abc123z'
415
- update.updated_fields.should == ['expiration-month', 'expiration-year']
523
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::GrantorUpdatedGrantedPaymentMethod)
524
+ expect(update.grant_owner_merchant_id).to eq("vczo7jqrpwrsi2px")
525
+ expect(update.grant_recipient_merchant_id).to eq("cf0i8wgarszuy6hc")
526
+ expect(update.payment_method_nonce).to eq("ee257d98-de40-47e8-96b3-a6954ea7a9a4")
527
+ expect(update.token).to eq("abc123z")
528
+ expect(update.updated_fields).to eq(["expiration-month", "expiration-year"])
416
529
  end
417
530
 
418
531
  it "builds a sample notification for a RecipientUpdatedGrantedPaymentMethod webhook" do
419
532
  sample_notification = Braintree::WebhookTesting.sample_notification(
420
533
  Braintree::WebhookNotification::Kind::RecipientUpdatedGrantedPaymentMethod,
421
- "my_id"
534
+ "my_id",
422
535
  )
423
536
 
424
537
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
425
538
  update = notification.granted_payment_instrument_update
426
539
 
427
- notification.kind.should == Braintree::WebhookNotification::Kind::RecipientUpdatedGrantedPaymentMethod
428
- update.grant_owner_merchant_id.should == 'vczo7jqrpwrsi2px'
429
- update.grant_recipient_merchant_id.should == 'cf0i8wgarszuy6hc'
430
- update.payment_method_nonce.should == 'ee257d98-de40-47e8-96b3-a6954ea7a9a4'
431
- update.token.should == 'abc123z'
432
- update.updated_fields.should == ['expiration-month', 'expiration-year']
540
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::RecipientUpdatedGrantedPaymentMethod)
541
+ expect(update.grant_owner_merchant_id).to eq("vczo7jqrpwrsi2px")
542
+ expect(update.grant_recipient_merchant_id).to eq("cf0i8wgarszuy6hc")
543
+ expect(update.payment_method_nonce).to eq("ee257d98-de40-47e8-96b3-a6954ea7a9a4")
544
+ expect(update.token).to eq("abc123z")
545
+ expect(update.updated_fields).to eq(["expiration-month", "expiration-year"])
433
546
  end
434
547
  end
435
548
 
436
549
  context "granted_payment_instrument_revoked" do
437
550
  let(:gateway) do
438
551
  config = Braintree::Configuration.new(
439
- :merchant_id => 'merchant_id',
440
- :public_key => 'wrong_public_key',
441
- :private_key => 'wrong_private_key'
552
+ :merchant_id => "merchant_id",
553
+ :public_key => "wrong_public_key",
554
+ :private_key => "wrong_private_key",
442
555
  )
443
556
  Braintree::Gateway.new(config)
444
557
  end
@@ -488,10 +601,10 @@ describe Braintree::WebhookNotification do
488
601
  notification = Braintree::WebhookNotification._new(gateway, attributes[:notification])
489
602
  metadata = notification.revoked_payment_method_metadata
490
603
 
491
- notification.kind.should == Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentRevoked
492
- metadata.customer_id.should == "credit_card_customer_id"
493
- metadata.token.should == "credit_card_token"
494
- metadata.revoked_payment_method.class.should == Braintree::CreditCard
604
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentRevoked)
605
+ expect(metadata.customer_id).to eq("credit_card_customer_id")
606
+ expect(metadata.token).to eq("credit_card_token")
607
+ expect(metadata.revoked_payment_method.class).to eq(Braintree::CreditCard)
495
608
  end
496
609
  end
497
610
 
@@ -523,10 +636,10 @@ describe Braintree::WebhookNotification do
523
636
  notification = Braintree::WebhookNotification._new(gateway, attributes[:notification])
524
637
  metadata = notification.revoked_payment_method_metadata
525
638
 
526
- notification.kind.should == Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentRevoked
527
- metadata.customer_id.should == "paypal_customer_id"
528
- metadata.token.should == "paypal_token"
529
- metadata.revoked_payment_method.class.should == Braintree::PayPalAccount
639
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentRevoked)
640
+ expect(metadata.customer_id).to eq("paypal_customer_id")
641
+ expect(metadata.token).to eq("paypal_token")
642
+ expect(metadata.revoked_payment_method.class).to eq(Braintree::PayPalAccount)
530
643
  end
531
644
  end
532
645
 
@@ -558,10 +671,26 @@ describe Braintree::WebhookNotification do
558
671
  notification = Braintree::WebhookNotification._new(gateway, attributes[:notification])
559
672
  metadata = notification.revoked_payment_method_metadata
560
673
 
561
- notification.kind.should == Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentRevoked
562
- metadata.customer_id.should == "venmo_customer_id"
563
- metadata.token.should == "venmo_token"
564
- metadata.revoked_payment_method.class.should == Braintree::VenmoAccount
674
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::GrantedPaymentInstrumentRevoked)
675
+ expect(metadata.customer_id).to eq("venmo_customer_id")
676
+ expect(metadata.token).to eq("venmo_token")
677
+ expect(metadata.revoked_payment_method.class).to eq(Braintree::VenmoAccount)
678
+ end
679
+
680
+ it "builds a sample notification for a GrantedPaymentMethodRevoked webhook" do
681
+ sample_notification = Braintree::WebhookTesting.sample_notification(
682
+ Braintree::WebhookNotification::Kind::GrantedPaymentMethodRevoked,
683
+ "my_id",
684
+ )
685
+
686
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
687
+ expect(notification.kind).to eq Braintree::WebhookNotification::Kind::GrantedPaymentMethodRevoked
688
+
689
+ metadata = notification.revoked_payment_method_metadata
690
+
691
+ expect(metadata.customer_id).to eq "venmo_customer_id"
692
+ expect(metadata.token).to eq "my_id"
693
+ expect(metadata.revoked_payment_method.class).to eq Braintree::VenmoAccount
565
694
  end
566
695
  end
567
696
  end
@@ -570,16 +699,16 @@ describe Braintree::WebhookNotification do
570
699
  it "builds a sample notification for a payment_method_revoked_by_customer webhook" do
571
700
  sample_notification = Braintree::WebhookTesting.sample_notification(
572
701
  Braintree::WebhookNotification::Kind::PaymentMethodRevokedByCustomer,
573
- "my_payment_method_token"
702
+ "my_payment_method_token",
574
703
  )
575
704
 
576
705
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
577
- notification.kind.should == Braintree::WebhookNotification::Kind::PaymentMethodRevokedByCustomer
706
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::PaymentMethodRevokedByCustomer)
578
707
 
579
708
  metadata = notification.revoked_payment_method_metadata
580
- metadata.token.should == "my_payment_method_token"
581
- metadata.revoked_payment_method.class.should == Braintree::PayPalAccount
582
- metadata.revoked_payment_method.revoked_at.should_not be_nil
709
+ expect(metadata.token).to eq("my_payment_method_token")
710
+ expect(metadata.revoked_payment_method.class).to eq(Braintree::PayPalAccount)
711
+ expect(metadata.revoked_payment_method.revoked_at).not_to be_nil
583
712
  end
584
713
  end
585
714
 
@@ -587,20 +716,116 @@ describe Braintree::WebhookNotification do
587
716
  it "builds a sample notification for a local_payment webhook" do
588
717
  sample_notification = Braintree::WebhookTesting.sample_notification(
589
718
  Braintree::WebhookNotification::Kind::LocalPaymentCompleted,
590
- "my_id"
719
+ "my_id",
591
720
  )
592
721
 
593
722
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
594
- notification.kind.should == Braintree::WebhookNotification::Kind::LocalPaymentCompleted
723
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::LocalPaymentCompleted)
595
724
 
596
725
  local_payment_completed = notification.local_payment_completed
597
- local_payment_completed.payment_id.should == "PAY-XYZ123"
598
- local_payment_completed.payer_id.should == "ABCPAYER"
599
- local_payment_completed.payment_method_nonce.should == "ee257d98-de40-47e8-96b3-a6954ea7a9a4"
600
- local_payment_completed.transaction.id.should == "my_id"
601
- local_payment_completed.transaction.status.should == Braintree::Transaction::Status::Authorized
602
- local_payment_completed.transaction.amount.should == 49.99
603
- local_payment_completed.transaction.order_id.should == "order4567"
726
+ expect(local_payment_completed.blik_aliases).to be_nil
727
+ expect(local_payment_completed.payer_id).to eq("ABCPAYER")
728
+ expect(local_payment_completed.payment_id).to eq("PAY-XYZ123")
729
+ expect(local_payment_completed.payment_method_nonce).to eq("ee257d98-de40-47e8-96b3-a6954ea7a9a4")
730
+ expect(local_payment_completed.transaction.id).to eq("my_id")
731
+ expect(local_payment_completed.transaction.status).to eq(Braintree::Transaction::Status::Authorized)
732
+ expect(local_payment_completed.transaction.amount).to eq(49.99)
733
+ expect(local_payment_completed.transaction.order_id).to eq("order4567")
734
+ end
735
+
736
+ it "builds a sample notification for a local_payment webhook when funding source is blik one click" do
737
+ sample_notification = Braintree::WebhookTesting.sample_notification(
738
+ Braintree::WebhookNotification::Kind::LocalPaymentCompleted,
739
+ "blik_one_click_id",
740
+ )
741
+
742
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
743
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::LocalPaymentCompleted)
744
+
745
+ local_payment_completed = notification.local_payment_completed
746
+ expect(local_payment_completed.blik_aliases).to match_array([{:key => "alias-key-1", :label => "alias-label-1"}])
747
+ expect(local_payment_completed.payer_id).to eq("ABCPAYER")
748
+ expect(local_payment_completed.payment_id).to eq("PAY-XYZ123")
749
+ expect(local_payment_completed.payment_method_nonce).to eq("ee257d98-de40-47e8-96b3-a6954ea7a9a4")
750
+ expect(local_payment_completed.transaction.id).to eq("blik_one_click_id")
751
+ expect(local_payment_completed.transaction.status).to eq(Braintree::Transaction::Status::Authorized)
752
+ expect(local_payment_completed.transaction.amount).to eq(49.99)
753
+ expect(local_payment_completed.transaction.order_id).to eq("order4567")
754
+ end
755
+ end
756
+
757
+ context "local_payment_expired" do
758
+ it "builds a sample notification for a local_payment_expired webhook" do
759
+ sample_notification = Braintree::WebhookTesting.sample_notification(
760
+ Braintree::WebhookNotification::Kind::LocalPaymentExpired,
761
+ "my_id",
762
+ )
763
+
764
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
765
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::LocalPaymentExpired)
766
+
767
+ local_payment_expired = notification.local_payment_expired
768
+ expect(local_payment_expired.payment_id).to eq("PAY-XYZ123")
769
+ expect(local_payment_expired.payment_context_id).to eq("cG5b=")
770
+ end
771
+ end
772
+
773
+ context "local_payment_funded" do
774
+ it "builds a sample notification for a local_payment_funded webhook" do
775
+ sample_notification = Braintree::WebhookTesting.sample_notification(
776
+ Braintree::WebhookNotification::Kind::LocalPaymentFunded,
777
+ "my_id",
778
+ )
779
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
780
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::LocalPaymentFunded)
781
+
782
+ local_payment_funded = notification.local_payment_funded
783
+ expect(local_payment_funded.payment_id).to eq("PAY-XYZ123")
784
+ expect(local_payment_funded.payment_context_id).to eq("cG5b=")
785
+ expect(local_payment_funded.transaction.id).to eq("my_id")
786
+ expect(local_payment_funded.transaction.status).to eq(Braintree::Transaction::Status::Settled)
787
+ expect(local_payment_funded.transaction.amount).to eq(49.99)
788
+ expect(local_payment_funded.transaction.order_id).to eq("order4567")
789
+ end
790
+ end
791
+
792
+ context "local_payment_reversed" do
793
+ it "builds a sample notification for a local_payment webhook" do
794
+ sample_notification = Braintree::WebhookTesting.sample_notification(
795
+ Braintree::WebhookNotification::Kind::LocalPaymentReversed,
796
+ "my_id",
797
+ )
798
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
799
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::LocalPaymentReversed)
800
+
801
+ local_payment_reversed = notification.local_payment_reversed
802
+ expect(local_payment_reversed.payment_id).to eq("PAY-XYZ123")
803
+ end
804
+ end
805
+
806
+ context "payment_method_customer_data_updated" do
807
+ it "builds a sample notification for a payment_method_customer_data_updated webhook" do
808
+ sample_notification = Braintree::WebhookTesting.sample_notification(
809
+ Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated,
810
+ "my_id",
811
+ )
812
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
813
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated)
814
+
815
+ payment_method_customer_data_updated = notification.payment_method_customer_data_updated_metadata
816
+
817
+ expect(payment_method_customer_data_updated.token).to eq("TOKEN-12345")
818
+ expect(payment_method_customer_data_updated.datetime_updated).to eq("2022-01-01T21:28:37Z")
819
+
820
+ enriched_customer_data = payment_method_customer_data_updated.enriched_customer_data
821
+ expect(enriched_customer_data.fields_updated).to eq(["username"])
822
+
823
+ profile_data = enriched_customer_data.profile_data
824
+ expect(profile_data.first_name).to eq("John")
825
+ expect(profile_data.last_name).to eq("Doe")
826
+ expect(profile_data.username).to eq("venmo_username")
827
+ expect(profile_data.phone_number).to eq("1231231234")
828
+ expect(profile_data.email).to eq("john.doe@paypal.com")
604
829
  end
605
830
  end
606
831
 
@@ -620,7 +845,7 @@ describe Braintree::WebhookNotification do
620
845
  it "raises InvalidSignature error when the signature is completely invalid" do
621
846
  sample_notification = Braintree::WebhookTesting.sample_notification(
622
847
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
623
- "my_id"
848
+ "my_id",
624
849
  )
625
850
 
626
851
  expect do
@@ -631,13 +856,13 @@ describe Braintree::WebhookNotification do
631
856
  it "raises InvalidSignature error with a message when the public key is not found" do
632
857
  sample_notification = Braintree::WebhookTesting.sample_notification(
633
858
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
634
- "my_id"
859
+ "my_id",
635
860
  )
636
861
 
637
862
  config = Braintree::Configuration.new(
638
- :merchant_id => 'merchant_id',
639
- :public_key => 'wrong_public_key',
640
- :private_key => 'wrong_private_key'
863
+ :merchant_id => "merchant_id",
864
+ :public_key => "wrong_public_key",
865
+ :private_key => "wrong_private_key",
641
866
  )
642
867
  gateway = Braintree::Gateway.new(config)
643
868
 
@@ -649,7 +874,7 @@ describe Braintree::WebhookNotification do
649
874
  it "raises InvalidSignature error if the payload has been changed" do
650
875
  sample_notification = Braintree::WebhookTesting.sample_notification(
651
876
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
652
- "my_id"
877
+ "my_id",
653
878
  )
654
879
 
655
880
  expect do
@@ -660,7 +885,7 @@ describe Braintree::WebhookNotification do
660
885
  it "raises InvalidSignature error with a message complaining about invalid characters" do
661
886
  sample_notification = Braintree::WebhookTesting.sample_notification(
662
887
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
663
- "my_id"
888
+ "my_id",
664
889
  )
665
890
 
666
891
  expect do
@@ -671,7 +896,7 @@ describe Braintree::WebhookNotification do
671
896
  it "allows all valid characters" do
672
897
  sample_notification = Braintree::WebhookTesting.sample_notification(
673
898
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
674
- "my_id"
899
+ "my_id",
675
900
  )
676
901
 
677
902
  sample_notification[:bt_payload] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+=/\n"
@@ -682,20 +907,20 @@ describe Braintree::WebhookNotification do
682
907
  exception = e
683
908
  end
684
909
 
685
- exception.message.should_not match(/payload contains illegal characters/)
910
+ expect(exception.message).not_to match(/payload contains illegal characters/)
686
911
  end
687
912
 
688
913
  it "retries a payload with a newline" do
689
914
  sample_notification = Braintree::WebhookTesting.sample_notification(
690
915
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
691
- "my_id"
916
+ "my_id",
692
917
  )
693
918
 
694
919
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload].rstrip)
695
920
 
696
- notification.kind.should == Braintree::WebhookNotification::Kind::SubscriptionWentPastDue
697
- notification.subscription.id.should == "my_id"
698
- notification.timestamp.should be_within(10).of(Time.now.utc)
921
+ expect(notification.kind).to eq(Braintree::WebhookNotification::Kind::SubscriptionWentPastDue)
922
+ expect(notification.subscription.id).to eq("my_id")
923
+ expect(notification.timestamp).to be_within(10).of(Time.now.utc)
699
924
  end
700
925
  end
701
926
 
@@ -703,30 +928,30 @@ describe Braintree::WebhookNotification do
703
928
  it "returns true for check webhook kinds" do
704
929
  sample_notification = Braintree::WebhookTesting.sample_notification(
705
930
  Braintree::WebhookNotification::Kind::Check,
706
- nil
931
+ nil,
707
932
  )
708
933
 
709
934
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload].rstrip)
710
935
 
711
- notification.check?.should == true
936
+ expect(notification.check?).to eq(true)
712
937
  end
713
938
 
714
939
  it "returns false for non-check webhook kinds" do
715
940
  sample_notification = Braintree::WebhookTesting.sample_notification(
716
941
  Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
717
- nil
942
+ nil,
718
943
  )
719
944
 
720
945
  notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload].rstrip)
721
946
 
722
- notification.check?.should == false
947
+ expect(notification.check?).to eq(false)
723
948
  end
724
949
  end
725
950
 
726
951
  describe "self.verify" do
727
952
  it "creates a verification string" do
728
953
  response = Braintree::WebhookNotification.verify("20f9f8ed05f77439fe955c977e4c8a53")
729
- response.should == "integration_public_key|d9b899556c966b3f06945ec21311865d35df3ce4"
954
+ expect(response).to eq("integration_public_key|d9b899556c966b3f06945ec21311865d35df3ce4")
730
955
  end
731
956
 
732
957
  it "raises InvalidChallenge error with a message complaining about invalid characters" do
@@ -737,4 +962,16 @@ describe Braintree::WebhookNotification do
737
962
  end.to raise_error(Braintree::InvalidChallenge, /challenge contains non-hex characters/)
738
963
  end
739
964
  end
965
+
966
+ describe "refund failed" do
967
+ it "builds a sample notification for refund failed" do
968
+ sample_notification = Braintree::WebhookTesting.sample_notification(
969
+ Braintree::WebhookNotification::Kind::RefundFailed,
970
+ "my_id",
971
+ )
972
+ notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
973
+ expect(notification.kind.should).to eq(Braintree::WebhookNotification::Kind::RefundFailed)
974
+ expect(notification.transaction.id).to eq("my_id")
975
+ end
976
+ end
740
977
  end