Not authorized to access orders with location_id while creating a order checkout

Hello Folks,

I am trying to create a payment and transfer the amount to a connected merchant account and I’m stuck with the error as below,

“detail”:“Not authorized to access orders with location_id=MLNFQ7QGFRX4B”}]

I have two different account where one I’m using as inter mediator to transfer amount to merchant account directly from end users

and I’m not able to achieve the requirement do help me out with the same.

Here’s my code,

	$client = new SquareClient([
		'accessToken' => env('SQUARE_ACCESS_TOKEN'),
		'environment' => Environment::SANDBOX,

    $amount_money = new \Square\Models\Money();

	$app_fee_money = new \Square\Models\Money();

	$body = new \Square\Models\CreatePaymentRequest(
	$body->setNote('Brief description here');

	$api_response = $client->getPaymentsApi()->createPayment($body);

Thanks & regards,

:wave: Hi Anil, are you using an OAuth access token generated from OAuth for the account you’re trying to take the payment on behalf of? :slightly_smiling_face:

Hi Bryan,

I tried plenty of ways to resolve my issue nothing worked.

at last, I figured out that I am supposed to use the merchant access_token stored while connecting the account, and the location id is supposed to be the developer’s account used as a mediator in the applications side.

after changes this is how my code looks,

	$client = new SquareClient([
		'accessToken' => $merchant_square_access, //Merchants access token
		'environment' => Environment::SANDBOX,

    $order = new \Square\Models\Order(env('LOCATION_ID')); //Developer's account location id

	$price_money = new \Square\Models\Money();

	$quick_pay = new \Square\Models\QuickPay(
		'Testing Quick Pay',
		env('LOCATION_ID') //Developer's account location id

	$body = new \Square\Models\CreatePaymentLinkRequest();

	$api_response = $client->getCheckoutApi()->createPaymentLink($body);

	if ($api_response->isSuccess()) {	
		$result = $api_response->getResult();
	} else {
		$errors = $api_response->getErrors();

Thanks for response, do check my code and please let me know If I’m following the correct way

Glad to hear you figured it out. All looks good! :slightly_smiling_face:

1 Like