阅读installation instructions for Square's SDK我收到以下错误:
致命错误:未捕获错误:调用未定义的函数charge() D:...... \ square \ 1.php 28号线
我添加了丢失的$access_token
但不确定如何继续?如何修复缺少的充电功能错误?
<?php
require 'vendor/autoload.php';
$access_token = 'sandbox-abcdefghijkl_mnopqrstivwxyzzz';
# setup authorization
\SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken($access_token);
# create an instance of the Transaction API class
$transactions_api = new \SquareConnect\Api\TransactionsApi();
$location_id = 'CBASEEum0KeFu_h-4VA4OWaV3F8gAQ';
$nonce = 'CBA15363g28251525625624455255A';
$request_body = array (
"card_nonce" => $nonce,
# Monetary amounts are specified in the smallest unit of the applicable currency.
# This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.
"amount_money" => array (
"amount" => 100,
"currency" => "USD"
),
# Every payment you process with the SDK must have a unique idempotency key.
# If you're unsure whether a particular payment succeeded, you can reattempt
# it with the same idempotency key without worrying about double charging
# the buyer.
"idempotency_key" => uniqid()
);
try {
$result = $transactions_api-charge($location_id, $request_body);
print_r($result);
} catch (\SquareConnect\ApiException $e) {
echo "Exception when calling TransactionApi->charge:";
var_dump($e->getResponseBody());
}
?>
答案 0 :(得分:1)
你是否从某个地方复制并粘贴了这个?
$transactions_api-charge
应该是
$transactions_api->charge