Module: Synthra::WebhookSimulator::Stripe

Defined in:
lib/synthra/webhook_simulator.rb

Overview

Simulate Stripe webhooks

Constant Summary collapse

EVENTS =
{
  payment_succeeded: "payment_intent.succeeded",
  payment_failed: "payment_intent.payment_failed",
  subscription_created: "customer.subscription.created",
  subscription_updated: "customer.subscription.updated",
  subscription_deleted: "customer.subscription.deleted",
  invoice_paid: "invoice.paid",
  invoice_payment_failed: "invoice.payment_failed",
  charge_succeeded: "charge.succeeded",
  charge_refunded: "charge.refunded"
}.freeze

Class Method Summary collapse

Class Method Details

.payment_succeeded(amount:, currency: "usd", **options) ⇒ Object



284
285
286
287
288
289
290
291
292
293
# File 'lib/synthra/webhook_simulator.rb', line 284

def payment_succeeded(amount:, currency: "usd", **options)
  WebhookSimulator.send("payment_intent.succeeded", data: {
    id: "pi_#{SecureRandom.hex(12)}",
    object: "payment_intent",
    amount: amount,
    currency: currency,
    status: "succeeded",
    created: Time.now.to_i
  }, **options)
end

.subscription_created(customer_id:, plan_id:, **options) ⇒ Object



295
296
297
298
299
300
301
302
303
304
# File 'lib/synthra/webhook_simulator.rb', line 295

def subscription_created(customer_id:, plan_id:, **options)
  WebhookSimulator.send("customer.subscription.created", data: {
    id: "sub_#{SecureRandom.hex(12)}",
    object: "subscription",
    customer: customer_id,
    items: { data: [{ price: { id: plan_id } }] },
    status: "active",
    created: Time.now.to_i
  }, **options)
end