stripe_model_callbacks 0.1.7 → 0.1.9

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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +1 -1
  4. data/app/models/stripe_model_callbacks/application_record.rb +28 -14
  5. data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +1 -1
  6. data/app/services/stripe_model_callbacks/attributes_assigner_service.rb +154 -8
  7. data/app/services/stripe_model_callbacks/base_service.rb +9 -6
  8. data/app/services/stripe_model_callbacks/charge/dispute_updated_service.rb +3 -3
  9. data/app/services/stripe_model_callbacks/charge/updated_service.rb +5 -5
  10. data/app/services/stripe_model_callbacks/configure_service.rb +58 -27
  11. data/app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb +1 -1
  12. data/app/services/stripe_model_callbacks/customer/discount_updated_service.rb +1 -1
  13. data/app/services/stripe_model_callbacks/customer/source_updated_service.rb +3 -3
  14. data/app/services/stripe_model_callbacks/customer/subscription/updated_service.rb +2 -2
  15. data/app/services/stripe_model_callbacks/customer/updated_service.rb +2 -2
  16. data/app/services/stripe_model_callbacks/event_mocker_service.rb +14 -8
  17. data/app/services/stripe_model_callbacks/invoice/updated_service.rb +4 -4
  18. data/app/services/stripe_model_callbacks/payment_intent/updated_service.rb +19 -0
  19. data/app/services/stripe_model_callbacks/payment_method/updated_service.rb +19 -0
  20. data/app/services/stripe_model_callbacks/payout/updated_service.rb +3 -3
  21. data/app/services/stripe_model_callbacks/plan/updated_service.rb +1 -1
  22. data/app/services/stripe_model_callbacks/price/updated_service.rb +1 -1
  23. data/app/services/stripe_model_callbacks/product/updated_service.rb +1 -1
  24. data/app/services/stripe_model_callbacks/recipient/updated_service.rb +1 -1
  25. data/app/services/stripe_model_callbacks/review/updated_service.rb +1 -1
  26. data/app/services/stripe_model_callbacks/setup_intent/updated_service.rb +8 -0
  27. data/app/services/stripe_model_callbacks/sku/updated_service.rb +1 -1
  28. data/app/services/stripe_model_callbacks/source/transaction_created_service.rb +17 -0
  29. data/app/services/stripe_model_callbacks/source/updated_service.rb +4 -4
  30. data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +1 -1
  31. data/app/services/stripe_model_callbacks/subscription_schedule/updated_service.rb +1 -1
  32. data/app/services/stripe_model_callbacks/sync_everything.rb +17 -2
  33. data/app/services/stripe_model_callbacks/sync_from_stripe.rb +1 -1
  34. data/app/services/stripe_model_callbacks/tax_rate/updated_service.rb +3 -3
  35. data/app/services/stripe_model_callbacks/transfer/updated_service.rb +1 -1
  36. data/config/rails_best_practices.yml +1 -0
  37. data/db/migrate/20180206151132_change_activities_trackable_id_to_string.rb +1 -1
  38. data/db/migrate/20180208091647_change_stripe_subscription_items_quantity_to_integer.rb +1 -1
  39. data/db/migrate/20181219121712_add_new_primary_id_and_rename_old.rb +2 -2
  40. data/db/migrate/20230210081405_create_stripe_setup_intents.rb +28 -0
  41. data/db/migrate/20230331182902_add_amount_captured_to_stripe_charges.rb +6 -0
  42. data/db/migrate/20230420092307_create_stripe_payment_methods.rb +15 -0
  43. data/db/migrate/20230421072509_create_stripe_payment_intents.rb +44 -0
  44. data/db/migrate/20230422074329_add_payment_intent_to_stripe_charges.rb +6 -0
  45. data/db/migrate/20230422175529_add_payment_intent_to_stripe_refunds.rb +6 -0
  46. data/db/migrate/20230422180602_change_stripe_refunds_stripe_charge_id_to_nullable.rb +5 -0
  47. data/db/migrate/20230518072538_change_stripe_setup_intents_payment_method_to_string.rb +7 -0
  48. data/lib/stripe_model_callbacks/configuration.rb +1 -1
  49. data/lib/stripe_model_callbacks/event_mocker.rb +1 -1
  50. data/lib/stripe_model_callbacks/factories/stripe_charges.rb +10 -0
  51. data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +10 -9
  52. data/lib/stripe_model_callbacks/factories/stripe_customers.rb +6 -4
  53. data/lib/stripe_model_callbacks/factories/stripe_invoice_items.rb +1 -0
  54. data/lib/stripe_model_callbacks/factories/stripe_invoices.rb +1 -0
  55. data/lib/stripe_model_callbacks/factories/stripe_payment_intents.rb +17 -0
  56. data/lib/stripe_model_callbacks/factories/stripe_payment_methods.rb +15 -0
  57. data/lib/stripe_model_callbacks/factories/stripe_plans.rb +9 -12
  58. data/lib/stripe_model_callbacks/factories/stripe_products.rb +9 -8
  59. data/lib/stripe_model_callbacks/factories/stripe_recipients.rb +2 -0
  60. data/lib/stripe_model_callbacks/factories/stripe_reviews.rb +2 -0
  61. data/lib/stripe_model_callbacks/factories/stripe_setup_intents.rb +7 -0
  62. data/lib/stripe_model_callbacks/factories/stripe_skus.rb +1 -0
  63. data/lib/stripe_model_callbacks/factories/stripe_subscription_items.rb +7 -7
  64. data/lib/stripe_model_callbacks/factories/stripe_subscriptions.rb +10 -12
  65. data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +10 -0
  66. data/lib/stripe_model_callbacks/factories/stripe_transfers.rb +2 -0
  67. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refunded.json +1 -0
  68. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +0 -1
  69. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.amount_capturable_updated.json +66 -0
  70. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.canceled.json +66 -0
  71. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.created.json +66 -0
  72. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.partially_funded.json +66 -0
  73. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.payment_failed.json +66 -0
  74. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.processing.json +66 -0
  75. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.requires_action.json +66 -0
  76. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.succeeded.json +66 -0
  77. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.attached.json +63 -0
  78. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.automatically_updated.json +63 -0
  79. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.card_automatically_updated.json +63 -0
  80. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.detached.json +63 -0
  81. data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.updated.json +63 -0
  82. data/lib/stripe_model_callbacks/fixtures/stripe_events/setup_intent/setup_intent.created.json +47 -0
  83. data/lib/stripe_model_callbacks/fixtures/stripe_events/setup_intent/setup_intent.updated.json +47 -0
  84. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/{source.transaction_created.json → source.transaction.created.json} +2 -1
  85. data/lib/stripe_model_callbacks/models/stripe_charge.rb +51 -4
  86. data/lib/stripe_model_callbacks/models/stripe_coupon.rb +12 -0
  87. data/lib/stripe_model_callbacks/models/stripe_customer.rb +12 -0
  88. data/lib/stripe_model_callbacks/models/stripe_invoice.rb +17 -1
  89. data/lib/stripe_model_callbacks/models/stripe_payment_intent.rb +125 -0
  90. data/lib/stripe_model_callbacks/models/stripe_payment_method.rb +31 -0
  91. data/lib/stripe_model_callbacks/models/stripe_plan.rb +13 -0
  92. data/lib/stripe_model_callbacks/models/stripe_product.rb +10 -0
  93. data/lib/stripe_model_callbacks/models/stripe_recipient.rb +1 -1
  94. data/lib/stripe_model_callbacks/models/stripe_refund.rb +3 -1
  95. data/lib/stripe_model_callbacks/models/stripe_setup_intent.rb +21 -0
  96. data/lib/stripe_model_callbacks/models/stripe_source.rb +2 -1
  97. data/lib/stripe_model_callbacks/models/stripe_subscription.rb +23 -4
  98. data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +28 -2
  99. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +2 -2
  100. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase.rb +1 -1
  101. data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +6 -0
  102. data/lib/stripe_model_callbacks/version.rb +1 -1
  103. data/lib/stripe_model_callbacks.rb +1 -1
  104. metadata +47 -14
