Module: Webhookdb::Replicator::StripeV1Mixin
- Included in:
- StripeChargeV1, StripeCouponV1, StripeCustomerV1, StripeDisputeV1, StripeInvoiceItemV1, StripeInvoiceV1, StripePayoutV1, StripePriceV1, StripeProductV1, StripeRefundV1, StripeSubscriptionItemV1, StripeSubscriptionV1
- Defined in:
- lib/webhookdb/replicator/stripe_v1_mixin.rb
Instance Method Summary collapse
- #_fetch_backfill_page(pagination_token, **_kwargs) ⇒ Object
- #_mixin_backfill_url ⇒ Object
-
#_mixin_event_type_names ⇒ Object
this array describes which event this webhook should subscribe to stripe.com/docs/api/events/types.
- #_resource_and_event(request) ⇒ Object
- #_timestamp_column_name ⇒ Object
- #_verify_backfill_401_err_msg ⇒ Object
- #_verify_backfill_403_err_msg ⇒ Object
- #_verify_backfill_err_msg ⇒ Object
- #_webhook_response(request) ⇒ Object
- #calculate_backfill_state_machine ⇒ Object
- #calculate_webhook_state_machine ⇒ Object
- #restricted_key_resource_name ⇒ Object
Instance Method Details
#_fetch_backfill_page(pagination_token, **_kwargs) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 99 def _fetch_backfill_page(pagination_token, **_kwargs) url = self._mixin_backfill_url url += pagination_token if pagination_token.present? response = Webhookdb::Http.get( url, basic_auth: {username: self.service_integration.backfill_key}, logger: self.logger, timeout: Webhookdb::Stripe.http_timeout, ) data = response.parsed_response next_page_param = nil if data["has_more"] last_item_id = data["data"][-1]["id"] next_page_param = "?starting_after=" + last_item_id end return data["data"], next_page_param end |
#_mixin_backfill_url ⇒ Object
12 13 14 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 12 def _mixin_backfill_url raise NotImplementedError end |
#_mixin_event_type_names ⇒ Object
this array describes which event this webhook should subscribe to stripe.com/docs/api/events/types
18 19 20 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 18 def _mixin_event_type_names raise NotImplementedError end |
#_resource_and_event(request) ⇒ Object
6 7 8 9 10 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 6 def _resource_and_event(request) body = request.body return body.fetch("data").fetch("object"), body if body.fetch("object") == "event" return body, nil end |
#_timestamp_column_name ⇒ Object
26 27 28 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 26 def return :updated end |
#_verify_backfill_401_err_msg ⇒ Object
91 92 93 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 91 def _verify_backfill_401_err_msg return "It looks like that API Key is invalid. Please reenter the API Key you just created:" end |
#_verify_backfill_403_err_msg ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 83 def _verify_backfill_403_err_msg return "It looks like that API Key does not have permission to access #{self.resource_name_singular} Records. " \ "Please check the permissions by going to the list of restricted keys and " \ "hovering over the information icon in the entry for this key. " \ "Once you've verified or corrected the permissions for this key, " \ "please reenter the API Key you just created:" end |
#_verify_backfill_err_msg ⇒ Object
95 96 97 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 95 def _verify_backfill_err_msg return "An error occurred. Please reenter the API Key you just created:" end |
#_webhook_response(request) ⇒ Object
22 23 24 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 22 def _webhook_response(request) return Webhookdb::Stripe.webhook_response(request, self.service_integration.webhook_secret) end |
#calculate_backfill_state_machine ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 58 def calculate_backfill_state_machine step = Webhookdb::Replicator::StateMachineStep.new unless self.service_integration.backfill_key.present? step.output = %(In order to backfill #{self.resource_name_plural}, we need an API key. From your Stripe Dashboard, go to Developers -> API Keys -> Restricted Keys -> Create Restricted Key. Create a key with Read access to #{self.restricted_key_resource_name}. Submit, then copy the key when Stripe shows it to you: ) return step.secret_prompt("Restricted Key").backfill_key(self.service_integration) end unless (result = self.verify_backfill_credentials).verified self.service_integration.replicator.clear_backfill_information step.output = result. return step.secret_prompt("Restricted Key").backfill_key(self.service_integration) end step.output = %(Great! We are going to start backfilling your #{self.resource_name_plural}. #{self._query_help_output} ) return step.completed end |
#calculate_webhook_state_machine ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 30 def calculate_webhook_state_machine step = Webhookdb::Replicator::StateMachineStep.new unless self.service_integration.webhook_secret.present? step.output = %{You are about to start replicating #{self.resource_name_singular} info into WebhookDB. We've made an endpoint available for #{self.resource_name_singular} webhooks: #{self._webhook_endpoint} From your Stripe Dashboard, go to Developers -> Webhooks -> Add Endpoint. Use the URL above, and choose all of the following events: #{self._mixin_event_type_names.join("\n ")} Then click Add Endpoint. The page for the webhook will have a 'Signing Secret' section. Reveal it, then copy the secret (it will start with `whsec_`). } return step.secret_prompt("secret").webhook_secret(self.service_integration) end step.output = %(Great! WebhookDB is now listening for #{self.resource_name_singular} webhooks. #{self._query_help_output} In order to backfill existing #{self.resource_name_plural}, run this from a shell: #{self._backfill_command} ) return step.completed end |
#restricted_key_resource_name ⇒ Object
81 |
# File 'lib/webhookdb/replicator/stripe_v1_mixin.rb', line 81 def restricted_key_resource_name = self.resource_name_plural.gsub(/^Stripe /, "") |