question

shamvil avatar image
shamvil asked devender answered

How to integrate Clover payment api from web app in php?

Hi there,

I am new in clover api. I have created an web app in sandbox account. Now I want to integrate it that means integrate payments form my e-commerce website using this clover api.

I am using php and javascript in my e-commerce website. Is there any simple way/steps to integrate it in php or javascript?

I have even searched for all the docs but could not figure out which can help me make payments on a web app.

Please help..!!!

10 |2000

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

Mark Mullan avatar image
Mark Mullan Deactivated answered anujc commented

Hi,

I've created a Python script here that properly uses our Developer Pay API. I'll be translating it into other languages in the future, but hope this guides you in the right direction for now.

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.

anujc avatar image anujc commented ·

Did you translate code in php? This would be very helpful for php community, we frustrated with writing code in different way !

0 Likes 0 ·
devender avatar image
devender answered devender edited
Which class or libraries we need to include for this $rsa = new Crypt_RSA(); . I am trying to charge customer using credit , debit card in php framework cakephp 3+.

I got the prefix , modulus, exponent using below API URL

$url = 'https://sandbox.dev.clover.com/v2/merchant/'.$merchant_Id.'/pay/key';
But i stuck with the Encryption using class $rsa = new Crypt_RSA();. So my question is it compulsory to Encrypt the customer credit card can we send it without Encryption ?


Regards
Devender
10 |2000

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

pyronerd62 avatar image
pyronerd62 answered devender edited
PHP Secure Communications Library
https://github.com/phpseclib/phpseclib
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.

devender avatar image devender commented ·

I used the same library but i am getting the below error. I checked the class inside common it exist there.

Error: Class 'phpseclib\Crypt\Common\AsymmetricKey' not found 

I also use the phpseclib1.0.6 and phpseclib1.0.7 it retrun me the below error :-

Error: Class 'App\Controller\Crypt_RSA' not found

0 Likes 0 ·
devender avatar image devender commented ·

Now finaly i used the phpseclib1.0.6 everything is working but when i come to payment section then i got the below error :-

error: Protocol " https" not supported or disabled in libcurl https://sandbox.dev.clover.com/v2/merchant/xxxxxxxxxxxxx/pay
0 Likes 0 ·
pyronerd62 avatar image
pyronerd62 answered
If you decide to use 2.0 the classes changed a bit. Here's what I'm using
        $rsa = new RSA();


        $prefix = $this->key['prefix'];
        $modulus = $this->key['modulus'];
        $exponent = $this->key['exponent'];


        list($user_cc_mo,$user_cc_yr) = explode('/', $paymentData['exp']);
        $user_cc_no = str_replace('-','',$paymentData['cc']);
        $user_cc_cvv = (integer) $paymentData['cvv'];
        $user_zip = (integer) $profileData->zip;
        $first_6 = substr($user_cc_no, 0, 6);
        $last_4 = substr($user_cc_no, -4);
        // $user_cc_no = 4264281511118886;
        // $user_cc_cvv = 111;
        // $user_zip = 29368;
        // $first_6 = substr($user_cc_no, 0, 6);
        // $last_4 = substr($user_cc_no, -4);




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


        $rsa->loadKey(['n' => $modulus, 'e' => $exponent]);
        $rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);


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


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


    /****************** 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.

pyronerd62 avatar image
pyronerd62 answered
I have a question for you. It regards the OAuth. Can you get this endpoint to work? https://api.clover.com/oauth/authorize?client_id=XXXXXXXXXXXX&redirect_uri=https://XXXXXXXXXXXX.com/clover/authorize
10 |2000

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

devender avatar image
devender answered
Everything working fine now using phpseclib1.0.6 and only i am getting the currency error now :-
What will be valid currency i am using USD in currency parameters.

string(45) "{"message":"Please supply a valid currency."}"
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