很难从 createCustomer 对象中检索 customer_id getId() 以传递给 createCustomerCard
Having a hard time retrieving the customer_id getId() from createCustomer object to pass to createCustomerCard
这是我的代码,它是我在 here
中使用的示例
$createcustomer_api = new \SquareConnect\Api\CustomersApi();
$createcustomer_result = $createcustomer_api->createCustomer(array(
'given_name' => 'Amelia',
'family_name' => 'Earhart',
'email_address' => 'Amelia.Earhart@example.com',
'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] => Amelia.Earhart@example.com
[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 is called like $customer->getId()
, but according to this,我只需将 ->getId()
添加到我的 [=19] =]对象。
所以我试图将 getId()
函数调用为
$createcustomer_result->getId()
但在我的代码中出现错误
Fatal error: Call to undefined method SquareConnect\Model\CreateCustomerResponse::getId()
如何从 createCustomer
中正确获取客户 ID?
您只从通信设备 API 获得了响应对象。您需要先从响应中提取创建的对象,然后您可以查询它的ID。
$customer = $createcustomer_result->getCustomer();
这应该让您获得实际的客户对象,然后您可以:
$customer_id = $customer->getId();
这对于 API 库来说很常见。如果发生错误,您还可以查询响应对象以查找错误。使用这些类型的库时,深入了解各种 类 并通读函数,您可以更好地了解如何使用它们。
这是我的代码,它是我在 here
中使用的示例$createcustomer_api = new \SquareConnect\Api\CustomersApi();
$createcustomer_result = $createcustomer_api->createCustomer(array(
'given_name' => 'Amelia',
'family_name' => 'Earhart',
'email_address' => 'Amelia.Earhart@example.com',
'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] => Amelia.Earhart@example.com
[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 is called like $customer->getId()
, but according to this,我只需将 ->getId()
添加到我的 [=19] =]对象。
所以我试图将 getId()
函数调用为
$createcustomer_result->getId()
但在我的代码中出现错误
Fatal error: Call to undefined method SquareConnect\Model\CreateCustomerResponse::getId()
如何从 createCustomer
中正确获取客户 ID?
您只从通信设备 API 获得了响应对象。您需要先从响应中提取创建的对象,然后您可以查询它的ID。
$customer = $createcustomer_result->getCustomer();
这应该让您获得实际的客户对象,然后您可以:
$customer_id = $customer->getId();
这对于 API 库来说很常见。如果发生错误,您还可以查询响应对象以查找错误。使用这些类型的库时,深入了解各种 类 并通读函数,您可以更好地了解如何使用它们。