thanhhieu291082-yahoo
-
2/25/2009 2:16:58 AM
How to custom payment gateway using Paypal payment method?
Dear, I custom payment gateway depend on KenticoCMS_EcommerceGuide_Purchase process and payment gateways_Developing custom payment gateways. I using PayPal payment method I create custom payment gateway form and custom payment gateway class, in shopping cart process, at step 6 of shopping cart process when payment gateway form show, I click "Finish Payment" button and it redirect to https://www.sandbox.paypal.com/us/cgi-bin/webscr with parametter of URL: https://www.sandbox.paypal.com/cgi-bin/webscr?cardnumber=4991319512885564&price=25.289¤cy=USD&orderid=29 but paypay is not recognize my order, it isn't minus money in my account and don't have this order This is my code: Payment gateway form:
public partial class Doggy_PaymentProvider_CustomPaypalGatewayForm : CMSPaymentGatewayForm { protected void Page_Load(object sender, EventArgs e) { lblTitle.Text = "Your credit card details"; lblCardNumber.Text = "Credit card number:"; } public override void LoadData() { base.LoadData(); txtCardNumber.Text = ValidationHelper.GetString(this.ShoppingCartInfoObj.PaymentGatewayCustomData["CustomGatewayCardNumber"], ""); } public override string ValidateData() { return base.ValidateData(); if (txtCardNumber.Text.Trim() == "") { lblError.Visible = true; lblError.Text = "Please enter your credit card number"; return lblError.Text; } return ""; } public override string ProcessData() { this.ShoppingCartInfoObj.PaymentGatewayCustomData["CustomGatewayCardNumber"] = txtCardNumber.Text.Trim(); return ""; } }
Custom payment gateway class: namespace Doggy.PaymentProvider { public class PaypalPaymentGateway : CMSPaymentGatewayProvider { public PaymentResultInfo PaypalPaymentResult;
public override CMSPaymentGatewayForm GetPaymentDataForm() { try { return (CMSPaymentGatewayForm)this.ShoppingCartControl.LoadControl("~/Doggy/PaymentProvider/CustomPaypalGatewayForm.ascx"); } catch { return null; } } public override void ProcessPayment() { // Get payment gateway url string url = this.GetPaymentGatewayUrl(); if (url != "") { // Initialize payment parameters Hashtable parameters = InitializePaymentParameters(); // Add required payment data to the url url = GetFullPaymentGatewayUrl(url, parameters); // Redirect to payment gateway to finish payment this.ShoppingCartControl.Page.Response.Redirect(url); } else { // Show error message - payment gateway url not found this.ErrorMessage = "Unable to finish payment: Payment gateway url not found."; // Update payment result this.PaypalPaymentResult.PaymentDescription = this.ErrorMessage; this.PaypalPaymentResult.PaymentIsCompleted = false; // Update order payment result in database this.UpdateOrderPaymentResult(); } }
/// <summary> /// Returns table with initialized payment parameters. /// </summary> /// <returns></returns> private Hashtable InitializePaymentParameters() { Hashtable parameters = new Hashtable(); parameters["orderid"] = this.ShoppingCartInfoObj.OrderId; parameters["price"] = this.ShoppingCartInfoObj.TotalPrice; parameters["currency"] = this.ShoppingCartInfoObj.CurrencyInfoObj.CurrencyCode; parameters["cardnumber"] = Convert.ToString(this.ShoppingCartInfoObj.PaymentGatewayCustomData["CustomGatewayCardNumber"]); return parameters; }
/// <summary> /// Returns payment gateway url with payment data in query string. /// </summary> /// <param name="url">Payment gateway url.</param> /// <param name="parameters">Initialized payment paremeters.</param> /// <returns></returns> private string GetFullPaymentGatewayUrl(string url, Hashtable parameters) { foreach (DictionaryEntry parameter in parameters) { // Add payment data to the url url = UrlHelper.AddParameterToUrl(url, Convert.ToString(parameter.Key), HttpUtility.UrlEncode(Convert.ToString(parameter.Value))); } return url; } } }
Please help me how to custom payment gateway correct and which param I need to get
|