Skip to content

Charge_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

###auth

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

####Arguments

Returns

Returns an Array or JSON object.

Example Usage

Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996');
Twocheckout::sellerId('901248204');

try {
    $charge = Twocheckout_Charge::auth(array(
        "sellerId" => "1817037",
        "merchantOrderId" => "123",
        "token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni',
        "currency" => 'USD',
        "total" => '10.00',
        "billingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'testingtester@2co.com',
            "phoneNumber" => '555-555-5555'
        ),
        "shippingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'testingtester@2co.com',
            "phoneNumber" => '555-555-5555'
        )
    ), 'array');
    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
    }
} catch (Twocheckout_Error $e) {
    $e->getMessage();
}

Example Response

Array
(
    [validationErrors] =>
    [exception] =>
    [response] => Array
        (
            [type] => AuthResponse
            [lineItems] => Array
                (
                    [0] => Array
                        (
                            [options] => Array
                                (
                                )

                            [price] => 10.00
                            [quantity] => 1
                            [recurrence] =>
                            [startupFee] =>
                            [productId] =>
                            [tangible] => N
                            [name] => 123
                            [type] => product
                            [description] =>
                            [duration] =>
                        )

                )

            [transactionId] => 205181140830
            [billingAddr] => Array
                (
                    [addrLine1] => 123 Test St
                    [addrLine2] =>
                    [city] => Columbus
                    [zipCode] => 43123
                    [phoneNumber] => 555-555-5555
                    [phoneExtension] =>
                    [email] => testingtester@2co.com
                    [name] => Testing Tester
                    [state] => OH
                    [country] => USA
                )

            [shippingAddr] => Array
                (
                    [addrLine1] => 123 Test St
                    [addrLine2] =>
                    [city] => Columbus
                    [zipCode] => 43123
                    [phoneNumber] =>
                    [phoneExtension] =>
                    [email] =>
                    [name] => Testing Tester
                    [state] => OH
                    [country] => USA
                )

            [merchantOrderId] => 123
            [orderNumber] => 205181140821
            [recurrentInstallmentId] =>
            [responseMsg] => Successfully authorized the provided credit card
            [responseCode] => APPROVED
            [total] => 10.00
            [currencyCode] => USD
            [errors] =>
        )

)

To test using the sandbox, pass an additional 3rd argument with a value of sandbox to the Twocheckout::setApiCredentials method along with your credentials.

Clone this wiki locally