question

wengyuli avatar image
wengyuli asked wengyuli commented

Error connecting to Payment Gateway

when use API of https://docs.clover.com/build/developer-pay-api/ ,
the pay API gives:
Error connecting to Payment Gateway

I noticed it needs oauth, I got access_token by oauth, how to use it ? thanks.
Payments
10 |2000

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

Raymond Lee avatar image
Raymond Lee Deactivated answered wengyuli commented
Regarding the pem parameter not being returned, after looking into it, it looks like the reason you are not receiving it is due to you missing the "Process Credit Cards" permission. See here.

It looks like the API token you are using is a merchant generated API token. We do not allow the use of merchant generated API token when using our Developer Pay API. This is why there is no PROCESS_CARD permission option when you generate a merchant API Token.

To retrieve an API token that has PROCESS_CARD permission:
You will first need to go to your Clover app's settings -> Required Permissions -> Set Process Credit Cards. Any merchants that already have your app installed before you set this permission need to uninstall/reinstall your Clover app in order to apply the new permissions.
Then generate an API token using our OAuth process if you are doing a Web app.

If you are doing an Android app instead, you can retrieve an API token using the following code snippet:
CloverAuth.AuthResult authResult = CloverAuth.authenticate(getApplicationContext(), mAccount);
final String authToken = authResult.authToken;

Thanks for bringing this to our attention, I will file a ticket to make it more clear when you are missing PROCESS_CARD permission, instead of still giving the prefix/modulus/exponent.
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.

wengyuli avatar image wengyuli commented ·

thanks Raymond, I will try to setup the permission and use the oauth access token today.

0 Likes 0 ·
Raymond Lee avatar image
Raymond Lee Deactivated answered wengyuli commented
Errors that relate to connecting to the Payment Gateway are probably due to either network issues, or problems occurring with the payment gateway.

It is recommend to just retry if you get an "Error connecting to Payment Gateway" error.

Regarding the access_token, you need to add it to the header of your request like so:

Authorization: Bearer <access_token>

So the full request should look like:

GET /v2/merchant/<merchant_id>/pay/key HTTP/1.1
Host: apisandbox.dev.clover.com
Authorization: Bearer <access_token>
Content-Type: application/json
Cache-Control: no-cache
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.

wengyuli avatar image wengyuli commented ·

thanks for your answer.

I am using node js to request the web pay api, in github sample, node js can use the pem parameter, but I can't get the pem parameter from the { {url}}/v2/merchant/{ {mId}}/pay/key api, just got modulus, exponent and prefix these 3 parameter, so I use below code to generate the encrypted card number, it seems the cardEncrypted is wrong, then api return me : "Error connecting to Payment Gateway" , can you please help with this? thanks in advance.

var RsaNode = require('rsa-node');

var rsa = new RsaNode(modulus, exponent);

var encrypted = rsa.encrypt(prefix + cardNumber);

var cardEncrypted = new Buffer(encrypted).toString('base64');

0 Likes 0 ·
wengyuli avatar image wengyuli wengyuli commented ·

another try is below, still with error: error:0306E06C:bignum routines:BN_mod_inverse:no inverse

var getPem = require('rsa-pem-from-mod-exp');

var pem = getPem(modulus, exponent);

const crypto = require('crypto');

var encrypted = crypto.publicEncrypt(pem, Buffer(prefix + cardNumber));

0 Likes 0 ·

Welcome to the
Clover Developer Community