2Checkout / 2checkout-php

2Checkout PHP Library
MIT License
83 stars 66 forks source link

Order with "lineItems" do not seem to work #13

Closed umutm closed 10 years ago

umutm commented 10 years ago

We use the 2CO PHP library and can not pass the orders successfully (in the sandbox) using the lineItems object. Without lineItems, things work ok but we need lineItems for using the recurring payments feature.

But get a "Unable to process the request" request with HTTP 400 status. It seems like we send the request as expected but it fails. Are we missing anything?

The complete code is as:

$charge = Twocheckout_Charge::auth(array(
    "merchantOrderId" => "123",
    "token" => $twoCheckoutToken,
    "currency" => 'USD',
    //"total" => '10.00',
    "lineItems" => array(
        "name" => 'TEST PRODUCT',
        "type" => 'product',
        "quantity" => '1',
        "price" => '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!";
}

Once we remove this part:

"lineItems" => array(
    "name" => 'TEST PRODUCT',
    "type" => 'product',
    "quantity" => '1',
    "price" => '10.00'
),

it works (but we need that part).

umutm commented 10 years ago

Just realized that lineItems has to be a multi-dimensional array and things worked that way :).

JAW-Dev commented 9 years ago

Can you supply the code you used I'm having the same problem.

umutm commented 9 years ago

Here it is:

  $lineItemsArray = array("name" => $productName, "type" => 'product', "quantity" => $quantity, "price" => $productPrice);
    try {
        $charge = Twocheckout_Charge::auth(array(
            "merchantOrderId" => $uniqueID,
            "token" => $twoCheckoutToken,
            "currency" => $paymentCurrency,
            "lineItems" => array(
                $lineItemsArray
            ),
            "billingAddr" => array(
                "name" => $userBillingName,
                "addrLine1" => $userBillingAddress,

and so..

Hope it helps.

JAW-Dev commented 9 years ago

Hey thanks. That's what I've been doing, but I can't get it to send or the response just isn't reflecting it.

umutm commented 9 years ago

I can at least tell that 2CO's system (live system.. not sure about the dev. system) is working fine and there shall be something with the code.

I'll suggest sending very realistic data (in the address) with all the fields as I remember "bla bla data, addresses without zip" was causing issues.

premhunt commented 9 years ago

You have to use lineItem under two arrays. Please find below example. You replace lineItem with this. It will work. "lineItems" => array( array( "type" => 'product', "price" => "5.00", "productId" => "123", "name" => "Test Product", "quantity" => "1", "tangible" => "N", "startupFee" => "1.00", "recurrence" => "1 Month", "description" => "This is a test" ) ),

kamleshpal1311 commented 7 years ago

Hi

Can i remove this is it mandatory or not.

"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' )

craigchristenson commented 7 years ago

The billing address is mandatory. More information on the required data can be found in the payment API documentation.

wiloke commented 7 years ago

It should be "lineItems" => array( array( "type" => "product", "name" => "Tet", "price" => "10.00", "tangible" => "Y", "recurrence" => "1 Week", "duration" => "1 Week", "quantity" => 1, "startupFee" => "1.00", "productId" => "123", "description" => "This is a test" ) ) lineItems not lineItem ;)