Étiquettes
ASP.NET MVC Paybox Intégration
PAYBOX is a payment solution as PAYPAL and others, providing services Present and Payment, E-Commerce, Call Centers ….
In this article we propose to integrate the PAYBOX e-commerce payment solution.
For information on PAYBOX, thank you for visit (http://www.paybox.com/)
We are using Visual studio C# and ASP.NET MVC4 (for more information about ASP.NET MVC please take a look at  http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4
Lets Go :
1. Open Visual studio 2010 or later and Create your Project
2. Â Choose ASP.NET MVC4 Template Projet, Internet Application and Razor ViewEngine
3. Expand Model folder and Create a new Model named PayBoxModel to hold PayBox payment parameters
public class PayBoxModel
{
public PayBoxModel()
{
}
public string PBX_SITE { get; set; }
public string PBX_RANG { get; set; }
public string PBX_IDENTIFIANT { get; set; }
public string PBX_TOTAL { get; set; }
public string PBX_DEVISE { get; set; }
public string PBX_CMD { get; set; }
public string PBX_PORTEUR { get; set; }
public string PBX_RETOUR { get; set; }
public string PBX_HASH { get; set; }
public string PBX_TIME { get; set; }
public string PBX_TYPEPAIEMENT { get; set; }
public string PBX_TYPECARTE { get; set; }
public string PBX_EFFECTUE { get; set; }
public string PBX_REFUSE { get; set; }
public string PBX_ANNULE { get; set; }
public string PBX_ERREUR { get; set; }
public string PBX_HMAC { get; set; }
}
4. Now Create a Partial View (PostToPayBox.csHtml) Â to use our Model. Â Do not forget that all fields must be of type hidden
@model Logcorner.SoftwareStore.Payment.Models.PayBoxModel
<form id= »frm » action=@ViewBag.actionURL>
@Html.HiddenFor(model => model.PBX_SITE)
@Html.HiddenFor(model => model.PBX_RANG)
@Html.HiddenFor(model => model.PBX_IDENTIFIANT)
@Html.HiddenFor(model => model.PBX_TOTAL)
@Html.HiddenFor(model => model.PBX_DEVISE)
@Html.HiddenFor(model => model.PBX_CMD)
@Html.HiddenFor(model => model.PBX_PORTEUR)
@Html.HiddenFor(model => model.PBX_RETOUR)
@Html.HiddenFor(model => model.PBX_HASH)
@Html.HiddenFor(model => model.PBX_TIME)
@Html.HiddenFor(model => model.PBX_TYPEPAIEMENT)
@Html.HiddenFor(model => model.PBX_TYPECARTE)
@Html.HiddenFor(model => model.PBX_HMAC)
</form>
<p style= »text-align: center »>
<h4>
Redirecting to PayBox…</h4>
</p>
5. Now Expand our Controller folder , open HomeController class and add a action Result PostToPayBox.
6. Note its important to secure our action post. So only user who have credentials are allowed to pay articles ( For more information about securing your asp.NET MVC internet application please have a look at our tutorial How to configure Custom Membership and Role Provider using ASP.NET MVC4
7. Now will implement our function GenerateHMAC
8. Next finish our partialView by adding a jquery code to auto submit our form. The necessary scripts are  Jquery-{version}.js and    Jquery-{version}.min.js. Here we are used  @Scripts.Render(« ~/bundles/jquery »)  to include all Jquery scripts.  A more better practice will be to export all javascript functions to external file but the submit function must be called just after displaying hidden field of our  form
9. The next step is to create our checkOut form that dispays product name , Quanty, price and Total :
So expand View folder , expand Home folder and open index.csHtml file. Replace its contents by the following
10. we are at the end. Our final step is to update the web.config file with the appropriate settngs
11. Now , lets go testing our solution :
12. Run the  application (or Press F5 )
13. Confirm payment by clicking on button Pay With Paybox, then you will be redirected to the payment  page
14. So enter  the card test parameter :
Paybox test Credit Card Number :Â 1111 2222 3333 4444
Validity : 06/14
CVV : 123
Note this parameters are for test . So if does not work. Contact paybox So as to have updated parameters.
In a real worl application , you must contact paybox (and your bank) to subscribe the appropriated options according to your business.
Hope this post are helped you.
Note : for Paypal Integration please visit our tutorial for PayPal
Â
Pingback: ASP.NET MVC PayPal Integration | Gora LEYE
quangngoc88 a dit:
Bonjour,
J’ai fait comme le votre, mais j’ai obtenu le message: « Erreur de protection. Nous regrettons de ne pouvoir donner une suite favorable à votre demande de paiement. »
Que-pensez vous la raison de ce problème?
Je vous remercie par avant.
quangngoc88 a dit:
J’ai résolu mon problème. Merci
goraleye a dit:
Bonne continuation.
merci
bouarmod a dit:
Rebonjour, pouvez vous me venir en aide j’ai le même problème que @quangngoc88. si vous pouvez me dire ce qui était à l’origine de votre problème Erreur de Protection. merci d’avance pour le temps que vous allez consacrer à me repondre !!!!
Arnaud a dit:
Quelle était la solution?
quangngoc88 a dit:
C’est comme goraleye dit:
Pour le test, juste faire attention PBX_RANG = « 32 », PBX_SITE = « 1999888 » et PBX_IDENTIFIANT c’est dans le document fourni (et pas comme dans le site)
Pour vérifier la signature de PayBox en .NET, je vous conseille d’utiliser bouncycastle https://www.bouncycastle.org/
Code exemple:
—-
string clear_message =
String.Format(« PBX_SITE={0} » +
« &PBX_RANG={1} » +
« &PBX_IDENTIFIANT={2} » +
« &PBX_TOTAL={3} » +
« &PBX_DEVISE={4} » +
« &PBX_CMD={5} » +
« &PBX_PORTEUR={6} » +
« &PBX_RETOUR={7} » +
« &PBX_REPONDRE_A={8} » +
« &PBX_EFFECTUE={9} » +
« &PBX_ANNULE={10} » +
« &PBX_REFUSE={11} » +
« &PBX_ATTENTE={12} » +
« &PBX_HASH={13} » +
« &PBX_TIME={14} »,
pay_box.PBX_SITE, pay_box.PBX_RANG, pay_box.PBX_IDENTIFIANT, pay_box.PBX_TOTAL,
pay_box.PBX_DEVISE, pay_box.PBX_CMD, pay_box.PBX_PORTEUR, pay_box.PBX_RETOUR, pay_box.PBX_REPONDRE_A,
pay_box.PBX_EFFECTUE, pay_box.PBX_ANNULE, pay_box.PBX_REFUSE, pay_box.PBX_ATTENTE,
pay_box.PBX_HASH, pay_box.PBX_TIME);
const string secretKey =
« 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF »;
pay_box.PBX_HMAC = GenerateHMAC(clear_message, secretKey);
return View(pay_box);
private string GenerateHMAC(string clear_message, string secret_key)
{
var encoder = new ASCIIEncoding();
byte[] message_bytes = encoder.GetBytes(clear_message);
var secret_key_bytes = new byte[secret_key.Length/2];
for (int index = 0; index current + String.Format(« {0:X2} », b));
}
quangngoc88 a dit:
private string GenerateHMAC(string clear_message, string secret_key)
{
var encoder = new ASCIIEncoding();
byte[] message_bytes = encoder.GetBytes(clear_message);
var secret_key_bytes = new byte[secret_key.Length/2];
for (int index = 0; index current + String.Format(« {0:X2} », b));
}
Anonyme a dit:
Slt formidable traité !
razafintseheno tojo irina a dit:
J’ai fait exactement comme Gora LEYE fait dans ce tuto mais j’ai toujours le problème « Problème d’identificatoin du commerce. Accès refusé! ».
Je me suis renseigné sur ce doc: http://www1.paybox.com/wp-content/uploads/2014/02/ParametresTestPaybox_V6.2_FR.pdf
https://preprod-admin.paybox.com/
site : 1999888
login: 199988832
mdp : 1999888I
rang : 32
identifiant : 110647233
goraleye a dit:
Ok I will send you the zip project.
razafintseheno tojo irina a dit:
Gora Leye > Thanx for your help but I haven’t already get your zip project!! 🙂
goraleye a dit:
hi, Inbox your email adress, I cannot send zip project here
razafintseheno tojo irina a dit:
Hi, could you attach zip project on this article (download source project)
like paypal project pliz?
goraleye a dit:
you can download it now
razafintseheno tojo irina a dit:
thank you for your code, I’ll try immediately
bouarmod a dit:
Bonjour, je ne sais pas si le commentaire sont toujours actifs sur cet article mais je vous présente mon problème cas même. depuis la semaine en suivant cet article j’ai intégré le système paybox à mon projet mais j’obtiens ça comme problème « Erreur de protection. Nous regrettons de ne pouvoir donner une suite favorable à votre demande de paiement. ». bien évidemment avant de poster j’ai testé les solutions proposées par les uns et les autres. toujours pas d’issue favorable.
La spécificité chez moi est que je travaille avec vb.net et c’est mon premier projet sous vb puis que je travaillais avant avec c# => du coup je dois convertir mes pensés(codes) de c# vers vb.net.
J’espère que vous m’expliquerez claire ce qui ont réussie à corriger ce problème chez eux.
Merci d’avance
goraleye a dit:
Bonjour,
tu peux télécharger le code en bas de cette article. pour traduire le c# en vb.net (http://www.developerfusion.com/tools/convert/csharp-to-vb/)
y’a une adresse email dans le mail, tu peux mettre le tiens pour tester
bouarmod a dit:
Merci, j’ai pu résolu le problème et c’était tout bête, je m’explique quand j’appelais l’api du paybox si je voulais faire une opération de 18€ et au lieu de convertir en centimes soit 1800ct. je faisais mon appel direct avec 18€ du coup incohérence avec leurs systèmes => Erreur de protection.
Si tu pouvais modifier ton article en précisant ce point.
Merci en tout mon problème n’étais un problème de conversion de code du c# vers vb.net
tojoirinah a dit:
goraleye > j’ai une autre approche pour la configuration paybox. Comment puis-je uploader un fichier ici afin que je puisse partager mes recherches?
goraleye a dit:
Pour uploader un ficher, il faudrait le mettre sur google drive ou onedrive et mettre le lien dans ton commentaire.
tojoirinah a dit: