question

anujc avatar image
anujc asked anujc answered

Issue to payment using api on web platform!

I am trying to implement api with php for web, i am using below api to payment.

https://docs.clover.com/build/develop... https://docs.clover.com/faq#how-do-i-...

After follow given instructions i am composing below details to post using Curl, please check this code, please tell me what is mistake i am doing!

https://apisandbox.dev.clover.com/v2/...

Response : string(35) "Error connecting to Payment Gateway"

Thanks Brijmohan

10 |2000

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

1 Answer

anujc avatar image
anujc answered

Developed by Brijmohan karadia : 9829388872

include_once('components/Crypt/RSA.php');

$merchantorderdatamarchantid = 'XHEXXXXXT0'; $accesstoken = 'exxxxx0547-8f62-aaaa-f2fa-8853333301b2'; $orderId='DBSXXXXXVM';

//https://sandbox.dev.clover.com/v2/merchant/YK4N7TXVWGJ2J/pay/key
 $clover_api = new CloverApi(); 

$pay_key_data = $clover_api->GetPayKeyData($merchant_order_data_marchantid,$access_token);
$pay_key_data = json_decode($pay_key_data);
//print_r($pay_key_data); 
//echo "<hr>";

$rsa = new Crypt_RSA();
//1. GET to /v2/merchant/{mId}/pay/key To get the encryption information you’ll need for the pay endpoint.
//2. Encrypt the card information 

$prefix = $pay_key_data->prefix;
$modulus = $pay_key_data->modulus;
$exponent = $pay_key_data->exponent;
//echo "<hr>";


$user_cc_no = '4111111111111111';
$user_cc_mo = '06';
$user_cc_yr = '2017';
$user_cc_cvv = '123';
$user_zip = '23402';

//2.1. Prepend the card number with the prefix from GET /v2/merchant/{mId}/pay/key.
$stingToEnc = $user_cc_no.$prefix; 

//2.2. Generate an RSA public key using the modulus and exponent provided byGET /v2/merchant/{mId}/pay/key.
$modulus = new Math_BigInteger($modulus);
$exponent = new Math_BigInteger($exponent);

$rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
$rsa->setPublicKey();

$mypublickey = $rsa->getPublicKey();
//echo "<hr>";

//2.3. Encrypt the card number and prefix from step 1 with the public key.
$stingToEncPublickey = $stingToEnc.$mypublickey; 
$ciphertext =   $rsa->encrypt($stingToEncPublickey);
//echo "<hr>";

//3. Base64 encode the resulting encrypted data into a string which you will send to Clover in the “cardEncrypted” field.
  $stingBase64Encpted = base64_encode($ciphertext);
//echo "<hr>";

/****************** POST DATA TO PAYMENT API ******************/

  $url = 'https://apisandbox.dev.clover.com/v2/merchant/'.$merchant_order_data_marchantid.'/pay?access_token='.$access_token;   

  $curlPost = 'orderId='.$orderId.
 '&taxAmount=12'.
 '&zip='.$user_zip.
 '&expMonth='.$user_cc_mo.
 '&cvv='.$user_cc_cvv.
 '&amount=231'.
 '&currency=USD'.
 '&last4=1111'. 
 '&expYear='.$user_cc_yr. 
 '&first6=411111'.
 '&cardEncrypted='.$stingBase64Encpted; 
$ch = curl_init();      
curl_setopt($ch, CURLOPT_URL, $url);        
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        
curl_setopt($ch, CURLOPT_POST, 1);      
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json'));
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);    
$data = curl_exec($ch);  


/****************** POST DATA TO PAYMENT API ******************/
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