dstt1818 2018-08-15 18:39
浏览 19

PHP支付网关事务错误

I keep getting get the following 2 errors which I do not know how to fix

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

And

InvalidArgumentException: invalid keys: lineItems[ in C:\wamp64\www\pay\braintree\lib\Braintree\Util.php on line 351

This is line 351 throw new InvalidArgumentException('invalid keys: ' . $sortedList); from the code below.

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

Here is the first of my two functions that seem to cause the errors

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

Here is my second function

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;
    }       
}
  • 写回答

1条回答 默认 最新

  • dongmen5867 2018-08-15 19:47
    关注

    I'm guessing you need something more like this, I've used Braintree a bit and I've never passed it a big string of data like that.

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

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)