【问题标题】:2checkout api call for create sale2checkout api调用创建销售
【发布时间】:2016-07-19 05:38:57
【问题描述】:

我正在使用 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调用设置订单项?

【问题讨论】:

    标签: php api 2checkout


    【解决方案1】:

    您的 lineitem 数组缺少“名称”参数,这是一个必需参数。所需参数的完整列表可以在 here 找到。

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

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

    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 数组中。我提供的示例包含无形销售的所有必需参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 2019-06-16
      • 2016-10-14
      • 1970-01-01
      相关资源
      最近更新 更多