首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP支付网关事务错误

PHP支付网关事务错误
EN

Stack Overflow用户
提问于 2018-08-16 02:39:35
回答 1查看 193关注 0票数 0

我一直得到以下两个错误,我不知道如何修复它们

代码语言:javascript
复制
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'invalid keys: lineItems[ in C:\wamp64\www\pay\braintree\lib\Braintree\Util.php on line 351

代码语言:javascript
复制
InvalidArgumentException: invalid keys: lineItems[ in C:\wamp64\www\pay\braintree\lib\Braintree\Util.php on line 351

这是来自以下代码的第351行throw new InvalidArgumentException('invalid keys: ' . $sortedList);

代码语言:javascript
复制
public static function verifyKeys($signature, $attributes)
{
    $validKeys = self::_flattenArray($signature);
    $userKeys = self::_flattenUserKeys($attributes);
    $invalidKeys = array_diff($userKeys, $validKeys);
    $invalidKeys = self::_removeWildcardKeys($validKeys, $invalidKeys);

    if(!empty($invalidKeys)) {
        asort($invalidKeys);
        $sortedList = join(', ', $invalidKeys);
        throw new InvalidArgumentException('invalid keys: ' . $sortedList);
    }
}

下面是可能导致错误的两个函数中的第一个

代码语言:javascript
复制
function payment_data($gateway, $order_id){
    try{
        $account_number = account_number();
        $total_amount = total_amount();

        $credit_cards = $gateway->customer()->find($account_number);
        $members_first_name = $credit_cards->firstName;
        $members_last_name = $credit_cards->lastName;
        $members_email = $credit_cards->email;

        if(!empty($credit_cards)){
            foreach($credit_cards->creditCards as $c){
                if($c->default === true){
                    $first_name = $c->billingAddress->firstName;
                    $last_name = $c->billingAddress->lastName;
                    $street_address = $c->billingAddress->streetAddress;
                    $extended_address = $c->billingAddress->extendedAddress;
                    $city = $c->billingAddress->locality;
                    $region = $c->billingAddress->region;
                    $postal_code = $c->billingAddress->postalCode;
                    $country_name = $c->billingAddress->countryName;
                    $card_token = $c->token;
                    $customer_id = $c->customerId;

                    if(empty($extended_address)){
                        $extended_address = null;
                    }                   

                    if(empty($region)){
                        $region = null;
                    }

                    $result = $gateway->transaction()->sale([
                      'amount' => $total_amount,
                      'orderId' => $order_id,
                      'customerId' => $customer_id,
                      'customer' => [
                        'firstName' => $members_first_name,
                        'lastName' => $members_last_name,
                        'email' => $members_email
                      ],
                      'billing' => [
                        'firstName' => $first_name,
                        'lastName' => $last_name,
                        'streetAddress' => $street_address ,
                        'extendedAddress' => $extended_address,
                        'countryName' => $country_name,
                        'locality' => $city,
                        'region' => $region,
                        'postalCode' => $postal_code
                      ],
                      'shipping' => [
                        'firstName' => $first_name,
                        'lastName' => $last_name,
                        'streetAddress' => $street_address ,
                        'extendedAddress' => $extended_address,
                        'countryName' => $country_name,
                        'locality' => $city,
                        'region' => $region,
                        'postalCode' => $postal_code
                      ],
                      'lineItems' => [
                        products($order_id)
                      ],
                      'options' => [
                        'submitForSettlement' => true
                      ]
                    ]);
                }
            }           
        }
    } catch (Braintree_Exception_NotFound $e) {
        return false;
    }
}

下面是我的第二个函数

代码语言:javascript
复制
function products($order_id){
    if(products('Now') !== false){
        $total = count(products('Now'));
        $x = 1;
        $line_items = '';

        foreach(products('Now') as $product){
            $title = $product['title'];
            $quantity = $product['quantity'];
            $sales_tax = $product['sales_tax'];
            $regular_price = $product['regular_price'];
            $total_sales_tax = $product['total_sales_tax'];
            $total_amount = $product['total_amount'];
            $savings_price = $product['savings_price'];
            $product_id = $product['product_id'];

            $line_items .= "[";
            $line_items .= "'name' => '" . $title . "',";
            $line_items .= "'description' => 'Product',";
            $line_items .= "'quantity' => '" . $quantity . "',";
            $line_items .= "'unitTaxAmount' => '" . $sales_tax . "',";
            $line_items .= "'unitAmount' => '" . $regular_price . "',";
            $line_items .= "'taxAmount' => '" . $total_sales_tax . "',";
            $line_items .= "'totalAmount' => '" . $total_amount . "',";
            $line_items .= "'discountAmount' => '" . $savings_price . "',";
            $line_items .= "'productCode' => '" . $product_id . "',";
            $line_items .= "'kind' => 'debit',";
            $line_items .= "'url' => 'http://localhost/product.php?id=" . $product_id . "'";

            if($x !== $total){
                $line_items .= "],";
            } else {
                $line_items .= "]";
            }

            $x++;
        }

        return $line_items;
    }       
}
EN

回答 1

Stack Overflow用户

发布于 2018-08-16 03:47:00

我猜你需要更多像这样的东西,我用过Braintree,但我从来没有给它传递过这么大的数据串。

代码语言:javascript
复制
function products($order_id){
    if(products('Now') !== false){

        $total = count(products('Now'));

        $line_items = Array();
        foreach(products('Now') as $product){

            $title = $product['title'];
            $quantity = $product['quantity'];
            $sales_tax = $product['sales_tax'];
            $regular_price = $product['regular_price'];
            $total_sales_tax = $product['total_sales_tax'];
            $total_amount = $product['total_amount'];
            $savings_price = $product['savings_price'];
            $product_id = $product['product_id'];

            $line_item = Array();
            $line_item['name'] = $title;
            $line_item['description'] = 'Product';
            $line_item['quantity'] = $quantity;
            $line_item['unitTaxAmount'] = $sales_tax;
            $line_item['unitAmount'] = $regular_price;
            $line_item['taxAmount'] = $total_sales_tax;
            $line_item['totalAmount'] = $total_amount;
            $line_item['discountAmount'] = $savings_price;
            $line_item['productCode'] = $product_id;
            $line_item['kind'] = 'debit';
            $line_item['url'] = 'http://localhost/product.php?id=' . $product_id;
            $line_items[] = $line_item;
        }

        return $line_items;
    }       
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51864570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档