WebSite X5Help Center

 
Franck M.
Franck M.
User

Stripe et autres paiements LA SOLUTION !  fr

Author: Franck M.
Visited 6549, Followers 6, Shared 0  

Bonjour,

Voici un petit tuto qui devrait faire avancer le schmilblick avec les paiements autres que ceux proposés par websitex5 par défaut.

Je fais ce tutoriel en me basant sur Stripe, un moyen de paiement qui se démocratise et qui fonctionne avec php (entre autre), mais aussi avec curl, Ruby, Python, Java, Node, Go, .NET...) et pas du html.

Notre contrainte avec websitex5 est qu'il n'autorise qu'un formulaire en html pour associer le fournisseur de paiement, donc je pense que ce tuto pourra servir à tous ceux qui ont des formulaires en php de leur prestataire de paiements (cas le plus fréquent !).

Allez on commence.

1 – Le serveur

Pour Stripe, si vous avez un serveur perso, il faudra installer Composer qui va installer les bibliothèques Stripe sur votre serveur web, je fais ça sur un serveur ubuntu, je vous laisse adapter en fonction de votre distribution :

Sudo apt-get install composer

Ensuite allez dans le répertoire cart de votre site

Cd monsitewebsitex5/cart

Et tapez la commande :

Sudo composer require stripe/stripe-php

Ceci va installer les bibliothèques stripe à la racine du dossier cart et un dossier vendor qui contient les fichiers php qui vont bien pour traiter notre demande.

2 – Le formulaire

Ensuite, comme beaucoup de processus de paiement, il se fait en 2 phases :

Le formulaire qui permet la saisie des informations, appelé "checkout" chez Stripe

https://stripe.com/docs/checkout

Pour celui-ci, vous aurez besoin d'une clé publique que vous trouverez ici :

https://dashboard.stripe.com/account/apikeys

Le traitement des données du formulaire via un token appelé "charge" chez Stripe

https://stripe.com/docs/charges

Pour notre formulaire, nous allons l'intégrer dans le fameux code personnalisé qui ennuie tout le monde dans websitex5 depuis belle lurette mais qui a au moins le mérite d'exister même si aucun support ne l'accompagne.

Pour le trouver… Paramètres – Avancés – Panier virtuel e-commerce – Gestion – dans liste des types de paiement – stripe ou autres – modifier – onglet type – payer maintenant – code personnalisé – OUF je suis au bon endroit !

On y colle le code suivant :

