stripe_model_callbacks 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -1
  3. data/app/models/stripe_model_callbacks/application_record.rb +17 -0
  4. data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +1 -1
  5. data/app/services/stripe_model_callbacks/attributes_assigner_service.rb +1 -1
  6. data/app/services/stripe_model_callbacks/base_service.rb +37 -4
  7. data/app/services/stripe_model_callbacks/charge/dispute_updated_service.rb +1 -1
  8. data/app/services/stripe_model_callbacks/charge/updated_service.rb +1 -1
  9. data/app/services/stripe_model_callbacks/configure_service.rb +52 -24
  10. data/app/services/stripe_model_callbacks/coupon/sync_all.rb +9 -0
  11. data/app/services/stripe_model_callbacks/coupon/updated_service.rb +1 -1
  12. data/app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb +1 -1
  13. data/app/services/stripe_model_callbacks/customer/deleted_service.rb +1 -1
  14. data/app/services/stripe_model_callbacks/customer/discount_updated_service.rb +1 -1
  15. data/app/services/stripe_model_callbacks/customer/source_updated_service.rb +1 -1
  16. data/app/services/stripe_model_callbacks/customer/subscription/updated_service.rb +1 -1
  17. data/app/services/stripe_model_callbacks/customer/updated_service.rb +1 -1
  18. data/app/services/stripe_model_callbacks/event_mocker_service.rb +1 -1
  19. data/app/services/stripe_model_callbacks/invoice/updated_service.rb +1 -1
  20. data/app/services/stripe_model_callbacks/invoice_item/updated_service.rb +1 -1
  21. data/app/services/stripe_model_callbacks/notifier_service.rb +1 -1
  22. data/app/services/stripe_model_callbacks/order/updated_service.rb +1 -1
  23. data/app/services/stripe_model_callbacks/payout/updated_service.rb +1 -1
  24. data/app/services/stripe_model_callbacks/plan/sync_all.rb +9 -0
  25. data/app/services/stripe_model_callbacks/plan/updated_service.rb +1 -1
  26. data/app/services/stripe_model_callbacks/price/updated_service.rb +14 -0
  27. data/app/services/stripe_model_callbacks/product/updated_service.rb +1 -1
  28. data/app/services/stripe_model_callbacks/recipient/updated_service.rb +1 -1
  29. data/app/services/stripe_model_callbacks/refund/updated_service.rb +1 -1
  30. data/app/services/stripe_model_callbacks/review/updated_service.rb +1 -1
  31. data/app/services/stripe_model_callbacks/sku/updated_service.rb +1 -1
  32. data/app/services/stripe_model_callbacks/source/updated_service.rb +1 -1
  33. data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +2 -2
  34. data/app/services/stripe_model_callbacks/subscription_schedule/updated_service.rb +46 -0
  35. data/app/services/stripe_model_callbacks/sync_everything.rb +8 -0
  36. data/app/services/stripe_model_callbacks/sync_from_stripe.rb +29 -0
  37. data/app/services/stripe_model_callbacks/tax_rate/updated_service.rb +27 -0
  38. data/app/services/stripe_model_callbacks/transfer/updated_service.rb +1 -1
  39. data/config/routes.rb +1 -1
  40. data/db/migrate/20180206151132_change_activities_trackable_id_to_string.rb +1 -1
  41. data/db/migrate/20180208091647_change_stripe_subscription_items_quantity_to_integer.rb +1 -1
  42. data/db/migrate/20200317160513_add_auto_advance_and_billing_reason_to_stripe_invoices.rb +6 -0
  43. data/db/migrate/20200317160602_add_status_and_status_transitions_to_stripe_invoices.rb +10 -0
  44. data/db/migrate/20200317180115_add_product_type_to_products.rb +5 -0
  45. data/db/migrate/20200317181224_rename_stripe_invoices_application_fee_to_application_fee_amount.rb +6 -0
  46. data/db/migrate/20200320105158_make_stripe_invoices_forgive_optional.rb +5 -0
  47. data/db/migrate/20200320114859_make_stripe_invoice_closed_optional.rb +5 -0
  48. data/db/migrate/20200323143634_add_amount_paid_and_remaining_and_invoice_url_and_pdf.rb +11 -0
  49. data/db/migrate/20200331074940_add_unit_label_to_stripe_products.rb +5 -0
  50. data/db/migrate/20200331075241_add_metered_info_to_stripe_plans.rb +9 -0
  51. data/db/migrate/20200513131105_create_stripe_subscription_schedules.rb +31 -0
  52. data/db/migrate/20200513131120_create_stripe_subscription_schedule_phases.rb +21 -0
  53. data/db/migrate/20200513131640_create_stripe_subscription_schedule_phase_plans.rb +13 -0
  54. data/db/migrate/20200514132247_add_stripe_id_uniq_to_stripe_invoices.rb +8 -0
  55. data/db/migrate/20200520152604_change_stripe_subscription_schedule_phase_id_to_bigint.rb +27 -0
  56. data/db/migrate/20200529144649_add_latest_invoice_id_to_stripe_subscription.rb +5 -0
  57. data/db/migrate/20201223173035_rename_stripe_subscriptions_start_to_start_date.rb +5 -0
  58. data/db/migrate/20201223202117_create_stripe_tax_rates.rb +15 -0
  59. data/db/migrate/20201224120534_create_stripe_subscription_default_tax_rates.rb +9 -0
  60. data/db/migrate/20201224122058_create_stripe_prices.rb +26 -0
  61. data/db/migrate/20201224123838_add_stripe_price_to_stripe_subscription_items.rb +6 -0
  62. data/db/migrate/20211121155313_change_invoice_billing_to_nullable.rb +5 -0
  63. data/db/migrate/20211121155732_rename_invoices_billing_to_deprecated_billing.rb +5 -0
  64. data/lib/stripe_model_callbacks/configuration.rb +1 -1
  65. data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +16 -0
  66. data/lib/stripe_model_callbacks/factories/stripe_invoices.rb +1 -1
  67. data/lib/stripe_model_callbacks/factories/stripe_plans.rb +3 -1
  68. data/lib/stripe_model_callbacks/factories/stripe_prices.rb +3 -0
  69. data/lib/stripe_model_callbacks/factories/stripe_products.rb +13 -0
  70. data/lib/stripe_model_callbacks/factories/stripe_subscription_default_tax_rates.rb +6 -0
  71. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule.rb.rb +5 -0
  72. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phase_plan.rb +5 -0
  73. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phases.rb +5 -0
  74. data/lib/stripe_model_callbacks/factories/stripe_subscriptions.rb +1 -1
  75. data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +5 -0
  76. data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.created.json +29 -0
  77. data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.deleted.json +29 -0
  78. data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.updated.json +31 -0
  79. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.closed.json +65 -0
  80. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.created.json +65 -0
  81. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.funds_reinstated.json +65 -0
  82. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.funds_withdrawn.json +65 -0
  83. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.updated.json +96 -0
  84. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refund.updated.json +28 -0
  85. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refunded.json +98 -0
  86. data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.created.json +29 -0
  87. data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.deleted.json +29 -0
  88. data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.updated.json +31 -0
  89. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.bank_account.deleted.json +29 -0
  90. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.created.json +36 -0
  91. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.deleted.json +47 -0
  92. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.created.json +36 -0
  93. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.deleted.json +36 -0
  94. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.updated.json +55 -0
  95. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.created.card.json +80 -0
  96. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.created.json +53 -0
  97. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.deleted.json +53 -0
  98. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.expiring.json +53 -0
  99. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.updated.json +56 -0
  100. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.2020-12-24.json +112 -0
  101. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.json +84 -0
  102. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.deleted.json +83 -0
  103. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.trial_will_end.json +88 -0
  104. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.updated.json +100 -0
  105. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.updated.json +50 -0
  106. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.created.json +135 -0
  107. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_failed.json +100 -0
  108. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_succeeded.json +207 -0
  109. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.sent.json +100 -0
  110. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +100 -0
  111. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.updated.json +105 -0
  112. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.voided.json +152 -0
  113. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoiceitem/invoiceitem.created.json +34 -0
  114. data/lib/stripe_model_callbacks/fixtures/stripe_events/order/order.created.json +72 -0
  115. data/lib/stripe_model_callbacks/fixtures/stripe_events/order/order.updated.json +74 -0
  116. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.canceled.json +35 -0
  117. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.created.json +35 -0
  118. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.failed.json +35 -0
  119. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.paid.json +35 -0
  120. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.updated.json +37 -0
  121. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.created.json +32 -0
  122. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.deleted.json +27 -0
  123. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.updated.json +30 -0
  124. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.created.json +37 -0
  125. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.deleted.json +37 -0
  126. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.updated.json +40 -0
  127. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.created.json +49 -0
  128. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.deleted.json +48 -0
  129. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.updated.json +50 -0
  130. data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.created.json +37 -0
  131. data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.deleted.json +37 -0
  132. data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.updated.json +39 -0
  133. data/lib/stripe_model_callbacks/fixtures/stripe_events/review/review.closed.json +21 -0
  134. data/lib/stripe_model_callbacks/fixtures/stripe_events/review/review.opened.json +21 -0
  135. data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.created.json +36 -0
  136. data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.deleted.json +36 -0
  137. data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.updated.json +38 -0
  138. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.canceled.json +53 -0
  139. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.chargeable.json +53 -0
  140. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.failed.json +53 -0
  141. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.mandate_notification.json +53 -0
  142. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.transaction_created.json +21 -0
  143. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.canceled.json +81 -0
  144. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.created.json +77 -0
  145. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.updated.json +87 -0
  146. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.created.json +26 -0
  147. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.updated.json +29 -0
  148. data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.created.json +41 -0
  149. data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.reversed.json +40 -0
  150. data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.updated.json +44 -0
  151. data/lib/stripe_model_callbacks/models/stripe_bank_account.rb +1 -0
  152. data/lib/stripe_model_callbacks/models/stripe_card.rb +2 -1
  153. data/lib/stripe_model_callbacks/models/stripe_charge.rb +3 -0
  154. data/lib/stripe_model_callbacks/models/stripe_coupon.rb +1 -0
  155. data/lib/stripe_model_callbacks/models/stripe_customer.rb +4 -2
  156. data/lib/stripe_model_callbacks/models/stripe_discount.rb +10 -3
  157. data/lib/stripe_model_callbacks/models/stripe_dispute.rb +1 -0
  158. data/lib/stripe_model_callbacks/models/stripe_invoice.rb +62 -7
  159. data/lib/stripe_model_callbacks/models/stripe_invoice_item.rb +2 -0
  160. data/lib/stripe_model_callbacks/models/stripe_order.rb +1 -0
  161. data/lib/stripe_model_callbacks/models/stripe_order_item.rb +1 -0
  162. data/lib/stripe_model_callbacks/models/stripe_payout.rb +2 -1
  163. data/lib/stripe_model_callbacks/models/stripe_plan.rb +4 -1
  164. data/lib/stripe_model_callbacks/models/stripe_price.rb +27 -0
  165. data/lib/stripe_model_callbacks/models/stripe_product.rb +17 -7
  166. data/lib/stripe_model_callbacks/models/stripe_recipient.rb +1 -0
  167. data/lib/stripe_model_callbacks/models/stripe_refund.rb +1 -0
  168. data/lib/stripe_model_callbacks/models/stripe_review.rb +1 -0
  169. data/lib/stripe_model_callbacks/models/stripe_sku.rb +13 -6
  170. data/lib/stripe_model_callbacks/models/stripe_source.rb +4 -2
  171. data/lib/stripe_model_callbacks/models/stripe_subscription.rb +56 -6
  172. data/lib/stripe_model_callbacks/models/stripe_subscription_default_tax_rate.rb +4 -0
  173. data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +19 -1
  174. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +94 -0
  175. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase.rb +67 -0
  176. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase_plan.rb +37 -0
  177. data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +22 -0
  178. data/lib/stripe_model_callbacks/models/stripe_transfer.rb +1 -0
  179. data/lib/stripe_model_callbacks/version.rb +1 -1
  180. data/lib/stripe_model_callbacks.rb +1 -0
  181. metadata +176 -24
  182. data/app/assets/config/stripe_model_callbacks_manifest.js +0 -2
  183. data/app/assets/javascripts/stripe_model_callbacks/application.js +0 -13
  184. data/app/assets/stylesheets/stripe_model_callbacks/application.css +0 -15
  185. data/app/controllers/stripe_model_callbacks/application_controller.rb +0 -3
  186. data/app/jobs/stripe_model_callbacks/application_job.rb +0 -2
  187. data/app/mailers/stripe_model_callbacks/application_mailer.rb +0 -4
  188. data/app/views/layouts/stripe_model_callbacks/application.html.erb +0 -14
