Class: MyMoip::Purchase

Inherits:
Object
  • Object
show all
Defined in:
lib/mymoip/purchase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Purchase

Returns a new instance of Purchase.



6
7
8
9
10
11
12
# File 'lib/mymoip/purchase.rb', line 6

def initialize(attrs)
  @id          = attrs.fetch(:id) { rand }
  @price       = attrs.fetch(:price)
  @credit_card = MyMoip::CreditCard.new(attrs.fetch(:credit_card))
  @payer       = MyMoip::Payer.new(attrs.fetch(:payer))
  @reason      = attrs.fetch(:reason)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/mymoip/purchase.rb', line 4

def code
  @code
end

#credit_cardObject

Returns the value of attribute credit_card.



3
4
5
# File 'lib/mymoip/purchase.rb', line 3

def credit_card
  @credit_card
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/mymoip/purchase.rb', line 3

def id
  @id
end

#payerObject

Returns the value of attribute payer.



3
4
5
# File 'lib/mymoip/purchase.rb', line 3

def payer
  @payer
end

#priceObject

Returns the value of attribute price.



3
4
5
# File 'lib/mymoip/purchase.rb', line 3

def price
  @price
end

#reasonObject

Returns the value of attribute reason.



3
4
5
# File 'lib/mymoip/purchase.rb', line 3

def reason
  @reason
end

Instance Method Details

#checkout!Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/mymoip/purchase.rb', line 14

def checkout!
  authorization = get_authorization!
  payment = MyMoip::CreditCardPayment.new(@credit_card,
                                          installments: 1)
  request = MyMoip::PaymentRequest.new(@id)
  request.api_call(payment, token: authorization.token)

  @code = request.code
  request.success?
end