<form action="charge.php" method="POST">

    <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"

    data-key="pk_test_MaClePubliqueQueStripeMaDonneePlusHaut"

    data-amount=[PRICE,100, ###,@@]

    data-name="LeNomDeMonJoliSite"

    data-description=[ORDER_NO]

    data-image="LaJolieImageQuiSAfficheSurLInterfaceDePaiement.png"

    data-locale="auto"

    data-zip-code="true"

    data-currency="eur">

  </script>

<input type="hidden" name="order_no" value="[ORDER_NO]" />

<input type="hidden" name="price" value="[PRICE]" />

</form>

1ère ligne charge.php c'est le nom de la page php qui sera appelée pour traiter la demande une fois le formulaire rempli.

Ligne 3 – c'est la clé publique

Ligne 4 – C'est le prix – Merci Mark Fletcher pour les # et les @ pour que le prix s'affiche bien.

Ligne 5 – Le nom utilisé sur le formulaire

Ligne 6 – Le numéro de commande

Ligne 7 – L'image à personnaliser du formulaire

Ligne 10 – La devise utilisée eur,usd,hkd, etc…

Ligne 12 et 13 – Ces 2 lignes permettent de récupérer ensuite les données des variables de notre formulaire dans le fichier charge.php, c'est grâce à ça qu'on a la passerelle entre la page html de paiement et la page charge.php de traitement. Merci au support de Stripe pour la combine !

3 – Les fichiers php

Il nous faudra 2 fichiers php à la racine de cart

Vous aurez besoin de clés secrètes que vous trouverez ici :

https://dashboard.stripe.com/account/apikeys

Le fichier config.php :

<?php

require_once('vendor/autoload.php');

$stripe = array(

 "secret_key"      => " sk_test_MaCLeSecreteAMoiToutSeul",

 "publishable_key" => " pk_test_MaClePubliqueQueStripeMaDonneePlusHaut"

);

\Stripe\Stripe::setApiKey($stripe['secret_key']);

?>

Ligne 2 : Appelle à la bibliothèque Stripe pour gérer la transaction…

Ensuite : On enregistre les clés

Pour le second fichier charge.php on passe au point 4

4 – Le traitement des données

Pour celui-ci vous aurez besoin d'une clé secrète que vous trouverez ici :

https://dashboard.stripe.com/account/apikeys

Ensuite pour traiter la requête, les données du formulaire sont transmises à notre page charge.php qui contient

<?php

$price = $_POST['price']*100;

require_once('vendor/autoload.php');

\Stripe\Stripe::setApiKey("sk_test_MaCLeSecreteAMoiToutSeul");

$token = $_POST['stripeToken'];

Try {

$charge = \Stripe\Charge::create(array(

  'amount' => $price,

  'currency' => "eur",

  'description' => $_POST["order_no"],

  'source' => $token

));

print ("<script language = \"JavaScript\">");

print ("location.href = 'https://VotrePagePaiementPASOK.html';");

print ("</script>");

} catch(\Stripe\Error\Card $e) {

  // Since it's a decline, \Stripe\Error\Card will be caught

  $body = $e->getJsonBody();

  $err  = $body['error'];

  print('Status is:' . $e->getHttpStatus() . "\n");

  print('Type is:' . $err['type'] . "\n");

  print('Code is:' . $err['code'] . "\n");

  // param is '' in this case

  print('Param is:' . $err['param'] . "\n");

  print('Message is:' . $err['message'] . "\n");

  print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

} catch (\Stripe\Error\RateLimit $e) {

  // Too many requests made to the API too quickly

print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

} catch (\Stripe\Error\InvalidRequest $e) {

  // Invalid parameters were supplied to Stripe's API

print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

} catch (\Stripe\Error\Authentication $e) {

  // Authentication with Stripe's API failed

  // (maybe you changed API keys recently)

print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

} catch (\Stripe\Error\ApiConnection $e) {

  // Network communication with Stripe failed

print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

} catch (\Stripe\Error\Base $e) {

  // Display a very generic error to the user, and maybe send

  // yourself an email

print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

} catch (Exception $e) {

  // Something else happened, completely unrelated to Stripe

print ("<script language = \"JavaScript\">");

print ("location.href = 'https:// VotrePagePaiementPASOK.html';");

print ("</script>");

}

?>

Ligne 2 – on multiplie le prix par 100… pas de virgule chez Stripe, tout en centimes !

Ligne 3 – on appelle les bibliothèques stripe

Ligne 4 – La clé secrète

Ligne 6 et 16 – try et catch – pour vérifier que le paiement est ok ou non - Vous avez tout compris !

Ligne 13 à 15 – Pour afficher la page paiement ok, c'est du javascript si quelqu'un a une meilleure idée en php, je suis preneur car je ne sais pas faire…

Et voilà, ça devrait fonctionner ! en tout cas ça marche chez moi ;-)

J'espère que cela aidera la plupart d'entre nous car je le relève une fois de plus et je le déplore, l'aide d'Incomédia à ce sujet est inexistante et que WebsiteX5 se prétende un logiciel Professionnel de e-commerce alors que cette fonctionnalité n'est pas présente mais qu'en plus, aucune aide ne nous soit apportée, c'est lamentable de la part d'incomédia.

Surtout que WebsiteX5 est excellent en tout point de vue, alors pourquoi laisser ces lacunes au niveau e-commerce ?