@@ -0,0 +1,66 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pi_1JGpBw4Lf1hyuG3tSrdK3llw",
9
+ "object": "payment_intent",
10
+ "amount": 1000,
11
+ "amount_capturable": 0,
12
+ "amount_details": {
13
+ "tip": {}
14
+ },
15
+ "amount_received": 0,
16
+ "application": null,
17
+ "application_fee_amount": null,
18
+ "automatic_payment_methods": null,
19
+ "canceled_at": null,
20
+ "cancellation_reason": null,
21
+ "capture_method": "automatic",
22
+ "client_secret": "pi_1JGpBw4Lf1hyuG3tSrdK3llw_secret_LS2rgASDfUetReE3XLXayygdt",
23
+ "confirmation_method": "automatic",
24
+ "created": 1627149796,
25
+ "currency": "usd",
26
+ "customer": null,
27
+ "description": "Created by stripe.com/docs demo",
28
+ "invoice": null,
29
+ "last_payment_error": null,
30
+ "latest_charge": null,
31
+ "livemode": false,
32
+ "metadata": {},
33
+ "next_action": null,
34
+ "on_behalf_of": null,
35
+ "payment_method": null,
36
+ "payment_method_options": {
37
+ "card": {
38
+ "installments": null,
39
+ "mandate_options": null,
40
+ "network": null,
41
+ "request_three_d_secure": "automatic"
42
+ }
43
+ },
44
+ "payment_method_types": [
45
+ "card"
46
+ ],
47
+ "processing": null,
48
+ "receipt_email": null,
49
+ "review": null,
50
+ "setup_future_usage": null,
51
+ "shipping": null,
52
+ "statement_descriptor": null,
53
+ "statement_descriptor_suffix": null,
54
+ "status": "requires_payment_method",
55
+ "transfer_data": null,
56
+ "transfer_group": null
57
+ }
58
+ },
59
+ "livemode": true,
60
+ "pending_webhooks": 1,
61
+ "request": {
62
+ "id": null,
63
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
64
+ },
65
+ "type": "payment_intent.requires_action"
66
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pi_1JGpBw4Lf1hyuG3tSrdK3llw",
9
+ "object": "payment_intent",
10
+ "amount": 1000,
11
+ "amount_capturable": 0,
12
+ "amount_details": {
13
+ "tip": {}
14
+ },
15
+ "amount_received": 0,
16
+ "application": null,
17
+ "application_fee_amount": null,
18
+ "automatic_payment_methods": null,
19
+ "canceled_at": null,
20
+ "cancellation_reason": null,
21
+ "capture_method": "automatic",
22
+ "client_secret": "pi_1JGpBw4Lf1hyuG3tSrdK3llw_secret_LS2rgASDfUetReE3XLXayygdt",
23
+ "confirmation_method": "automatic",
24
+ "created": 1627149796,
25
+ "currency": "usd",
26
+ "customer": null,
27
+ "description": "Created by stripe.com/docs demo",
28
+ "invoice": null,
29
+ "last_payment_error": null,
30
+ "latest_charge": null,
31
+ "livemode": false,
32
+ "metadata": {},
33
+ "next_action": null,
34
+ "on_behalf_of": null,
35
+ "payment_method": null,
36
+ "payment_method_options": {
37
+ "card": {
38
+ "installments": null,
39
+ "mandate_options": null,
40
+ "network": null,
41
+ "request_three_d_secure": "automatic"
42
+ }
43
+ },
44
+ "payment_method_types": [
45
+ "card"
46
+ ],
47
+ "processing": null,
48
+ "receipt_email": null,
49
+ "review": null,
50
+ "setup_future_usage": null,
51
+ "shipping": null,
52
+ "statement_descriptor": null,
53
+ "statement_descriptor_suffix": null,
54
+ "status": "requires_payment_method",
55
+ "transfer_data": null,
56
+ "transfer_group": null
57
+ }
58
+ },
59
+ "livemode": true,
60
+ "pending_webhooks": 1,
61
+ "request": {
62
+ "id": null,
63
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
64
+ },
65
+ "type": "payment_intent.succeeded"
66
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pm_1MxwglIICJxvfdbRkDNKMCwZ",
9
+ "object": "payment_method",
10
+ "billing_details": {
11
+ "address": {
12
+ "city": null,
13
+ "country": "DK",
14
+ "line1": null,
15
+ "line2": null,
16
+ "postal_code": null,
17
+ "state": null
18
+ },
19
+ "email": null,
20
+ "name": null,
21
+ "phone": null
22
+ },
23
+ "card": {
24
+ "brand": "mastercard",
25
+ "checks": {
26
+ "address_line1_check": null,
27
+ "address_postal_code_check": null,
28
+ "cvc_check": "pass"
29
+ },
30
+ "country": "DK",
31
+ "exp_month": 6,
32
+ "exp_year": 2023,
33
+ "fingerprint": "QJ3sKGzehiISoOQ3",
34
+ "funding": "debit",
35
+ "generated_from": null,
36
+ "last4": "7080",
37
+ "networks": {
38
+ "available": [
39
+ "mastercard"
40
+ ],
41
+ "preferred": null
42
+ },
43
+ "three_d_secure_usage": {
44
+ "supported": true
45
+ },
46
+ "wallet": null
47
+ },
48
+ "created": 1681755727,
49
+ "customer": "cus_NiCY7UI5u0pbJH",
50
+ "livemode": true,
51
+ "metadata": {
52
+ },
53
+ "type": "card"
54
+ }
55
+ },
56
+ "livemode": true,
57
+ "pending_webhooks": 1,
58
+ "request": {
59
+ "id": null,
60
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
61
+ },
62
+ "type": "payment_method.attached"
63
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pm_1MxwglIICJxvfdbRkDNKMCwZ",
9
+ "object": "payment_method",
10
+ "billing_details": {
11
+ "address": {
12
+ "city": null,
13
+ "country": "DK",
14
+ "line1": null,
15
+ "line2": null,
16
+ "postal_code": null,
17
+ "state": null
18
+ },
19
+ "email": null,
20
+ "name": null,
21
+ "phone": null
22
+ },
23
+ "card": {
24
+ "brand": "mastercard",
25
+ "checks": {
26
+ "address_line1_check": null,
27
+ "address_postal_code_check": null,
28
+ "cvc_check": "pass"
29
+ },
30
+ "country": "DK",
31
+ "exp_month": 6,
32
+ "exp_year": 2023,
33
+ "fingerprint": "QJ3sKGzehiISoOQ3",
34
+ "funding": "debit",
35
+ "generated_from": null,
36
+ "last4": "7080",
37
+ "networks": {
38
+ "available": [
39
+ "mastercard"
40
+ ],
41
+ "preferred": null
42
+ },
43
+ "three_d_secure_usage": {
44
+ "supported": true
45
+ },
46
+ "wallet": null
47
+ },
48
+ "created": 1681755727,
49
+ "customer": "cus_NiCY7UI5u0pbJH",
50
+ "livemode": true,
51
+ "metadata": {
52
+ },
53
+ "type": "card"
54
+ }
55
+ },
56
+ "livemode": true,
57
+ "pending_webhooks": 1,
58
+ "request": {
59
+ "id": null,
60
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
61
+ },
62
+ "type": "payment_method.automatically_updated"
63
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pm_1MxwglIICJxvfdbRkDNKMCwZ",
9
+ "object": "payment_method",
10
+ "billing_details": {
11
+ "address": {
12
+ "city": null,
13
+ "country": "DK",
14
+ "line1": null,
15
+ "line2": null,
16
+ "postal_code": null,
17
+ "state": null
18
+ },
19
+ "email": null,
20
+ "name": null,
21
+ "phone": null
22
+ },
23
+ "card": {
24
+ "brand": "mastercard",
25
+ "checks": {
26
+ "address_line1_check": null,
27
+ "address_postal_code_check": null,
28
+ "cvc_check": "pass"
29
+ },
30
+ "country": "DK",
31
+ "exp_month": 6,
32
+ "exp_year": 2023,
33
+ "fingerprint": "QJ3sKGzehiISoOQ3",
34
+ "funding": "debit",
35
+ "generated_from": null,
36
+ "last4": "7080",
37
+ "networks": {
38
+ "available": [
39
+ "mastercard"
40
+ ],
41
+ "preferred": null
42
+ },
43
+ "three_d_secure_usage": {
44
+ "supported": true
45
+ },
46
+ "wallet": null
47
+ },
48
+ "created": 1681755727,
49
+ "customer": "cus_NiCY7UI5u0pbJH",
50
+ "livemode": true,
51
+ "metadata": {
52
+ },
53
+ "type": "card"
54
+ }
55
+ },
56
+ "livemode": true,
57
+ "pending_webhooks": 1,
58
+ "request": {
59
+ "id": null,
60
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
61
+ },
62
+ "type": "payment_method.card_automatically_updated"
63
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pm_1MxwglIICJxvfdbRkDNKMCwZ",
9
+ "object": "payment_method",
10
+ "billing_details": {
11
+ "address": {
12
+ "city": null,
13
+ "country": "DK",
14
+ "line1": null,
15
+ "line2": null,
16
+ "postal_code": null,
17
+ "state": null
18
+ },
19
+ "email": null,
20
+ "name": null,
21
+ "phone": null
22
+ },
23
+ "card": {
24
+ "brand": "mastercard",
25
+ "checks": {
26
+ "address_line1_check": null,
27
+ "address_postal_code_check": null,
28
+ "cvc_check": "pass"
29
+ },
30
+ "country": "DK",
31
+ "exp_month": 6,
32
+ "exp_year": 2023,
33
+ "fingerprint": "QJ3sKGzehiISoOQ3",
34
+ "funding": "debit",
35
+ "generated_from": null,
36
+ "last4": "7080",
37
+ "networks": {
38
+ "available": [
39
+ "mastercard"
40
+ ],
41
+ "preferred": null
42
+ },
43
+ "three_d_secure_usage": {
44
+ "supported": true
45
+ },
46
+ "wallet": null
47
+ },
48
+ "created": 1681755727,
49
+ "customer": "cus_NiCY7UI5u0pbJH",
50
+ "livemode": true,
51
+ "metadata": {
52
+ },
53
+ "type": "card"
54
+ }
55
+ },
56
+ "livemode": true,
57
+ "pending_webhooks": 1,
58
+ "request": {
59
+ "id": null,
60
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
61
+ },
62
+ "type": "payment_method.detached"
63
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1681755758,
6
+ "data": {
7
+ "object": {
8
+ "id": "pm_1MxwglIICJxvfdbRkDNKMCwZ",
9
+ "object": "payment_method",
10
+ "billing_details": {
11
+ "address": {
12
+ "city": null,
13
+ "country": "DK",
14
+ "line1": null,
15
+ "line2": null,
16
+ "postal_code": null,
17
+ "state": null
18
+ },
19
+ "email": null,
20
+ "name": null,
21
+ "phone": null
22
+ },
23
+ "card": {
24
+ "brand": "mastercard",
25
+ "checks": {
26
+ "address_line1_check": null,
27
+ "address_postal_code_check": null,
28
+ "cvc_check": "pass"
29
+ },
30
+ "country": "DK",
31
+ "exp_month": 6,
32
+ "exp_year": 2023,
33
+ "fingerprint": "QJ3sKGzehiISoOQ3",
34
+ "funding": "debit",
35
+ "generated_from": null,
36
+ "last4": "7080",
37
+ "networks": {
38
+ "available": [
39
+ "mastercard"
40
+ ],
41
+ "preferred": null
42
+ },
43
+ "three_d_secure_usage": {
44
+ "supported": true
45
+ },
46
+ "wallet": null
47
+ },
48
+ "created": 1681755727,
49
+ "customer": "cus_NiCY7UI5u0pbJH",
50
+ "livemode": true,
51
+ "metadata": {
52
+ },
53
+ "type": "card"
54
+ }
55
+ },
56
+ "livemode": true,
57
+ "pending_webhooks": 1,
58
+ "request": {
59
+ "id": null,
60
+ "idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
61
+ },
62
+ "type": "payment_method.updated"
63
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "id": "evt_1MZYBJIICJxvfdbR1IBR1zYM",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1675941649,
6
+ "data": {
7
+ "object": {
8
+ "id": "seti_1MZYBJIICJxvfdbRFtP2AeIi",
9
+ "object": "setup_intent",
10
+ "application": null,
11
+ "cancellation_reason": null,
12
+ "client_secret": "seti_1MZYBJIICJxvfdbRFtP2AeIi_secret_NKCapEVr1rCGRLrEjdHGercMNLWCKkH",
13
+ "created": 1675941649,
14
+ "customer": "cus_NKCaPfiHnRAtaq",
15
+ "description": null,
16
+ "flow_directions": null,
17
+ "last_setup_error": null,
18
+ "latest_attempt": null,
19
+ "livemode": false,
20
+ "mandate": null,
21
+ "metadata": {},
22
+ "next_action": null,
23
+ "on_behalf_of": null,
24
+ "payment_method": null,
25
+ "payment_method_options": {
26
+ "card": {
27
+ "mandate_options": null,
28
+ "network": null,
29
+ "request_three_d_secure": "automatic"
30
+ }
31
+ },
32
+ "payment_method_types": [
33
+ "card"
34
+ ],
35
+ "single_use_mandate": null,
36
+ "status": "requires_payment_method",
37
+ "usage": "off_session"
38
+ }
39
+ },
40
+ "livemode": false,
41
+ "pending_webhooks": 1,
42
+ "request": {
43
+ "id": "req_8TabPJe0whYnAR",
44
+ "idempotency_key": "853d4eff-b952-431c-b204-b0ee45895c1a"
45
+ },
46
+ "type": "setup_intent.created"
47
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "id": "evt_1MZYBJIICJxvfdbR1IBR1zYM",
3
+ "object": "event",
4
+ "api_version": "2022-11-15",
5
+ "created": 1675941649,
6
+ "data": {
7
+ "object": {
8
+ "id": "seti_1MZYBJIICJxvfdbRFtP2AeIi",
9
+ "object": "setup_intent",
10
+ "application": null,
11
+ "cancellation_reason": null,
12
+ "client_secret": "seti_1MZYBJIICJxvfdbRFtP2AeIi_secret_NKCapEVr1rCGRLrEjdHGercMNLWCKkH",
13
+ "created": 1675941649,
14
+ "customer": "cus_NKCaPfiHnRAtaq",
15
+ "description": null,
16
+ "flow_directions": null,
17
+ "last_setup_error": null,
18
+ "latest_attempt": null,
19
+ "livemode": false,
20
+ "mandate": null,
21
+ "metadata": {},
22
+ "next_action": null,
23
+ "on_behalf_of": null,
24
+ "payment_method": null,
25
+ "payment_method_options": {
26
+ "card": {
27
+ "mandate_options": null,
28
+ "network": null,
29
+ "request_three_d_secure": "automatic"
30
+ }
31
+ },
32
+ "payment_method_types": [
33
+ "card"
34
+ ],
35
+ "single_use_mandate": null,
36
+ "status": "requires_payment_method",
37
+ "usage": "off_session"
38
+ }
39
+ },
40
+ "livemode": false,
41
+ "pending_webhooks": 1,
42
+ "request": {
43
+ "id": "req_8TabPJe0whYnAR",
44
+ "idempotency_key": "853d4eff-b952-431c-b204-b0ee45895c1a"
45
+ },
46
+ "type": "setup_intent.updated"
47
+ }
@@ -15,7 +15,8 @@
15
15
  "bitcoin_amount": 3000000,
