Class: Beanstream::PaymentsAPI

Inherits:
Transaction show all
Defined in:
lib/beanstream/payments_api.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Transaction

#encode, #handle_api_error, #handle_restclient_error, #transaction_post

Class Method Details

.generateRandomOrderId(prefix) ⇒ Object



15
16
17
# File 'lib/beanstream/payments_api.rb', line 15

def self.generateRandomOrderId(prefix)
  "#{prefix}_#{SecureRandom.hex(8)}"
end

.payment_approved(payment_response) ⇒ Object



138
139
140
# File 'lib/beanstream/payments_api.rb', line 138

def self.payment_approved(payment_response)
  success = payment_response['approved'] == "1" && payment_response['message'] == "Approved"
end

Instance Method Details

#complete_preauth(transaciton_id, amount) ⇒ Object



132
133
134
135
136
# File 'lib/beanstream/payments_api.rb', line 132

def complete_preauth(transaciton_id, amount)
  complete_url = make_payment_url+transaciton_id+"/completions"
  completion = { :amount => amount }
  val = transaction_post("POST", complete_url, Beanstream.merchant_id, Beanstream.payments_api_key, completion)
end

#get_legato_token(card_info) ⇒ Object



142
143
144
145
146
# File 'lib/beanstream/payments_api.rb', line 142

def get_legato_token(card_info)
  turl = "/scripts/tokenization/tokens"
  result = Transaction.new().transaction_post("POST", turl, "", "", card_info)
  token = result['token']
end

#get_transaction(transaction_id) ⇒ Object



148
149
150
# File 'lib/beanstream/payments_api.rb', line 148

def get_transaction(transaction_id)
  transaction_post("GET", get_transaction_url(transaction_id), Beanstream.merchant_id, Beanstream.payments_api_key)
end

#get_transaction_url(transaction_id) ⇒ Object



34
35
36
# File 'lib/beanstream/payments_api.rb', line 34

def get_transaction_url(transaction_id)
  "#{Beanstream.api_base_url}/payments/#{transaction_id}"
end

#getCardPaymentRequestTemplateObject

Payment Request Hash for making a payment with a credit card number



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/beanstream/payments_api.rb', line 51

def getCardPaymentRequestTemplate()
  request = getPaymentRequestTemplate()
  request[:payment_method] = PaymentMethods::CARD
  request[:card] = {
    :name => "",
    :number => "",
    :expiry_month => "",
    :expiry_year => "",
    :cvd => "",
    :complete => true
   }
   return request
end

#getPaymentRequestTemplateObject

Base Payment Request Hash for making a payments Use one of getTokenPaymentRequestTemplate, getCardPaymentRequestTemplate, or getProfilePaymentRequestTemplate

Required parameters

:amount, :order_number, :payment_method, and one of [:card, :token, :payment_profile] if not paying for Cash or Cheque.

Use PaymentMethods

for the available payment_method options



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/beanstream/payments_api.rb', line 81

def getPaymentRequestTemplate()
  request = {
    :order_number => "",
    :amount => 0,
    :language=> "",
    :customer_ip=> "",
    :term_url=> "",
    :comments=> "",
    :billing=> {
      :name=> "",
      :address_line1=> "",
      :address_line2=> "",
      :city=> "",
      :province=> "",
      :country=> "",
      :postal_code=> "",
      :phone_number=> "",
      :email_address=> ""
    },
    :shipping=> {
      :name=> "",
      :address_line1=> "",
      :address_line2=> "",
      :city=> "",
      :province=> "",
      :country=> "",
      :postal_code=> "",
      :phone_number=> "",
      :email_address=> ""
    },
    :custom=> {
      :ref1=> "",
      :ref2=> "",
      :ref3=> "",
      :ref4=> "",
      :ref5=> ""
    }
  }
end

#getProfilePaymentRequestTemplateObject

Payment Request Hash for making a payment with a Payment Profile



66
67
68
69
70
71
72
73
74
75
# File 'lib/beanstream/payments_api.rb', line 66

def getProfilePaymentRequestTemplate()
  request = getPaymentRequestTemplate()
  request[:payment_method] = PaymentMethods::PROFILE
  request[:payment_profile] = {
    :customer_code => "",
    :card_id => 1,
    :complete => true
  }
  return request
end

#getTokenPaymentRequestTemplateObject

Payment Request Hash for making a payment with a Legato token



39
40
41
42
43
44
45
46
47
48
# File 'lib/beanstream/payments_api.rb', line 39

def getTokenPaymentRequestTemplate()
  request = getPaymentRequestTemplate()
  request[:payment_method] = PaymentMethods::TOKEN
  request[:token] = {
    :name => "",
    :code => "",
    :complete => true
  }
  return request
end

#make_payment(payment) ⇒ Object

Make a payment. If the payment is approved the PaymentResponse will be returned. If for any reason the payment is declined or if there is a connection error an exception will be thrown. This will accept a PaymentRequest Hash as defined by getTokenPaymentRequestTemplate(), getCardPaymentRequestTemplate(), or getProfilePaymentRequestTemplate().

PreAuth

For a pre-auth you must set the ‘complete’ parameter of the Card, Token, or Profile to be ‘false’.



128
129
130
# File 'lib/beanstream/payments_api.rb', line 128

def make_payment(payment)
  val = transaction_post("POST", make_payment_url, Beanstream.merchant_id, Beanstream.payments_api_key, payment)
end

#make_payment_urlObject

Urls



22
23
24
# File 'lib/beanstream/payments_api.rb', line 22

def make_payment_url
  "#{Beanstream.api_base_url()}/payments/"
end

#payment_returns_url(transaction_id) ⇒ Object



26
27
28
# File 'lib/beanstream/payments_api.rb', line 26

def payment_returns_url(transaction_id)
  "#{Beanstream.api_base_url}/payments/#{transaction_id}/returns"
end

#payment_void_url(transaction_id) ⇒ Object



30
31
32
# File 'lib/beanstream/payments_api.rb', line 30

def payment_void_url(transaction_id)
  "#{Beanstream.api_base_url}/payments/#{transaction_id}/void"
end

#return_payment(transaction_id, amount) ⇒ Object



152
153
154
155
# File 'lib/beanstream/payments_api.rb', line 152

def return_payment(transaction_id, amount)
  data = { amount: amount }
  transaction_post("POST", payment_returns_url(transaction_id), Beanstream.merchant_id, Beanstream.payments_api_key, data)
end

#void_payment(transaction_id, amount) ⇒ Object



157
158
159
160
# File 'lib/beanstream/payments_api.rb', line 157

def void_payment(transaction_id, amount)
  data = { amount: amount }
  transaction_post("POST", payment_void_url(transaction_id), Beanstream.merchant_id, Beanstream.payments_api_key, data)
end