I am using Personal Access Token from my Square Dashboard to Create Payments using the Square Connect PHP SDK.
Everything is going fine and now I read somewhere in documentation that Access Tokens expire every 30 days. So that means payments on my website will stop working after 30 days? Because I can not find any API to obtain fresh personal access token. And I don't want to manually plug in access token every 30 days.
$api_config = new \SquareConnect\Configuration();
$api_config->setHost($host_url);
$api_config->setAccessToken($access_token);
$api_client = new \SquareConnect\ApiClient($api_config);
$payments_api = new \SquareConnect\Api\PaymentsApi($api_client);
$request_body = array (
"source_id" =>$data['nonce'],
"amount_money" => array (
"amount" => $amount,
"currency" => $currency
),
"shipping_address" => array (
"address_line_1" => $data['address_1'],
"address_line_2" => $data['address_2'],
"postal_code" => $data['postal_code'],
"country" => $data['country'],
"first_name" => $data['first_name'],
"last_name" => $data['last_name'],
),
"customer_id" => $transaction->user_id,
"buyer_email_address" => $data['email'],
"reference_id" => $transaction->id,
"note" => $note,
"idempotency_key" => uniqid()
);
P.S: Square API documentation is the most shitty documentation ever!!!
Personal Access Tokens never expire. If you use OAuth, then the access tokens do expire every 30 days, and you would use the ObtainToken with a refresh_token
in order to generate a new access token.
Furthermore, feel free to send your feedback about our documentation to Square's Developer Support team so we can make it better.