簡體   English   中英

PHP Payment Gateway交易錯誤

[英]PHP Payment Gateway Transaction Errors

我不斷收到以下2個錯誤,但我不知道如何解決

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

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

這是第351行throw new InvalidArgumentException('invalid keys: ' . $sortedList); 從下面的代碼。

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

這是我的兩個似乎引起錯誤的函數中的第一個

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

這是我的第二個功能

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

我猜想您需要更多類似的東西,我已經使用了Braintree一點,但我從未像這樣傳遞過一大串數據。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM