Class: RubyEcommClient::ServicePurchase

Inherits:
ServiceBase show all
Defined in:
lib/ruby-ecomm-client/service_purchase.rb

Constant Summary collapse

ENDPOINTS_PURCHASE =
{
  :development => 'https://bonsaipurchase.dev.glbt1.gdg/BonsaiPurchase/Service.asmx',
  :production  => 'https://bonsaipurchase.prod.phx3.gdg/BonsaiPurchase/Service.asmx',
  :qa          => 'https://bonsaipurchase.test.glbt1.gdg/BonsaiPurchase/Service.asmx',
  :test        => 'https://bonsaipurchase.dev.glbt1.gdg/BonsaiPurchase/Service.asmx'
}
HOST_NAME =
`hostname`.chomp
WSDL_PURCHASE =
'purchase.wsdl'

Constants inherited from ServiceBase

RubyEcommClient::ServiceBase::ID_TYPE

Instance Method Summary collapse

Methods inherited from ServiceBase

#initialize

Methods included from Utils

included

Constructor Details

This class inherits a constructor from RubyEcommClient::ServiceBase

Instance Method Details

#request_change(target_tree_id, client_ip = '127.0.0.1') ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
# File 'lib/ruby-ecomm-client/service_purchase.rb', line 14

def request_change(target_tree_id, client_ip = '127.0.0.1')
  raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)

  if config_client.express_checkout?
    request_change_via_express(target_tree_id, client_ip)
  else
    config_client.request_change_via_manager(target_tree_id)
  end
end

#request_change_via_express(target_tree_id, client_ip = '127.0.0.1') ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby-ecomm-client/service_purchase.rb', line 24

def request_change_via_express(target_tree_id, client_ip = '127.0.0.1')
  raise ArgumentError.new('target_tree_id must be specified') if blank?(target_tree_id)
  config_global.validate

  request_hash = generate_request_change_hash
  request_hash['AccountPurchaseChangeXml'] = %W(
    <ClientChange
      TreeID='#{target_tree_id}'
      ShopperID='#{config_client.shopper_id}'
      TransactionCurrency='USD'
      RequestingApp='#{config_global.requesting_app}'
      RequestingAppHost='#{HOST_NAME}'
      ClientAddr='#{client_ip}'
      EnteredBy='customer'
      OrderSource='Online'
      RedirectToBasket='false'
      EstimateOnly='false'
      SendConfirmEmail='false'/>
  ).join(' ')

  result = client_purchase.call(:purchase_change_account_request, :message => request_hash)
  response = convert_response(result.body[:purchase_change_account_request_response])
  if response[:result_code] == 0
    {
      :used_express_checkout => true,
      :request_result        => response[:purchase_change_account_request_result],
      :error                 => response[:error],
      :order_xml             => response[:order_xml]
    }
  else
    raise RubyEcommError.new(response[:result_code], response[:change_account_request_result])
  end
end