class DidwwUps::Store

Constants

APPEND_CREDIT_CARD_PATH
NEW_CREDIT_CARD_PATH

Public Class Methods

profile() click to toggle source

Retrieves profile information for current store

profile = DidwwUps::Store.profile
# => "{\"api_public_key\":\"somekey\",\"api_secret_key\":\"somesecret\",\"callback_url\":\"http://yoursite.com/callback.php\",\"created_at\":\"2012-12-24T11:03:36Z\",\"enabled\":true,\"id\":1,\"ip\":null,\"name\":\"mystore\",\"terminal_id\":1,\"updated_at\":\"2013-01-09T12:27:01Z\",\"details\":{\"terminal_id\":1,\"currency_sign\":\"USD\",\"modules\":[\"Stripe\",\"Braintree\"]}}"
# File lib/didww_ups/store.rb, line 16
def self.profile
  self.get(:profile)
end

Public Instance Methods

append_credit_card_uri(customer_id, options = {}) click to toggle source
# File lib/didww_ups/store.rb, line 37
def append_credit_card_uri(customer_id,  options = {})
  credit_card_uri(APPEND_CREDIT_CARD_PATH, customer_id, options)     
end
credit_card_params(customer_id, options = {}) click to toggle source
# File lib/didww_ups/store.rb, line 48
def credit_card_params(customer_id, options = {})
  date_time = formatted_date_time
  card_id = options.has_key?(:card_id) ? options.delete(:card_id) : nil
  signed_hash = new_credit_card_uri_hash(customer_id, card_id, date_time)
  options.merge({customer_id: customer_id,
                            card_id: card_id,
                            date_time: date_time,
                            public_key: self['api_public_key'],
                            hash: signed_hash })
end
credit_card_uri(path, customer_id, options) click to toggle source
# File lib/didww_ups/store.rb, line 42
def credit_card_uri(path, customer_id, options)
   URI::HTTPS.build(host: DidwwUps.service_host,
                     path: path,
                     query: credit_card_params(customer_id, options).to_query)
end
new_credit_card_uri(customer_id, options = {}) click to toggle source

Builds new uri for customer to enter credit card info

  • Returns : URI::HTTPS object

Example

<URI::HTTPS:0x007fa62377cfb0 URL:https://google.com/api/iframe/new?customer_id=1&date_time=2014-06-05+21%3A30%3A46&hash=4452d71687b6bc2c9389c3349fdc17fbd73b833b&public_key=public>
 * +customer_id+ - unique string for customer or customer/credit-card combination
 * +card_id+ - card id unique for customer_id
 * +date_time+ - current utc datetime
 * +public_key+ - public api key number
 * +hash+ - SHA1 of next string  = api_secret_key+date_time+customer_id+ card_id
# File lib/didww_ups/store.rb, line 32
def new_credit_card_uri(customer_id,  options = {})
   credit_card_uri(NEW_CREDIT_CARD_PATH, customer_id, options)  
end
new_credit_card_uri_hash(customer_id, card_id, date_time) click to toggle source
# File lib/didww_ups/store.rb, line 108
def new_credit_card_uri_hash(customer_id, card_id, date_time)
  Digest::SHA1.hexdigest(self['api_secret_key'] + date_time + customer_id.to_s + card_id.to_s)
end
request_token(path, method) click to toggle source

method to generate authorization header token value

# File lib/didww_ups/store.rb, line 101
def request_token(path, method)
  date_time = formatted_date_time

  sign = Digest::SHA1.hexdigest "#{self['api_secret_key']}#{date_time}#{method.to_s.upcase}#{path}"
  "#{Base64.urlsafe_encode64("#{self['api_public_key']}:#{sign}").strip}, date_time=#{date_time},type=v1"
end
retrieve_credit_card(params= {}) click to toggle source
Build credit card instance from callback uri params

Params

  • success - 0/1 (1 - YES)

  • credit_card_expired - (credit card expiration YEAR-month)

  • credit_card_number - (masked card number)

  • credit_card_type - (credit card type upcased)

  • customer_id - (customer id, that opened the iframe - check if currently logged in )

  • date_time - UTC datetime (2014-06-06:09:19:16:000)

  • result - =error string if success equal to 0 , credit card ups token other-way.

  • secure_hash - SHA1 of result + success + customer_id + date_time + api_secret_key

Example success

#card_id=1&credit_card_expired=2020-06&credit_card_number=540400%2A%2A%2A%2A%2A%2A0001&credit_card_type=MASTERCARD&customer_id=test&date_time=2014-06-06%3A09%3A19%3A16%3A000&result=4UHSmRkBMhWtHloKQfkjVQ&secure_hash=e4817a8fdb5885248c5f6c6044f4c8707016f013&store=worldnet&success=1

Example failed

#credit_card_expired=&credit_card_number=&credit_card_type=&customer_id=1&date_time=2014-06-06%3A08%3A12%3A35%3A000&result=AVS+FAILURE&secure_hash=b5d63a10ca10e086dd3e087975b7eff4883f0216&success=0
# File lib/didww_ups/store.rb, line 76
def retrieve_credit_card(params= {})

  DidwwUps::CreditCard.new({
                               result: params["result"],
                               customer_id: params['customer_id'],
                               credit_card_expired: params['credit_card_expired'],
                               credit_card_type: params['credit_card_type'],
                               store_id: self.id,
                               credit_card_number: params['credit_card_number'],
                               secure_hash: params['secure_hash'],
                               date_time: params['date_time'],
                               success: params['success'],
                               card_id: params['card_id']
                           })

end
retrieve_credit_card!(params) click to toggle source

raises InvalidRequest

# File lib/didww_ups/store.rb, line 94
def retrieve_credit_card!(params)
  credit_card = retrieve_credit_card(params)
  raise InvalidRequest.new(credit_card.errors.full_messages.join(",")) unless credit_card.valid?
  credit_card
end

Protected Instance Methods

formatted_date_time() click to toggle source
# File lib/didww_ups/store.rb, line 114
def formatted_date_time
  Time.now.utc.strftime("%F %T")
end