Class: RSpecStripe::Factory::Plan

Inherits:
Struct
  • Object
show all
Defined in:
lib/rspec-stripe/factories/plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/rspec-stripe/factories/plan.rb', line 2

def id
  @id
end

Instance Method Details

#cleanupObject



20
21
22
# File 'lib/rspec-stripe/factories/plan.rb', line 20

def cleanup
  get.delete if @should_delete
end

#getObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec-stripe/factories/plan.rb', line 3

def get
  @get ||= begin
    @should_delete = false
    Stripe::Plan.retrieve(id.to_s)
  rescue Stripe::InvalidRequestError
    @should_delete = true
    # Lookup the plan's details and then create it
    Stripe::Plan.create(
      amount: 2000,
      interval: 'month',
      name: 'Amazing Gold Plan',
      currency: 'usd',
      id: id.to_s
    )
  end
end