0

我正在使用 2checkout api 进行网站产品销售。因此,我调用 2checkout api 来创建销售,我可以在其中调用 api 与单个产品的总金额。它看起来像流动:

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;
}

}

因此,当我尝试单独设置行项目时,如下所示:

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;
}

}

它给了我参数错误。请问有人可以帮忙吗?如何使用 api 调用设置订单项?

4

1 回答 1

0

您的 lineitem 数组缺少 'name' 参数,这是一个必需参数。可在此处找到所需参数的完整列表。

此外,您的运输阵列是不必要的,因为您的产品是无形的,因此您可以删除运输阵列。

这是我使用的一个工作示例:

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

为了更好地适应您的应用程序,请将“duration”和“recurrence”键及其各自的值添加到我上面提供的代码中的 lineItem 数组中。我提供的示例包含无形销售的所有必需参数。

于 2016-07-19T20:00:45.350 回答