mhernaez avatar image
mhernaez asked Jonathan Ryan Grice commented

How to get Authorization Code programmatically?

We have a native Clover POS app. We use the ACTION_SECURE_PAY, ACTION_MANUAL_PAY, ACTION_MANUAL_REFUND intents. In the event our app does not get the response back from the intent we would like to use the REST API to recall a payment.

According to we need an API Token. To get an API Token, we need an Authorization Code. Is there a way to generate an Authorization Code without anyone having to physically log into a website? We are looking for a way to generate the Authorization Code programmatically using the merchant's credentials.

The reasoning behind this.. the merchant will know their credentials; however, it will be the employees that will be using the app. It doesn't make sense for our native Clover app to redirect to a website (is that even possible on a Clover Flex?) and prompt for credentials that employees will not have access to. We just want the process to be fluent without any redirects or prompting for credentials. Is this possible?

Any help would be greatly appreciated.

REST APIClover FlexOAuthAuth
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Could you explain what you mean by your app not receiving a response after calling the ACTION_SECURE_PAY, ACTION_MANUAL_PAY, ACTION_MANUAL_REFUND intents?

0 Likes 0 ·

Sorry, our app receives the response. What I meant to say is that our app then sends the response to a Windows service which then process the information. In the event of a communication issue and the Windows service does not get the response, is there a way for the Windows service to make a call to get the last transaction? Is there an Android SDK function that will get the last transaction?

0 Likes 0 ·
zgreathouse avatar image
zgreathouse Deactivated answered Jonathan Ryan Grice commented
To get an access token using the SDK use the following code snippet:
CloverAuth.AuthResult authResult = CloverAuth.authenticate(getApplicationContext(), mAccount);
final String authToken = authResult.authToken;
String baseUrl = authResult.authData.getString(CloverAccount.KEY_BASE_URL);
String merchantId = authResult.merchantId;
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Understood.. thanks for the reply! We were trying to use the API to get transactions. Is there a way to query past transactions using the SDK?

0 Likes 0 ·

Can you please point me to a PHP example?

0 Likes 0 ·

Ok, so with the above solution I'm able to get the auth token.

Now I'm on Step 3: Request an API Token of I enter the client id, app id, and auth token in the following:{APP_ID}&client_secret={APP_SECRET}&code={AUTHORIZATION_CODE} but I get the following message: "Invalid OAuth Credentials". I'm using sandbox credentials for the client id, and app id...

Any ideas why I'm getting "Invalid OAuth Credentials"?

0 Likes 0 ·

when your http client calls GET on that uri it should return the API Token. one of your strings may have been passed as the wrong query string.

0 Likes 0 ·
Jonathan Ryan Grice avatar image
Jonathan Ryan Grice answered Jonathan Ryan Grice edited
PHP Example:
$mid = YOUR_MID;
$token = YOUR_API_TOKEN;

// If testing on sandbox use with same endpoint
//$restapi = '';
$restapi = '';

$header = array();
$header[] = sprintf('Authorization: Bearer %s', $token);

$ch = curl_init();
curl_setopt_array($ch, array(
	CURLOPT_URL => sprintf('%s/v3/merchants/%s/orders?limit=10', $restapi, $mid),
$result = curl_exec($ch);

if ($result === false) {
	echo sprintf('%s: %s', "CURL Error", curl_error($ch));
} else {
	header('Content-Type: application/json');
Hope this helps.
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community