2017-09-27 71 views
0

這裏是我的代碼,這是我從here有一個很難獲取從createCustomer對象CUSTOMER_ID的getId()傳遞給createCustomerCard

$createcustomer_api = new \SquareConnect\Api\CustomersApi(); 
$createcustomer_result = $createcustomer_api->createCustomer(array(
    'given_name' => 'Amelia', 
    'family_name' => 'Earhart', 
    'email_address' => '[email protected]', 
    'address' => array(
    'address_line_1' => '500 Electric Ave', 
    'address_line_2' => 'Suite 600', 
    'locality' => 'New York', 
    'administrative_district_level_1' => 'NY', 
    'postal_code' => '10003', 
    'country' => 'US' 
), 
    'phone_number' => '1-555-555-0122', 
    'reference_id' => 'YOUR_REFERENCE_ID', 
    'note' => 'a customer' 
)); 

使用的例子。如果我打印出來的結果我得到

SquareConnect\Model\CreateCustomerResponse Object 
(
    [errors:protected] => 
    [customer:protected] => SquareConnect\Model\Customer Object 
     (
      [id:protected] => CBASEHtp6YVU8AirkMv1lrVMyoIgAQ 
      [created_at:protected] => 2017-09-27T23:19:44.62Z 
      [updated_at:protected] => 2017-09-27T23:19:44.62Z 
      [cards:protected] => 
      [given_name:protected] => Amelia 
      [family_name:protected] => Earhart 
      [nickname:protected] => 
      [company_name:protected] => 
      [email_address:protected] => [email protected] 
      [address:protected] => SquareConnect\Model\Address Object 
       (
        [address_line_1:protected] => 500 Electric Ave 
        [address_line_2:protected] => Suite 600 
        [address_line_3:protected] => 
        [locality:protected] => New York 
        [sublocality:protected] => 
        [sublocality_2:protected] => 
        [sublocality_3:protected] => 
        [administrative_district_level_1:protected] => NY 
        [administrative_district_level_2:protected] => 
        [administrative_district_level_3:protected] => 
        [postal_code:protected] => 10003 
        [country:protected] => US 
        [first_name:protected] => 
        [last_name:protected] => 
        [organization:protected] => 
       ) 

      [phone_number:protected] => 1-555-555-0122 
      [reference_id:protected] => YOUR_REFERENCE_ID 
      [note:protected] => a customer 
      [preferences:protected] => SquareConnect\Model\CustomerPreferences Object 
       (
        [email_unsubscribed:protected] => 
       ) 

      [groups:protected] => 
     ) 

) 

現在我需要創建客戶卡,以便與客戶進行未來的定期付款。

$createcard_api = new \SquareConnect\Api\CustomersApi(); 
$createcard_result = $createcard_api->createCustomerCard($createcustomer_result->getId(), array(
    'card_nonce' => $nonce, 
    'billing_address' => array(
    'address_line_1' => '1455 Market St', 
    'address_line_2' => 'Suite 600', 
    'locality' => 'San Francisco', 
    'administrative_district_level_1' => 'CA', 
    'postal_code' => '94103', 
    'country' => 'US' 
), 
    'cardholder_name' => 'Amelia Earhart' 
)); 

據我瞭解有一個與方SDK是getId()它根據this被稱爲像$customer->getId()內置的功能,但根據this我只是需要添加->getId()createCustomer對象。

所以我試圖調用getId()功能

$createcustomer_result->getId() 

,但在我的代碼我收到錯誤

Fatal error: Call to undefined method SquareConnect\Model\CreateCustomerResponse::getId() 

如何正確獲取來自createCustomer客戶ID?

回答

2

您只從API(通訊設備)獲得響應對象。您需要首先從響應中提取創建的對象,然後可以查詢它的ID。

$customer = $createcustomer_result->getCustomer(); 

這應該讓你的客戶實際的對象,那麼你可以:

$customer_id = $customer->getId(); 

這是API庫很常見。如果發生錯誤,您還可以查詢響應對象。當使用這些庫時,看看各個類的內容並閱讀函數,可以更好地瞭解如何以這種方式使用它們。

+0

我愛你!這工作 –

+0

你會碰巧知道如何獲得Customercard ID?我嘗試使用'$ createcard_result-> getCustomerCard();'但沒有奏效。 –

+0

以及您在哪裏找到'getCustomer()'文檔?我無法在任何地方找到。 –

相關問題