@@ -0,0 +1,77 @@
1
+ {
2
+ "id": "evt_1GhwDXJ3a8kmO8fm05cNl8dF",
3
+ "object": "event",
4
+ "api_version": "2019-05-16",
5
+ "created": 1589282651,
6
+ "data": {
7
+ "object": {
8
+ "id": "sub_sched_1GhwDXJ3a8kmO8fm97mybWCy",
9
+ "object": "subscription_schedule",
10
+ "billing": "charge_automatically",
11
+ "billing_thresholds": null,
12
+ "canceled_at": null,
13
+ "collection_method": "charge_automatically",
14
+ "completed_at": null,
15
+ "created": 1589282651,
16
+ "current_phase": null,
17
+ "customer": "cus_HG9JJV3LEHUjhO",
18
+ "default_payment_method": null,
19
+ "default_settings": {
20
+ "billing_thresholds": null,
21
+ "collection_method": "charge_automatically",
22
+ "default_payment_method": null,
23
+ "default_source": null,
24
+ "invoice_settings": null
25
+ },
26
+ "default_source": null,
27
+ "end_behavior": "cancel",
28
+ "invoice_settings": null,
29
+ "livemode": false,
30
+ "metadata": {
31
+ },
32
+ "phases": [
33
+ {
34
+ "add_invoice_items": [
35
+ ],
36
+ "application_fee_percent": null,
37
+ "billing_thresholds": null,
38
+ "collection_method": "charge_automatically",
39
+ "coupon": null,
40
+ "default_payment_method": null,
41
+ "default_tax_rates": [
42
+ ],
43
+ "end_date": 1606780800,
44
+ "invoice_settings": null,
45
+ "plans": [
46
+ {
47
+ "billing_thresholds": null,
48
+ "plan": "plan_HG4dIu1k8KqRWi",
49
+ "price": "plan_HG4dIu1k8KqRWi",
50
+ "quantity": 2,
51
+ "tax_rates": [
52
+ ]
53
+ }
54
+ ],
55
+ "prorate": true,
56
+ "proration_behavior": "create_prorations",
57
+ "start_date": 1590969600,
58
+ "tax_percent": null,
59
+ "trial_end": null
60
+ }
61
+ ],
62
+ "released_at": null,
63
+ "released_subscription": null,
64
+ "renewal_behavior": "cancel",
65
+ "renewal_interval": null,
66
+ "status": "not_started",
67
+ "subscription": null
68
+ }
69
+ },
70
+ "livemode": false,
71
+ "pending_webhooks": 1,
72
+ "request": {
73
+ "id": "req_5afiaPgOrP3nYc",
74
+ "idempotency_key": null
75
+ },
76
+ "type": "subscription_schedule.created"
77
+ }
@@ -0,0 +1,87 @@
1
+ {
2
+ "id": "evt_1Ghw7aJ3a8kmO8fm2vPIdi50",
3
+ "object": "event",
4
+ "api_version": "2019-05-16",
5
+ "created": 1589282282,
6
+ "data": {
7
+ "object": {
8
+ "id": "sub_sched_1GhdpNJ3a8kmO8fmNG2vKBYY",
9
+ "object": "subscription_schedule",
10
+ "billing": "charge_automatically",
11
+ "billing_thresholds": null,
12
+ "canceled_at": null,
13
+ "collection_method": "charge_automatically",
14
+ "completed_at": null,
15
+ "created": 1589211961,
16
+ "current_phase": null,
17
+ "customer": "cus_HG9VgDZsSjwhZG",
18
+ "default_payment_method": null,
19
+ "default_settings": {
20
+ "billing_thresholds": null,
21
+ "collection_method": "charge_automatically",
22
+ "default_payment_method": null,
23
+ "default_source": null,
24
+ "invoice_settings": {
25
+ "days_until_due": null
26
+ }
27
+ },
28
+ "default_source": null,
29
+ "end_behavior": "release",
30
+ "invoice_settings": {
31
+ "days_until_due": null
32
+ },
33
+ "livemode": false,
34
+ "metadata": {
35
+ },
36
+ "phases": [
37
+ {
38
+ "add_invoice_items": [
39
+ ],
40
+ "application_fee_percent": null,
41
+ "billing_thresholds": null,
42
+ "collection_method": "charge_automatically",
43
+ "coupon": null,
44
+ "default_payment_method": null,
45
+ "default_tax_rates": [
46
+ ],
47
+ "end_date": 1623456000,
48
+ "invoice_settings": null,
49
+ "plans": [
50
+ {
51
+ "billing_thresholds": null,
52
+ "plan": "plan_HG4dIu1k8KqRWi",
53
+ "price": "plan_HG4dIu1k8KqRWi",
54
+ "quantity": 1,
55
+ "tax_rates": [
56
+ ]
57
+ }
58
+ ],
59
+ "prorate": true,
60
+ "proration_behavior": "create_prorations",
61
+ "start_date": 1620777600,
62
+ "tax_percent": null,
63
+ "trial_end": null
64
+ }
65
+ ],
66
+ "released_at": null,
67
+ "released_subscription": null,
68
+ "renewal_behavior": "release",
69
+ "renewal_interval": null,
70
+ "status": "not_started",
71
+ "subscription": null
72
+ },
73
+ "previous_attributes": {
74
+ "default_settings": {
75
+ "invoice_settings": null
76
+ },
77
+ "invoice_settings": null
78
+ }
79
+ },
80
+ "livemode": false,
81
+ "pending_webhooks": 2,
82
+ "request": {
83
+ "id": "req_sx6SHFvO3ZyCYh",
84
+ "idempotency_key": null
85
+ },
86
+ "type": "subscription_schedule.updated"
87
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "tax_rate.created",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-02-06",
10
+ "data": {
11
+ "object": {
12
+ "id": "txr_00000000000000",
13
+ "object": "tax_rate",
14
+ "active": true,
15
+ "created": 1608755171,
16
+ "description": "VAT Germany",
17
+ "display_name": "VAT",
18
+ "inclusive": false,
19
+ "jurisdiction": "DE",
20
+ "livemode": false,
21
+ "metadata": {
22
+ },
23
+ "percentage": 16
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "tax_rate.updated",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-02-06",
10
+ "data": {
11
+ "object": {
12
+ "id": "txr_00000000000000",
13
+ "object": "tax_rate",
14
+ "active": true,
15
+ "created": 1608755201,
16
+ "description": "VAT Germany",
17
+ "display_name": "VAT",
18
+ "inclusive": false,
19
+ "jurisdiction": "DE",
20
+ "livemode": false,
21
+ "metadata": {
22
+ },
23
+ "percentage": 16
24
+ },
25
+ "previous_attributes": {
26
+ "display_name": "Old name"
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "transfer.created",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-01-23",
10
+ "data": {
11
+ "object": {
12
+ "id": "tr_00000000000000",
13
+ "object": "transfer",
14
+ "amount": 1100,
15
+ "amount_reversed": 0,
16
+ "balance_transaction": "txn_00000000000000",
17
+ "created": 1517907211,
18
+ "currency": "usd",
19
+ "description": null,
20
+ "destination": "acct_1Brq15AT5SYrvIfd",
21
+ "destination_payment": "py_CH0DW4ihzdQQCd",
22
+ "livemode": false,
23
+ "metadata": {
24
+ },
25
+ "reversals": {
26
+ "object": "list",
27
+ "data": [
28
+
29
+ ],
30
+ "has_more": false,
31
+ "total_count": 0,
32
+ "url": "/v1/transfers/tr_1BsSClAT5SYrvIfdN12tbSTG/reversals"
33
+ },
34
+ "reversed": false,
35
+ "source_transaction": null,
36
+ "source_type": "card",
37
+ "transfer_group": null,
38
+ "status": "pending"
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "transfer.reversed",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-01-23",
10
+ "data": {
11
+ "object": {
12
+ "id": "tr_00000000000000",
13
+ "object": "transfer",
14
+ "amount": 1100,
15
+ "amount_reversed": 0,
16
+ "balance_transaction": "txn_00000000000000",
17
+ "created": 1517907289,
18
+ "currency": "usd",
19
+ "description": null,
20
+ "destination": "acct_1Brq15AT5SYrvIfd",
21
+ "destination_payment": "py_CH0EOf6bFQq9g2",
22
+ "livemode": false,
23
+ "metadata": {
24
+ },
25
+ "reversals": {
26
+ "object": "list",
27
+ "data": [
28
+
29
+ ],
30
+ "has_more": false,
31
+ "total_count": 0,
32
+ "url": "/v1/transfers/tr_1BsSE1AT5SYrvIfdP8OdqFvQ/reversals"
33
+ },
34
+ "reversed": false,
35
+ "source_transaction": null,
36
+ "source_type": "card",
37
+ "transfer_group": null
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "transfer.updated",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-01-23",
10
+ "data": {
11
+ "object": {
12
+ "id": "tr_00000000000000",
13
+ "object": "transfer",
14
+ "amount": 1100,
15
+ "amount_reversed": 0,
16
+ "balance_transaction": "txn_00000000000000",
17
+ "created": 1517907302,
18
+ "currency": "usd",
19
+ "description": null,
20
+ "destination": "acct_1Brq15AT5SYrvIfd",
21
+ "destination_payment": "py_CH0EWJqnvFoKjv",
22
+ "livemode": false,
23
+ "metadata": {
24
+ },
25
+ "reversals": {
26
+ "object": "list",
27
+ "data": [
28
+
29
+ ],
30
+ "has_more": false,
31
+ "total_count": 0,
32
+ "url": "/v1/transfers/tr_1BsSEEAT5SYrvIfdWexl6CKu/reversals"
33
+ },
34
+ "reversed": false,
35
+ "source_transaction": null,
36
+ "source_type": "card",
37
+ "transfer_group": null,
38
+ "status": "pending"
39
+ },
40
+ "previous_attributes": {
41
+ "description": "Old description"
42
+ }
43
+ }
44
+ }
@@ -4,6 +4,7 @@ class StripeBankAccount < StripeModelCallbacks::ApplicationRecord
4
4
  end
5
5
 
6
6
  def assign_from_stripe(object)
7
+ check_object_is_stripe_class(object)
7
8
  assign_attributes(stripe_account_id: object.account)
8
9
 
9
10
  StripeModelCallbacks::AttributesAssignerService.execute!(
@@ -6,6 +6,7 @@ class StripeCard < StripeModelCallbacks::ApplicationRecord
6
6
  end
7
7
 
8
8
  def assign_from_stripe(object)
9
+ check_object_is_stripe_class(object)
9
10
  self.stripe_customer_id = object.customer if object.respond_to?(:customer)
10
11
 
11
12
  StripeModelCallbacks::AttributesAssignerService.execute!(
@@ -20,6 +21,6 @@ class StripeCard < StripeModelCallbacks::ApplicationRecord
20
21
  end
21
22
 
22
23
  def to_stripe
23
- @to_stripe ||= Stripe::Customer.retrieve(stripe_customer_id).sources.retrieve(stripe_id)
24
+ @to_stripe ||= Stripe::Customer.retrieve_source(stripe_customer_id, stripe_id)
24
25
  end
25
26
  end
@@ -1,5 +1,7 @@
1
1
  class StripeCharge < StripeModelCallbacks::ApplicationRecord
2
2
  belongs_to :stripe_customer, optional: true, primary_key: "stripe_id"
3
+ belongs_to :stripe_invoice, optional: true, primary_key: "stripe_id"
4
+ belongs_to :stripe_source, optional: true, primary_key: "stripe_id"
3
5
  has_many :stripe_orders, primary_key: "stripe_id"
4
6
  has_many :stripe_refunds, primary_key: "stripe_id"
5
7
  has_many :stripe_reviews, primary_key: "stripe_id"
@@ -13,6 +15,7 @@ class StripeCharge < StripeModelCallbacks::ApplicationRecord
13
15
  end
14
16
 
15
17
  def assign_from_stripe(object)
18
+ check_object_is_stripe_class(object)
16
19
  assign_attributes(
17
20
  created: Time.zone.at(object.created),
18
21
  stripe_customer_id: object.customer,
@@ -8,6 +8,7 @@ class StripeCoupon < StripeModelCallbacks::ApplicationRecord
8
8
  end
9
9
 
10
10
  def assign_from_stripe(object)
11
+ check_object_is_stripe_class(object)
11
12
  assign_attributes(
12
13
  amount_off: object.amount_off ? Money.new(object.amount_off, object.currency) : nil,
13
14
  stripe_valid: object.valid
@@ -6,17 +6,19 @@ class StripeCustomer < StripeModelCallbacks::ApplicationRecord
6
6
  has_many :stripe_invoice_items, primary_key: "stripe_id"
7
7
  has_many :stripe_orders, primary_key: "stripe_id"
8
8
  has_many :stripe_subscriptions, primary_key: "stripe_id"
9
+ has_many :stripe_subscription_schedules, primary_key: "stripe_id"
9
10
 
10
11
  def self.stripe_class
11
12
  Stripe::Customer
12
13
  end
13
14
 
14
15
  def assign_from_stripe(object)
16
+ check_object_is_stripe_class(object)
15
17
  StripeModelCallbacks::AttributesAssignerService.execute!(
16
18
  model: self, stripe_model: object,
17
19
  attributes: %w[
18
- account_balance currency created delinquent description discount email id
19
- livemode metadata
20
+ account_balance currency created default_source delinquent description discount email
21
+ id livemode metadata
20
22
  ]
21
23
  )
22
24
  end
@@ -14,12 +14,19 @@ class StripeDiscount < StripeModelCallbacks::ApplicationRecord
14
14
  end
15
15
 
16
16
  def assign_from_stripe(object)
17
+ check_object_is_stripe_class(object)
18
+ if object.respond_to?(:customer)
19
+ customer_id = object.customer
20
+ else
21
+ customer_id = Stripe::Subscription.retrieve(object.subscription).customer
22
+ end
23
+
17
24
  assign_attributes(
18
25
  created: object.respond_to?(:created) ? Time.zone.at(object.created) : nil,
19
26
  start: Time.zone.at(object.start),
20
27
  end: object.end ? Time.zone.at(object.end) : nil,
21
28
  stripe_coupon_id: object.coupon.id,
22
- stripe_customer_id: object.customer,
29
+ stripe_customer_id: customer_id,
23
30
  stripe_subscription_id: object.subscription
24
31
  )
25
32
 
@@ -32,11 +39,11 @@ private
32
39
  def assign_coupon_attributes(object)
33
40
  assign_attributes(
34
41
  coupon_amount_off_cents: object.coupon.amount_off ? Money.new(object.coupon.amount_off, object.coupon.currency) : nil,
35
- coupon_created: Time.zone.at(object.coupon.created),
42
+ coupon_created: object.coupon.respond_to?(:created) ? Time.zone.at(object.coupon.created) : nil,
36
43
  coupon_currency: object.coupon.currency,
37
44
  coupon_duration: object.coupon.duration,
38
45
  coupon_duration_in_months: object.coupon.duration_in_months,
39
- coupon_livemode: object.coupon.livemode
46
+ coupon_livemode: object.coupon.respond_to?(:livemode) ? object.coupon.livemode : nil
40
47
  )
41
48
  end
42
49
 
@@ -6,6 +6,7 @@ class StripeDispute < StripeModelCallbacks::ApplicationRecord
6
6
  end
7
7
 
8
8
  def assign_from_stripe(object)
9
+ check_object_is_stripe_class(object)
9
10
  assign_attributes(
10
11
  amount: Money.new(object.amount, object.currency),
11
12
  balance_transaction_id: object.balance_transaction,
@@ -1,12 +1,17 @@
1
1
  class StripeInvoice < StripeModelCallbacks::ApplicationRecord
2
+ belongs_to :stripe_charge, optional: true, primary_key: "stripe_id"
2
3
  belongs_to :stripe_customer, optional: true, primary_key: "stripe_id"
3
4
  belongs_to :stripe_discount, optional: true
4
5
  belongs_to :stripe_subscription, optional: true, primary_key: "stripe_id"
5
6
 
6
7
  has_many :stripe_invoice_items, autosave: true, primary_key: "stripe_id"
7
8
 
9
+ validates :stripe_id, uniqueness: true
10
+
8
11
  monetize :amount_due_cents, allow_nil: true
9
- monetize :application_fee_cents, allow_nil: true
12
+ monetize :amount_paid_cents, allow_nil: true
13
+ monetize :amount_remaining_cents, allow_nil: true
14
+ monetize :application_fee_amount_cents, allow_nil: true
10
15
  monetize :subtotal_cents, allow_nil: true
11
16
  monetize :tax_cents, allow_nil: true
12
17
  monetize :total_cents, allow_nil: true
@@ -16,6 +21,7 @@ class StripeInvoice < StripeModelCallbacks::ApplicationRecord
16
21
  end
17
22
 
18
23
  def assign_from_stripe(object)
24
+ check_object_is_stripe_class(object)
19
25
  assign_attributes(
20
26
  stripe_charge_id: object.charge,
21
27
  stripe_customer_id: object.customer,
@@ -25,15 +31,24 @@ class StripeInvoice < StripeModelCallbacks::ApplicationRecord
25
31
  period_end: Time.zone.at(object.period_end)
26
32
  )
27
33
 
34
+ assign_closed(object)
28
35
  assign_created(object)
36
+
29
37
  assign_amounts(object)
38
+ assign_discount_item(object)
39
+ assign_tax(object)
40
+
41
+ assign_forgiven(object)
42
+ assign_status_transitions(object)
30
43
 
31
44
  StripeModelCallbacks::AttributesAssignerService.execute!(
32
45
  model: self, stripe_model: object,
33
46
  attributes: %w[
34
- attempted attempt_count billing closed currency description forgiven id livemode
35
- ending_balance forgiven next_payment_attempt number paid receipt_number
36
- starting_balance statement_descriptor tax_percent
47
+ attempted attempt_count auto_advance billing_reason
48
+ collection_method currency description ending_balance hosted_invoice_url
49
+ id invoice_pdf livemode next_payment_attempt number
50
+ paid receipt_number starting_balance statement_descriptor
51
+ status tax_percent
37
52
  ]
38
53
  )
39
54
 
@@ -45,14 +60,23 @@ private
45
60
  def assign_amounts(object)
46
61
  assign_attributes(
47
62
  amount_due: Money.new(object.amount_due, object.currency),
48
- application_fee: object.application_fee ? Money.new(object.application_fee, object.currency) : nil,
49
- stripe_discount_id: stripe_discount_id_from_object(object),
63
+ amount_paid: Money.new(object.amount_paid, object.currency),
64
+ amount_remaining: Money.new(object.amount_remaining, object.currency),
65
+ application_fee_amount: object.application_fee_amount ? Money.new(object.application_fee_amount, object.currency) : nil,
50
66
  subtotal: Money.new(object.subtotal, object.currency),
51
- tax: object.tax ? Money.new(object.tax, object.currency) : nil,
52
67
  total: object.total ? Money.new(object.total, object.currency) : nil
53
68
  )
54
69
  end
55
70
 
71
+ def assign_closed(object)
72
+ # The date-field was changed to auto_advance on 2018-11-08
73
+ if object.respond_to?(:closed)
74
+ self.closed = object.closed
75
+ else
76
+ self.closed = object.auto_advance == false
77
+ end
78
+ end
79
+
56
80
  def assign_created(object)
57
81
  # The date-field was renamed to created on 2019-03-14
58
82
  if object.respond_to?(:date)
@@ -62,6 +86,19 @@ private
62
86
  end
63
87
  end
64
88
 
89
+ def assign_discount_item(object)
90
+ self.stripe_discount_id = stripe_discount_id_from_object(object)
91
+ end
92
+
93
+ def assign_forgiven(object)
94
+ # The date-field was changed 2018-11-08
95
+ if object.respond_to?(:forgiven)
96
+ self.forgiven = object.forgiven
97
+ else
98
+ self.forgiven = object.status == "uncollectible"
99
+ end
100
+ end
101
+
65
102
  def assign_invoice_items(object)
66
103
  object.lines.each do |item|
67
104
  # Has to be found this way to actually update the values
@@ -77,6 +114,24 @@ private
77
114
  end
78
115
  end
79
116
 
117
+ def assign_status_transitions(object)
118
+ return unless object.respond_to?(:status_transitions)
119
+
120
+ transition_dates = {}
121
+ %i[finalized_at marked_uncollectible_at paid_at voided_at].each do |date_attribute|
122
+ date_value = object.status_transitions.__send__(date_attribute)
123
+ transition_dates[date_attribute] = Time.zone.at(date_value) if date_value.present?
124
+ end
125
+
126
+ assign_attributes(transition_dates) if transition_dates.any?
127
+ end
128
+
129
+ def assign_tax(object)
130
+ return unless object.tax
131
+
132
+ self.tax = Money.new(object.tax, object.currency)
133
+ end
134
+
80
135
  def stripe_discount_id_from_object(object)
81
136
  return nil unless object.discount
82
137
 
@@ -1,6 +1,7 @@
1
1
  class StripeInvoiceItem < 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_subscription, optional: true, primary_key: "stripe_id"
4
5
  belongs_to :stripe_subscription_item, optional: true, primary_key: "stripe_id"
5
6
  belongs_to :stripe_plan, optional: true, primary_key: "stripe_id"
6
7
 
@@ -11,6 +12,7 @@ class StripeInvoiceItem < StripeModelCallbacks::ApplicationRecord
11
12
  end
12
13
 
13
14
  def assign_from_stripe(object)
15
+ check_object_is_stripe_class(object, [Stripe::InvoiceItem, Stripe::InvoiceLineItem])
14
16
  assign_attributes(
15
17
  amount: Money.new(object.amount, object.currency),
16
18
  stripe_customer_id: object.try(:customer),
@@ -12,6 +12,7 @@ class StripeOrder < StripeModelCallbacks::ApplicationRecord
12
12
  end
13
13
 
14
14
  def assign_from_stripe(object)
15
+ check_object_is_stripe_class(object)
15
16
  assign_attributes(
16
17
  stripe_charge_id: object.charge,
17
18
  created: Time.zone.at(object.created),
@@ -8,6 +8,7 @@ class StripeOrderItem < StripeModelCallbacks::ApplicationRecord
8
8
  end
9
9
 
10
10
  def assign_from_stripe(object)
11
+ check_object_is_stripe_class(object)
11
12
  assign_attributes(
12
13
  amount: Money.new(object.amount, object.currency),
13
14
  currency: object.currency,
@@ -2,10 +2,11 @@ class StripePayout < StripeModelCallbacks::ApplicationRecord
2
2
  monetize :amount_cents, allow_nil: true
3
3
 
4
4
  def self.stripe_class
5
- Stripe::Subscription
5
+ Stripe::Payout
6
6
  end
7
7
 
8
8
  def assign_from_stripe(object)
9
+ check_object_is_stripe_class(object)
9
10
  assign_attributes(
10
11
  amount: Money.new(object.amount, object.currency),
11
12
  arrival_date: Time.zone.at(object.arrival_date),
@@ -14,14 +14,17 @@ class StripePlan < StripeModelCallbacks::ApplicationRecord
14
14
  end
15
15
 
16
16
  def assign_from_stripe(object)
17
+ check_object_is_stripe_class(object)
18
+ self.active = object.active == true if object.respond_to?(:active)
17
19
  assign_attributes(amount: Money.new(object.amount, object.currency))
18
20
  self.stripe_product_id = object.product if object.respond_to?(:product)
19
21
 
20
22
  StripeModelCallbacks::AttributesAssignerService.execute!(
21
23
  model: self, stripe_model: object,
22
24
  attributes: %w[
25
+ aggregate_usage amount_decimal billing_scheme
23
26
  created currency id interval interval_count livemode metadata nickname statement_descriptor
24
- trial_period_days
27
+ trial_period_days usage_type
25
28
  ]
26
29
  )
27
30
  end