Skip to content

Checkout_Authorize

Jacob McConnell edited this page Jun 10, 2014 · 1 revision

This method provides a binding to the authorization call available through our Payment API.

##Method

###authorize

Use to charge a buyer and create a new 2Checkout sale using a secure token provided by 2co.js.

####Arguments

####Returns

Returns a Checkout object.

####Example Usage:

Twocheckout::API.credentials = {
    :seller_id => '1817037',
    :private_key => '8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3'
}

params = {
    :merchantOrderId     => '123',
    :token          => 'ZmYyMzMyZGMtZTY2NS00NDAxLTlhYTQtMTgwZWIyZTgwMzQx',
    :currency       => 'USD',
    :total          => '1.00',
    :billingAddr    => {
        :name => 'Testing Tester',
        :addrLine1 => '123 Test St',
        :city => 'Columbus',
        :state => 'OH',
        :zipCode => '43123',
        :country => 'USA',
        :email => '[email protected]',
        :phoneNumber => '555-555-5555'
    }
}

begin
  result = Twocheckout::Checkout.authorize(params)
rescue Twocheckout::TwocheckoutError => e
  puts e.message
end

####Example Response:

#{
"type"=>"AuthResponse",
 "lineItems"=>
  [{"options"=>[],
    "price"=>"1.00",
    "quantity"=>"1",
    "recurrence"=>nil,
    "startupFee"=>nil,
    "productId"=>"",
    "tangible"=>"N",
    "name"=>"123",
    "type"=>"product",
    "description"=>"",
    "duration"=>nil}],
 "transactionId"=>"205180760223",
 "billingAddr"=>
  {"addrLine1"=>"123 Test St",
   "addrLine2"=>nil,
   "city"=>"Columbus",
   "zipCode"=>"43123",
   "phoneNumber"=>"555-555-5555",
   "phoneExtension"=>nil,
   "email"=>"[email protected]",
   "name"=>"Testing Tester",
   "state"=>"OH",
   "country"=>"USA"},
 "shippingAddr"=>
  {"addrLine1"=>nil,
   "addrLine2"=>nil,
   "city"=>nil,
   "zipCode"=>nil,
   "phoneNumber"=>nil,
   "phoneExtension"=>nil,
   "email"=>nil,
   "name"=>nil,
   "state"=>nil,
   "country"=>nil},
 "merchantOrderId"=>"123",
 "orderNumber"=>"205180760214",
 "recurrentInstallmentId"=>nil,
 "responseMsg"=>"Successfully authorized the provided credit card",
 "responseCode"=>"APPROVED",
 "total"=>"1.00",
 "currencyCode"=>"USD",
 "errors"=>nil}

To test using the sandbox, pass and additional sandbox option with a value of 1 to the Twocheckout::API.credentials method along with your credentials.

Clone this wiki locally