16
16
  "created": 1517906694,
17
17
  "currency": "usd",
18
- "receiver": "btcrcv_1B2J9N2eZvKYlo2C9nVfoiuu"
18
+ "receiver": "btcrcv_1B2J9N2eZvKYlo2C9nVfoiuu",
19
+ "source": "src_00000000000000"
19
20
  }
20
21
  }
21
22
  }
@@ -1,11 +1,20 @@
1
1
  class StripeCharge < StripeModelCallbacks::ApplicationRecord
2
2
  belongs_to :stripe_customer, optional: true, primary_key: "stripe_id"
3
3
  belongs_to :stripe_invoice, optional: true, primary_key: "stripe_id"
4
+ belongs_to :stripe_payment_intent, foreign_key: "payment_intent", optional: true, primary_key: "stripe_id"
4
5
  belongs_to :stripe_source, optional: true, primary_key: "stripe_id"
6
+ has_many :stripe_invoices, primary_key: "stripe_id"
5
7
  has_many :stripe_orders, primary_key: "stripe_id"
6
8
  has_many :stripe_refunds, primary_key: "stripe_id"
7
9
  has_many :stripe_reviews, primary_key: "stripe_id"
8
10
 
11
+ has_one :latest_charge_on_stripe_payment_intent,
12
+ class_name: "StripePaymentIntent",
13
+ foreign_key: "latest_charge",
14
+ inverse_of: :stripe_latest_charge,
15
+ primary_key: "stripe_id"
16
+
17
+ monetize :amount_captured_cents, allow_nil: true
9
18
  monetize :amount_cents
