2015-01-08 76 views
0

这是2co的多个数组我试图获取返回值并通过电子邮件发送给管理员,但我无法访问此数组中的值。为什么我不能访问这个数组元素

<?php 
require_once 'payment-api/Twocheckout.php'; 

Twocheckout::privateKey('4D67BA12-CE09-4F1D-AB20-0133F24E3472'); 
Twocheckout::sellerId('901249656'); 
Twocheckout::sandbox(true); 

try { 
    $charge = Twocheckout_Charge::auth(array(
     "merchantOrderId" => "123", 
     "token" => $_POST['token'], 
     "currency" => 'USD', 
     "total" => '10.00', 
     "billingAddr" => array(
      "name" => 'Testing Tester', 
      "addrLine1" => '123 Test St', 
      "city" => 'Columbus', 
      "state" => 'OH', 
      "zipCode" => '43123', 
      "country" => 'USA', 
      "email" => '[email protected]', 
      "phoneNumber" => '555-555-5555' 
     ) 
    )); 

    if ($charge['response']['responseCode'] == 'APPROVED') { 
     echo "Thanks for your Order!"; 
     echo "<h3>Return Parameters:</h3>"; 
     echo "<pre>"; 
     echo "His name" . $charge['billingAddr']['name']; 
     echo "</pre>"; 
    } 
} catch (Twocheckout_Error $e) { 
    print_r($e->getMessage()); 
} 

这就是我试图访问这个值。

echo "His name" . $charge['billingAddr']['name']; 

我在做什么错在这里。

什么我从print_r($charge);

Array 
(
    [validationErrors] => 
    [exception] => 
    [response] => Array 
     (
      [type] => AuthResponse 
      [currencyCode] => USD 
      [shippingAddr] => Array 
       (
        [addrLine1] => 
        [addrLine2] => 
        [city] => 
        [zipCode] => 
        [phoneNumber] => 
        [phoneExtension] => 
        [email] => 
        [name] => 
        [state] => 
        [country] => 
       ) 

      [merchantOrderId] => 123 
      [orderNumber] => 9093719883561 
      [transactionId] => 9093719883582 
      [billingAddr] => Array 
       (
        [addrLine1] => 123 Test St 
        [addrLine2] => 
        [city] => Columbus 
        [zipCode] => 43123 
        [phoneNumber] => 555-555-5555 
        [phoneExtension] => 
        [email] => [email protected] 
        [name] => Testing Tester 
        [state] => OH 
        [country] => USA 
       ) 

      [lineItems] => Array 
       (
        [0] => Array 
         (
          [duration] => 
          [options] => Array 
           (
           ) 

          [description] => 
          [price] => 10.00 
          [quantity] => 1 
          [recurrence] => 
          [startupFee] => 
          [productId] => 
          [tangible] => N 
          [name] => 123 
          [type] => product 
         ) 

       ) 

      [recurrentInstallmentId] => 
      [responseMsg] => Successfully authorized the provided credit card 
      [responseCode] => APPROVED 
      [total] => 10.00 
      [errors] => 
     ) 

) 
+0

你从这个回声中得到了什么? – goseo

+1

很难说不知道什么'Twocheckout_Charge :: auth'。检查'var_dump($ charge)',你可能会看到这个问题。 – evilive

+0

先看看print_r($ charge); –

回答

2

使用越来越:

$charge['response']['billingAddr']['name']; 

你忘了访问response关键。

相关问题