我能夠使用github上的示例,使用事務API成功收費。執行收費看起來是這樣的:使用Square Connect ChargeResponse對象工作時遇到的問題
$result = $transaction_api->charge($access_token, $location_id, $request_body);
echo "<pre>";
print_r($result);
echo "</pre>";
下面是輸出:
SquareConnect\Model\ChargeResponse Object
(
[errors:protected] =>
[transaction:protected] => SquareConnect\Model\Transaction Object
(
[id:protected] => REMOVED FROM POST
[location_id:protected] => REMOVED FROM POST
[created_at:protected] => 2016-04-30T23:42:33Z
[tenders:protected] => Array
(
[0] => SquareConnect\Model\Tender Object
(
[id:protected] => REMOVED FROM POST
[location_id:protected] => REMOVED FROM POST
[transaction_id:protected] => 02d1d965-51fd-5023-68f5-0fcd148a263b
[created_at:protected] => 2016-04-30T23:42:33Z
[note:protected] => Online Transaction
[amount_money:protected] => SquareConnect\Model\Money Object
(
[amount:protected] => 6000
[currency:protected] => USD
)
[processing_fee_money:protected] =>
[customer_id:protected] =>
[type:protected] => CARD
[card_details:protected] => SquareConnect\Model\TenderCardDetails Object
(
[status:protected] => CAPTURED
[card:protected] => SquareConnect\Model\Card Object
(
[id:protected] =>
[card_brand:protected] => VISA
[last_4:protected] => 5858
[exp_month:protected] =>
[exp_year:protected] =>
[cardholder_name:protected] =>
[billing_address:protected] =>
)
[entry_method:protected] => KEYED
)
[cash_details:protected] =>
)
)
[refunds:protected] =>
[reference_id:protected] =>
[product:protected] => EXTERNAL_API
)
)
我的問題是,雖然一些地方(如here)表明,我應該得到一個數組從後充電方法,我反而得到ChargeResponse對象。
在這個對象中是一個事務對象,它包含了所有我想在事務完成後向客戶顯示的相關信息,但它是受保護的,所以試圖回顯事務ID,created_at時間或金額這個返回的對象失敗。
我確定我做錯了什麼,但我迷失於如何從ChargeResponse對象捕獲屬性,以便我可以用它做有用的事情。
舉例來說,我已經試過
echo($result->transaction['id']);
,但我得到的是:
致命錯誤:無法訪問受保護的財產
這甚至可能不嘗試一些正確的方法像這樣,所以我完全接受建議。
編輯該問題以包含輸出。 –
第一個建議給出了關於不能訪問受保護屬性的相同錯誤,第二個和第三個建議不解析爲有效的php。 –