10
19
  monetize :amount_refunded_cents, allow_nil: true
11
20
  monetize :application_cents, allow_nil: true
@@ -22,29 +31,67 @@ class StripeCharge < StripeModelCallbacks::ApplicationRecord
22
31
  livemode: object.livemode,
23
32
  stripe_invoice_id: object.invoice,
24
33
  metadata: JSON.generate(object.metadata),
25
- stripe_order_id: object.order,
34
+ stripe_id: object.id,
35
+ stripe_order_id: object.try(:order),
26
36
  stripe_source_id: object.source
27
37
  )
28
38
 
39
+ if object.source.is_a?(String)
40
+ self.stripe_source_id = object.source
41
+ elsif object.source
42
+ self.stripe_source_id = object.source.id
43
+ end
44
+
29
45
  assign_amounts_from_stripe(object)
30
46
 
31
47
  StripeModelCallbacks::AttributesAssignerService.execute!(
32
48
  model: self,
33
49
  stripe_model: object,
34
50
  attributes: %w[
35
- captured currency description dispute outcome refunded fraud_details failure_message failure_code on_behalf_of paid
51
+ captured currency description dispute outcome refunded fraud_details failure_message failure_code on_behalf_of paid payment_intent
36
52
  receipt_email receipt_number review shipping source_transfer statement_descriptor status transfer_group
37
53
  ]
38
54
  )
