Class: Rev::Payment

Inherits:
ApiSerializable show all
Defined in:
lib/rev-api/models/order_request.rb

Overview

Payment Info. Payment can be done either by charging a credit card or by debiting the user’s account balance. If using a credit card, then either the user’s saved credit card can be used or credit card details provided.

For credit card payments, if specifying the credit card details in the request, the required elements are the card number, cardholder name, expiration month and year, and billing zipcode. If using the user’s saved card, you must currently specify the value “1” for the saved card id, as we currently only allow a single card to be saved for a user.

Constant Summary collapse

TYPES =

use to correctly set payment type

{
  :credit_card => 'CreditCard',
  :balance => 'AccountBalance'
}
CC_ON_FILE_ID =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiSerializable

#to_hash, #to_json

Constructor Details

#initialize(type, credit_card = nil) ⇒ Payment

Returns a new instance of Payment.

Parameters:

  • type (String)

    payment method

  • credit_card (CreditCard) (defaults to: nil)

    cc obj, if type is ‘CreditCard’



57
58
59
60
# File 'lib/rev-api/models/order_request.rb', line 57

def initialize(type, credit_card = nil)
  @type = type
  @credit_card = credit_card unless credit_card.nil?
end

Instance Attribute Details

#credit_cardObject

Returns the value of attribute credit_card.



45
46
47
# File 'lib/rev-api/models/order_request.rb', line 45

def credit_card
  @credit_card
end

#typeObject

Returns the value of attribute type.



45
46
47
# File 'lib/rev-api/models/order_request.rb', line 45

def type
  @type
end

Class Method Details

.with_account_balanceObject



71
72
73
# File 'lib/rev-api/models/order_request.rb', line 71

def ()
  Payment::new(TYPES[:account_balance])
end

.with_credit_card_on_fileObject



63
64
65
# File 'lib/rev-api/models/order_request.rb', line 63

def with_credit_card_on_file()
  Payment::new(TYPES[:credit_card], CreditCard.new(:saved_id => CC_ON_FILE_ID))
end

.with_saved_credit_card(credit_card) ⇒ Object



67
68
69
# File 'lib/rev-api/models/order_request.rb', line 67

def with_saved_credit_card(credit_card)
  Payment::new(TYPES[:credit_card], credit_card)
end