Class: MyMoip::Purchase
- Inherits:
-
Object
- Object
- MyMoip::Purchase
- Defined in:
- lib/mymoip/purchase.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#credit_card ⇒ Object
Returns the value of attribute credit_card.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payer ⇒ Object
Returns the value of attribute payer.
-
#price ⇒ Object
Returns the value of attribute price.
-
#reason ⇒ Object
Returns the value of attribute reason.
Instance Method Summary collapse
- #checkout! ⇒ Object
-
#initialize(attrs) ⇒ Purchase
constructor
A new instance of Purchase.
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/mymoip/purchase.rb', line 4 def code @code end |
#credit_card ⇒ Object
Returns the value of attribute credit_card.
3 4 5 |
# File 'lib/mymoip/purchase.rb', line 3 def credit_card @credit_card end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/mymoip/purchase.rb', line 3 def id @id end |
#payer ⇒ Object
Returns the value of attribute payer.
3 4 5 |
# File 'lib/mymoip/purchase.rb', line 3 def payer @payer end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/mymoip/purchase.rb', line 3 def price @price end |
#reason ⇒ Object
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! = payment = MyMoip::CreditCardPayment.new(@credit_card, installments: 1) request = MyMoip::PaymentRequest.new(@id) request.api_call(payment, token: .token) @code = request.code request.success? end |