question

mhernaez avatar image
mhernaez asked aniclouds 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 https://docs.clover.com/build/oauth-2-0/ 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.
Thanks.

REST APIClover FlexOAuthAuth
2 comments
10 |2000

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

zgreathouse avatar image zgreathouse commented ·

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 ·
mhernaez avatar image mhernaez commented ·

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;
4 comments
10 |2000

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

mhernaez avatar image mhernaez commented ·

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 ·
muralibalijepally avatar image muralibalijepally commented ·

Can you please point me to a PHP example?

0 Likes 0 ·
mhernaez avatar image mhernaez commented ·

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 https://docs.clover.com/build/oauth-2-0/. I enter the client id, app id, and auth token in the following: https://sandbox.dev.clover.com/oauth/token?client_id={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 ·
Jonathan Ryan Grice avatar image Jonathan Ryan Grice mhernaez commented ·

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 aniclouds commented
PHP Example:
<?php
$mid = YOUR_MID;
$token = YOUR_API_TOKEN;


// If testing on sandbox use with same endpoint
//$restapi = 'https://apisandbox.dev.clover.com';
$restapi = 'https://api.clover.com';


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


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


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

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

aniclouds avatar image aniclouds commented ·

Bei primus rewe finden Sie alles, was Sie für Ihren Haushalt benötigen, von Lebensmitteln bis zu nützlichen Haushaltswaren.

0 Likes 0 ·

Welcome to the
Clover Developer Community