github の例に従って、トランザクション API を使用して正常に課金できました。請求の実行は次のようになります。
$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
)
)
私の問題は、一部の場所 (ここなど) では、charge メソッドから配列を取得する必要があることを示していますが、代わりに ChargeResponse オブジェクトを取得することです。
このオブジェクト内には、トランザクションが完了したら顧客に表示したいすべての関連情報を含むトランザクション オブジェクトがありますが、保護されているため、この返されたオブジェクトからトランザクション ID、created_at time、または金額をエコーしようとすると失敗します.
私は何か間違ったことをしていると確信していますが、ChargeResponse オブジェクトからプロパティを取得して、それを使って便利なことを行う方法についてはわかりません。
たとえば、私は試しました
echo($result->transaction['id']);
しかし、私が得るのは次のとおりです。
致命的なエラー: 保護されたプロパティにアクセスできません
これは、このようなことを試みる正しい方法でさえないかもしれないので、私は提案を完全に受け入れています.