Et que dire du niveau de certain(e)s personnes d'Incomédia qui nous font patauger et nous laissent dans la panade. Je prends mon exemple : j'ai commencé à poser des questions sur les moyens de paiement en novembre 2017 et je dois faire leur boulot ! Ou alors on me propose des solutions que j'ai moi-même indiquées…

Fort heureusement, on peut s'aider entre nous, et au niveau français on peut remercier JiPé qui fait le boulot de tout le monde ici ainsi que quelques bonnes volontés qui trainent sur le forum. Mais ce n'est pas à nous, utilisateurs, de combler les failles d'un logiciel qu'on nous vend tous les ans, et qui tous les ans présente les mêmes failles.

Franck

Posted on the
23 ANSWERS - 2 USEFUL
Franck M.
Franck M.
User
Author

Bonjour,

Comme on ne peut modifier un commentaire...

Les 3 fichiers php créés plus haut doivent être à la racine du dossier cart du site pour que cela fonctionne...

+++

Read more
Posted on the from Franck M.
C. Guillaume
C. Guillaume
User

Bonjour, 

Le code en exemple chez monetico (credit mutuel) ne ressemble pas vraiment au votre. Pensez vous qu'il soit quand même possible de le faire fonctionner ? 

Monético est comme incomédia, pas de support pour les codes personnalisés...

<form method="post" name="MoneticoFormulaire" target="_top" action="https://p.moneticoservices.com/paiement.cgi">
<input type="hidden" name="version" value="3.0">
<input type="hidden" name="TPE" value="1234567">
<input type="hidden" name="date" value="05/12/2006:11:55:23">
<input type="hidden" name="montant" value="100EUR">
<input type="hidden" name="reference" value="ABERTPY00145">
<input type="hidden" name="MAC" value="78bc376c5b192f1c48844794cbdb0050f156b9a2">
<input type="hidden" name="url_retour"
value="http://url.retour.com/ko.cgi?order_ref=votreRF12345">
<input type="hidden" name="url_retour_ok"
value="http://url.retour.com/ok.cgi?order_ref=votreRF12345">
<input type="hidden" name="url_retour_err"
value="http://url.retour.com/err.cgi?order_ref=votreRF12345">
<input type="hidden" name="lgue" value="FR">
<input type="hidden" name="societe" value="monSite1">
<input type="hidden" name="texte-libre" value="ExempleTexteLibre">
<input type="hidden" name="mail" value="***">
<input type="hidden" name="nbrech" value="3">
<input type="hidden" name="dateech1" value="05/12/2006">
<input type="hidden" name="montantech1" value="50EUR">
<input type="hidden" name="dateech2" value="25/01/2007">
<input type="hidden" name="montantech2" value="25EUR">
<input type="hidden" name="dateech3" value="25/02/2007">
<input type="hidden" name="montantech3" value="25EUR">
<input type="submit" name="bouton" value="Paiement CB">
</form>

en faite, toutes mes infos sont ici https://helpcenter.websitex5.com/en/post/187064#26

mais ce code est un exemple fournit dans ce manuel 

https://www.monetico-paiement.fr/fr/installer/telechargements.html

avez vous pu mofier le déroulement de la commande ( commande - paiement - confirmation ) au lieu de ( commande - confirmation - paiement )

Merci 

Read more
Posted on the from C. Guillaume
Franck M.
Franck M.
User
Author

Bonjour Guillaume,

Ce code ne fonctionne pas avec leur kit ? c'est du html donc ca devrait pas poser de problème.

D'après l'image kitcybermut.zip que tu as mis sur l'autre post, il semblerait qu'ils proposent du php dedans donc visiblement, tu devrais pouvoir t'en tirer... reprend les exemples avec les :

<input type="hidden" name="montantech1" value="50EUR">

dans mon exemple pour la récupération des données et ca devrait fonctionner, je te souhaite bon courage tout de même car n'y connaissant pas grand chose en php, j'ai bien galéré mais comme tu vois : c'est possible !

Reste à voir si dans le kit php le formulaire html que tu publie ici ne renvoie pas à la même page :

