0

I am using 2checkout api for my website product sale. Hence I am calling 2checkout api to create sale where I can call api with total amount with a single product.It's look like flowing:

try {
    $charge = Twocheckout_Charge::auth(array(
        "merchantOrderId" => "123",
        "token"      => $_POST['token'],
        "currency"   => 'USD',
        "total"      => $first_bill['amount'],
        "billingAddr" => array(
            "name" => $_POST['b_name'],
            "addrLine1" => $_POST['b_address'],
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => $_POST['b_country'],
            "email" => $_POST['b_emaill'],
            "phoneNumber" => $_POST['b_phone']
            ),
        "shippingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'enter code hereOH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'example@2co.com',
            "phoneNumber" => '555-555-5555'
            )
        ));
    if ($charge['response']['responseCode'] == 'APPROVED') {

        echo $response;exit;
        // echo "Thanks for your Order!";
        // echo "<h3>Return Parameters:</h3>";
        // echo "<pre>";
        // print_r($charge);
        // echo "</pre>";
    }
    else
    {
        $this->Registrationmodel->delete_account($accounts_id);
        echo $charge['response']['responseCode'];
        exit;
    }
} 
catch (Twocheckout_Error $e) 
{
    echo $e->getMessage();
    exit;
}

}

hence when i try to set line items individual like following:

try {
    $charge = Twocheckout_Charge::auth(array(
        "merchantOrderId" => "123",
        "token"      => $_POST['token'],
        "currency"   => 'USD',
        //"total"      => $first_bill['amount'],
        "billingAddr" => array(
            "name" => $_POST['b_name'],
            "addrLine1" => $_POST['b_address'],
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => $_POST['b_country'],
            "email" => $_POST['b_emaill'],
            "phoneNumber" => $_POST['b_phone']
            ),
        "LineItem" => array(
            "duration" => 'Forever',
            "price" => '10',
            "productId" =>'1235',
            "quantity" => '1',
            "recurrence" => '1 Month',
            "tangible" => 'N',
            "type"=>'product'
            ),
        "shippingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'example@2co.com',
            "phoneNumber" => '555-555-5555'
            )
        ));
    if ($charge['response']['responseCode'] == 'APPROVED') {
        $response = $this->return_information($charge['response']['orderNumber']);
        echo $response;exit;
        // echo "Thanks for your Order!";
        // echo "<h3>Return Parameters:</h3>";
        // echo "<pre>";
        // print_r($charge);
        // echo "</pre>";
    }
    else
    {
        $this->Registrationmodel->delete_account($accounts_id);
        echo $charge['response']['responseCode'];
        exit;
    }
} 
catch (Twocheckout_Error $e) 
{
    $this->Registrationmodel->delete_account($accounts_id);
    echo $e->getMessage();
    exit;
}

}

It is giving me parameter error. Please can anyone help ? how to set line items using api call?

Rasel Ahmed
  • 1
  • 1
  • 6

1 Answers1

0

Your lineitem array is missing the 'name' param, which is a required parameter. A full list of required params can be located here .

Also your shipping array is unnecessary as your product is intangible, therefore you could remove the shipping array.

Here's a working example I use:

try {
    $charge = Twocheckout_Charge::auth(array(
    "sellerId" => "xxxxxxxxx",
    "li_0_merchant_order_id" => "1",
    "type" => "product",
    "token"      => $_POST['token'],
    "currency"   => "USD",
  //  "total" => "1.00",           //Only use when lineitems are not passed in

       "lineItems" => array(
           "0" => array(
                "name" => $_POST['name'],
                "price" => $_POST['price'],
                "quantity" => $_POST['quantity'],
                "startupFee" => $_POST['startupFee'],
                "tangible" => $_POST['tangible']
                )
             ),
        "billingAddr" => array(
            "name" => $_POST['customer'],
            "addrLine1" => $_POST['addrLine1'],
            "city" => $_POST['city'],
            "state" => $_POST['state'],
            "zipCode" => $_POST['zipCode'],
            "country" => $_POST['country'],
            "email" => $_POST['email'],
            "phoneNumber" => ''
            )
           ));

    if ($charge['response']['responseCode'] == 'APPROVED') {

To better fit your app, add the "duration" & "recurrence" keys & their respective values to the lineItem array in the code I provided above. The example I provided contains all required parameters for a non-tangible sale.

wtrmLn
  • 121
  • 1
  • 2