39
55
  end
40
56
 
57
+ def capture(**)
58
+ updated_charge = Stripe::Charge.capture(stripe_id, **)
59
+ assign_from_stripe(updated_charge)
60
+ save!
61
+ end
62
+
63
+ def create_stripe_mock!
64
+ mock_charge = Stripe::Charge.create(
65
+ amount: amount_cents,
66
+ captured:,
67
+ currency:,
68
+ customer: stripe_customer_id,
69
+ id: stripe_id,
70
+ paid:,
71
+ refunded:
72
+ )
73
+ assign_from_stripe(mock_charge)
74
+ save!
75
+ end
76
+
77
+ def refund(**)
78
+ StripeRefund.create_on_stripe!(charge: stripe_id)
79
+ updated_charge = Stripe::Charge.retrieve(stripe_id, **)
80
+ assign_from_stripe(updated_charge)
81
+ save!
82
+ end
83
+
41
84
  private
42
85
 
43
86
  def assign_amounts_from_stripe(object)
87
+ amount_captured_value = object.try(:amount_captured)
88
+ amount_captured_value = object.amount if amount_captured_value.nil? && object.respond_to?(:amount)
89
+
44
90
  assign_attributes(
45
91
  amount: Money.new(object.amount, object.currency),
46
- amount_refunded: object.amount_refunded ? Money.new(object.amount_refunded, object.currency) : nil,
47
- application: object.application ? Money.new(object.application, object.currency) : nil
92
+ amount_captured: amount_captured_value.nil? ? nil : Money.new(amount_captured_value, object.currency),
93
+ amount_refunded: object.amount_refunded.nil? ? nil : Money.new(object.amount_refunded, object.currency),
94
+ application: object.try(:application).nil? ? nil : Money.new(object.application, object.currency)
48
95
  )
49
96
  end
50
97
  end
@@ -11,6 +11,7 @@ class StripeCoupon < StripeModelCallbacks::ApplicationRecord
11
11
  check_object_is_stripe_class(object)
12
12
  assign_attributes(
13
13
  amount_off: object.amount_off ? Money.new(object.amount_off, object.currency) : nil,
14
+ livemode: object.respond_to?(:livemode) ? object.livemode == true : false,
14
15
  stripe_valid: object.valid
15
16
  )
16
17
 
@@ -22,4 +23,15 @@ class StripeCoupon < StripeModelCallbacks::ApplicationRecord
22
23
  ]
23
24
  )
24
25
  end
26
+
27
+ def create_stripe_mock!
28
+ mock_coupon = Stripe::Coupon.create(
29
+ duration:,
30
+ duration_in_months:,
31
+ id: stripe_id,
32
+ percent_off:
33
+ )
34
+ assign_from_stripe(mock_coupon)
35
+ save!
36
+ end
25
37
  end