<form method="post" name="MoneticoFormulaire" target="_top" action="https://p.moneticoservices.com/paiement.cgi">

mais plutot un truc du genre <form method="post" name="MoneticoFormulaire" target="_top" action="https://lapagephpquivabien.php">

Pour l'ordre commande - confirmation - paiement là on ne peut pas maitriser je pense la procédure, et il faut que ça arrive jusqu'aux neurones d'Incomédia !

Bon courage !

Franck

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Hi Franck M.,

I've followed your step by step instruction. But I received this error after I click Pay With Card button:

Parse error: syntax error, unexpected '$' in /home/cuticuti/ozytours.com/my/cart/charge.php on line 3

What does this mean? Really need your help and assistance.

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

Hi Mior,

Could you please paste here the code of the personnalized code you put in the websitex5 windows and the code of your php pages please, take care to mask your confidential information before ;-)

Or if you prefer go on my website and send me a mail with these infos.

Regards

Franck

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Dear Franck...

1. My custom code is:

<form action="charge.php" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_qGNorz0G0OlRdB0w9UM1hlcO"
data-amount=[PRICE, 100, ###.@@]
data-name="OZY TOURS"
data-description=[ORDER_NO]
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-zip-code="true"
data-currency="aud">
</script>
<input type = "hidden" name = "order_no" value = "[ORDER_NO]" />
<input type = "hidden" name = "price" value = "[PRICE]" />
</form>

2. My config.php file:

<? Php
require_once ( 'vendor / autoload.php');
$ stripe = array (
 "secret_key" => "sk_test_oSxBbheeNcwMvsYjnrMmx1ib",
 "publishable_key" => "pk_test_qGNorz0G0OlRdB0w9UM1hlcO"
);
\ Stripe \ Stripe :: setApiKey ($ stripe [ 'secret_key']);
?>


3. My charge.php file:

<? Php
$ price = $ _POST ['price'] * 100;
require_once ( 'vendor / autoload.php');
\ Stripe \ Stripe :: setApiKey ( "sk_test_oSxBbheeNcwMvsYjnrMmx1ib");
$ token = $ _POST ['stripeToken'];
Try {
$ load = \ Stripe \ Load :: create (array (
  'amount' => $ price,
  'currency' => "eur",
  'description' => $ _POST ["order_no"],
  'source' => $ token
));
print ("<script language = \" JavaScript \ ">");
print ("location.href = ' https: //YourPagePaymentPASOK.html';" );  <--- What url should I put here?
print ("</ script>");
} catch (\ Stripe \ Error \ Card $ e) {

  // Since it's a decline, \ Stripe \ Error \ Card will be caught
  $ body = $ e-> getJsonBody ();
  $ err = $ body ['error'];
  print ('Status is:'. $ e-> getHttpStatus (). "\ n");
  print ('Type is:'. $ err ['type']. "\ n");
  print ('Code is:'. $ err ['code']. "\ n");

  // param is '' in this case
  print ('Param is:'. $ err ['param']. "\ n");
  print ('Message is:'. $ err ['message']. "\ n");
  print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
} catch (\ Stripe \ Error \ RateLimit $ e) {

  // Too many requests made to the API too quickly
print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
} catch (\ Stripe \ Error \ InvalidRequest $ e) {

  // Invalid parameters were supplied to Stripe's API
print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
} catch (\ Stripe \ Error \ Authentication $ e) {

  // Authentication with Stripe API failed
  // (maybe you changed API keys recently)
print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
} catch (\ Stripe \ Error \ ApiConnection $ e) {

  // Network communication with Stripe failed
print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
} catch (\ Stripe \ Error \ Base $ e) {

  // Display a very generic error to the user, and maybe send
  // yourself an email
print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
} catch (Exception $ e) {

  // Something else happened, completely unrelated to Stripe
print ("<script language = \" JavaScript \ ">");
print ("location.href = 'https: // YourPayPayPage.html';");   <--- What url should I put here?
print ("</ script>");
}
?>

My website is www.ozytours.com. You can test the stripe payment here:

www.ozytours.com/deposit-payment.html


Thank you in advance for your assistance.

Regards,

Mior Ahmad

Note - My cart folder image in the attachment (all files that I've in the Cart folder)

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

Bonsoir Ahmad, oops pardon pour ton prénom plus haut ! embarassed

Tout d'abord enlève l'espace entre $ et le nom de ta variable dans tes codes php :

C'est $price et pas $ price

pareil pour token, bref regarde précisément dans le tuto plus haut.

De plus il te manque le dossier vendor dans ton dossier cart, pour ça :

reprends le tuto ici point 1 :

je crois que tu as raté le

Cd monsitewebsitex5/cart

pour installer les bibliothèques de stripe au bon endroit avec le :

Sudo composer require stripe/stripe-php

avec ça tu auras le fameux dossier vendor au bon endroit !

Essaie tout ça et reviens au cas ou tu aies encore un problème.

@+

Franck

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Dear Franck,

Thanks for the reply. I'm using the shared hosting at A2Hosting. Do you have any idea how to install stripe libraries for shared hosting because there is no SSH access.

Regarding the code, it should be $price & $token instead of $ price & $ token right? What about $ load? Is it correct or it should be $load? Sorry I'm not good in coding. embarassed

What about the url that I've highlighted in the charge.php file. Where do all the urls point to? Or I need to create files that are related to successful transaction or failed transaction to point the url?

Once again thank you for your help and advice. I really appreciate it.

Best Regards,

Mior Ahmad 

Read more
Posted on the from Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Dear Franck,

Sorry I make mistake on the coding because translating what you have written in Spanish to English. That's why the coding is wrong. 

Only a bit confuse on the url that I've highlighted in the charge.php file. Where do all the urls point to? Or do I need to create files that are related to successful transaction or failed transaction to point the url?

Once again thank you for your help and advice. I really appreciate it.

Best Regards,

Mior Ahmad 

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

Hi,

You have ssh access so it would be ok to work

So connect to your hosted computer by ssh and try the point 1 of the tuto.

In php you can't use the name load because it's a function in php so give your variable another name you want.

But don't have space between $ and nameofyourvariable so you have to write $nameofyourvariable.

For the successful transaction or failed transaction, you just have to create 2 pages in website and redirect user on these pages according the success or not of the transaction, like this for example :

https://luxinbag.com/payment-ok.html

Hope it will help, if you have other question don't hesitate !

Franck

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Thanks Franck M. for your fast reply. I've asked help from the A2Hosting support because I received this error after trying to sudo:

*** [~]# sudo apt-get install composer
sudo: unable to mkdir /var/db/sudo/cuticuti: Read-only file system

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for cuticuti:
cuticuti is not in the sudoers file. This incident will be reported.

I've corrected all the mistakes according to your advice. Only waiting the stripe library to be installed in the root of cart directory. Hope it will resolve soon by the A2Hosting support.

Thanks again for your help. I'll let you know on the result.

Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

Hi Ahmad,

wait&see ;-)

Regards.

Franck

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Hi Franck,

I've been able to install composer and stripe library by myself. After testing I got this result in Stripe dashboard:

400 ERR   POST /v1/charges                                                       2018/02/11 22:36:16
200 OK     POST /v1/tokens                                                        2018/02/11 22:36:16

For 400 ERR, below are the messages:

Summary

ID               req_OnITvPix6GTrAx
Time           2018/03/11 22:36:16
Method        POSTURL/v1/charges
Status         400
IP address   162.212.133.2
Version       2018-02-28 (latest)
Source        Stripe/v1 PhpBindings/5.9.2

Request query parameters

No query parameters

Request POST body

{
   "amount": "20898.9",
   "currency": "aud",
   "description": "180311-EL94",
   "source": "tok_1C4STJCjG0hVD3KSNYSgr1R6"
}

Response body

{
   "error": {
      "type": "invalid_request_error",
      "message": "Invalid integer: 20898.9",
      "param": "amount"
   }
}

For 200 OK, below are the messages:

Summary

ID                req_VGUo3WPoSxcahi
Time            2018/03/11 22:36:12
Method         POSTURL/v1/tokens
Status          200
IP address    52.42.160.117
Version         2015-01-11
Application    Stripe Checkout
Source          Stripe/v1 GoBindings/4.4.0

Request query parameters

No query parameters

Request POST body

{
   "customer": "cus_CSJXhcyHy8LF7H",
   "email": "***",
   "ip": "175.138.9.58",
   "payment_user_agent": "Stripe Checkout v3 checkout-manhattan(checkout-api)",
   "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36"
}

Response body

{
   "id": "tok_1C4STJCjG0hVD3KSNYSgr1R6",
   "object": "token",
   "card": {
      "id": "card_1C4STICjG0hVD3KSGyQFXg4z",
      "object": "card",
      "address_city": null,
      "address_country": null,
      "address_line1": null,
      "address_line1_check": null,
      "address_line2": null,
      "address_state": null,
      "address_zip": null,
      "address_zip_check": null,
      "brand": "Visa",
      "country": "US",
      "cvc_check": "pass",
      "dynamic_last4": null,
      "exp_month": 2,
      "exp_year": 2021,
      "funding": "credit",
      "last4": "4242",
      "metadata": {
      },
      "name": "***",
      "tokenization_method": null
   },
   "client_ip": "175.138.9.58",
   "created": 1520768173,
   "email": "***",
   "livemode": false,
   "type": "card",
   "used": false
}


The transaction turned out to be failed. Need help and expert advice from you to check based on this log, why this transaction failed. My charge.php is as below:

<?php

$price = $_POST['price']*100;

require_once('vendor/autoload.php');

\Stripe\Stripe::setApiKey("sk_test_oSxBbheeNcwMvsYjnrMmx1ib");

$token = $_POST['stripeToken'];

Try {

$charge = \Stripe\Charge::create(array(

'amount' => $price,

'currency' => "aud",

'description' => $_POST["order_no"],

'source' => $token

));

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-successful.html';");

print ("</script>");

} catch(\Stripe\Error\Card $e) {

// Since it's a decline, \Stripe\Error\Card will be caught

$body = $e->getJsonBody();

$err = $body['error'];

print('Status is:' . $e->getHttpStatus() . "\n");

print('Type is:' . $err['type'] . "\n");

print('Code is:' . $err['code'] . "\n");

// param is '' in this case

print('Param is:' . $err['param'] . "\n");

print('Message is:' . $err['message'] . "\n");

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

} catch (\Stripe\Error\RateLimit $e) {

// Too many requests made to the API too quickly

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

} catch (\Stripe\Error\InvalidRequest $e) {

// Invalid parameters were supplied to Stripe's API

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

} catch (\Stripe\Error\Authentication $e) {

// Authentication with Stripe's API failed

// (maybe you changed API keys recently)

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

} catch (\Stripe\Error\ApiConnection $e) {

// Network communication with Stripe failed

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

} catch (\Stripe\Error\Base $e) {

// Display a very generic error to the user, and maybe send

// yourself an email

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

} catch (Exception $e) {

// Something else happened, completely unrelated to Stripe

print ("<script language = \"JavaScript\">");

print ("location.href = 'http://ozytours.com/transaction-failed.html';");

print ("</script>");

}

?>


My custom code:

<form action="charge.php" method="POST">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_qGNorz0G0OlRdB0w9UM1hlcO"
data-amount=[PRICE,100, ###,@@]
data-name="OZY TOURS"
data-description=[ORDER_NO]
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-zip-code="true"
data-currency="aud">
</script>
<input type="hidden" name="order_no" value="[ORDER_NO]" />
<input type="hidden" name="price" value="[PRICE]" />
</form>


Need your expert advice about this error.

Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Dear Franck

I've corrected the invalid integer error and now my transaction has been successful. I've round out the charge figure without any decimal. The transaction pass through successfully.

Thanks again for your expert advice.

Best Regards,

Mior Ahmad 

Read more
Posted on the from Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Dear Franck,

Sorry to disturb you again. By the way if we would like to avoid invalid integer error so that Stripe could accept decimal, what should we change in the custom code (or other file) either to make it accept decimal or make it round up the figure.

Please advice.

Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

Hi Ahmad,

En effet,c'était bien le problème de faire passer une valeur entière donc il faut passer la valeur en centimes par exemple si tu veux faire payer 3698.36 $, il faut passer à stripe 369836 comme valeur.

$price = $_POST['price']*100;

Ça fait drôle au début, mais c'est la solution !

Bon courage et bravo pour ta tenacité et la réussite de l'intégration !

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Dear Franck,

Firstly thanks again for the expert advice. We have a very nice brainstorming session in this Stripe topic for us and for others who intend to use Stripe as online payment gateway.

Issue of Invalid Integer

The invalid integer always happened when we add certain percentage of charges in the price. Example if the package price is AUD225 and we add 2.95% (Actual conversion is AUD6.6375. In invoice AUD6.64 - round into 2 decimal) as Stripe service fee, there where invalid integer comes. Now the total price in the invoice will become AUD231.64 (actual should be AUD231.6375). But when we pay by card, the price indicate AUD231.63 in Stripe not according to invoice AUD231.64 (please refer to the attachment images). When we do payment it failed with 400 error as below:

Request POST body

{
    "amount": "23163.8",

    "currency": "aud",

    "description": "180312-JH22",

    "source": "tok_1C4rhlCjG0hVD3KSsvAX3QEt"
}

Response body

{
    "error": {

       "type": "invalid_request_error",

       "message": "Invalid integer: 23163.8",

       "param": "amount"

    }
}

You can see that Stripe does not round the price into 2 decimal. The price 23163.8 makes the invalid integer whereby it should be 23164.

Question - How do we make Stripe to round up the decimal into 2 decimal places? What code we should put in either our custom code or charge.php or config.php to make Stripe round up the total price figure?


Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

Hi Ahmad,

Perhaps try in charge.php to replace the

$price = $_POST['price']*100;

by

$price = round($_POST['price']*100, 0, PHP_ROUND_HALF_UP);

Let me know because I can't test for the moment...

See u

Franck

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User

Hi Franck,

I've chat with Stripe support. She said our website custom code does not round the total price figure into 2 decimal before sending to Stripe. I've asked her if she has any idea about coding on how to make this rounding happen before sending to Stripe and she said no. Do you have any idea on how to do this Franck?

Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User
Franck M.
Hi Ahmad, Perhaps try in charge.php to replace the $price = $_POST['price']*100; by $price = round($_POST['price']*100, 0, PHP_ROUND_HALF_UP); Let me know because I can't test for the moment... See u Franck

Yes yes yes.... transaction successful. Thanks again Franck. You are really an expert. Thumbs up to you.

Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

I'm happy for you ! but one more time, I'm angry to have to do the work of incomedia.

Read more
Posted on the from Franck M.
Mior Ahmad Ridzuan A.
Mior Ahmad Ridzuan A.
User
Franck M.
I'm happy for you ! but one more time, I'm angry to have to do the work of incomedia.

Yeah.. Incomedia should pay you some token because you've resolved this Stripe integration issue with WebsiteX5. Hope Incomedia will read this.

Once again.... thanks for all your help and assistance to make Stripe integration happened Franck (actually Incomedia should say this to you). For others who have come across this post and want to integrate Stripe as your payment gateway, kindly give credit to Franck M. for making Stripe integration with WebsiteX5 happened.

Thumbs up to you Franck. I really appreciate it. May God bless you.

Best Regards,

Mior Ahmad

Read more
Posted on the from Mior Ahmad Ridzuan A.
Franck M.
Franck M.
User
Author

I am affected by your thanks and appreciation and very glad it works.

Franck

Read more
Posted on the from Franck M.