public bool ShortcutExpressCheckout(string amt, long ShoppingCartID, ref string token, ref string retMsg, bool isWorkshop) { pEndPointURL = ConfigurationManager.AppSettings["pEndPointURL"]; host = ConfigurationManager.AppSettings["host"]; APIUsername = ConfigurationManager.AppSettings["APIUsername"]; APIPassword = ConfigurationManager.AppSettings["APIPassword"]; APISignature = ConfigurationManager.AppSettings["APISignature"]; if (bSandbox) { pEndPointURL = ConfigurationManager.AppSettings["pEndPointURL_SB"]; host = ConfigurationManager.AppSettings["host_SB"]; APIUsername = ConfigurationManager.AppSettings["APIUsername_SB"]; APIPassword = ConfigurationManager.AppSettings["APIPassword_SB"]; APISignature = ConfigurationManager.AppSettings["APISignature_SB"]; } string returnURL = ConfigurationManager.AppSettings["returnURL"]; string cancelURL = ConfigurationManager.AppSettings["cancelURL"]; if (isWorkshop) { returnURL = ConfigurationManager.AppSettings["returnURLWorkshop"]; cancelURL = ConfigurationManager.AppSettings["cancelWorkshop"]; } NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["NOSHIPPING"] = "1"; encoder["ALLOWNOTE"] = "1"; encoder["RETURNURL"] = returnURL; encoder["CANCELURL"] = cancelURL; encoder["BRANDNAME"] = ConfigurationManager.AppSettings["brandName"]; encoder["INVNUM"] = ShoppingCartID.ToString(); encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD"; // Get the Shopping Cart Products Cart cart = controller.LoadCart(ShoppingCartID); int i = 0; foreach (CartItem cartitem in cart.CartItems) { encoder["L_PAYMENTREQUEST_0_NUMBER" + i] = cartitem.product_id.ToString(); encoder["L_PAYMENTREQUEST_0_NAME" + i] = cartitem.product_title; encoder["L_PAYMENTREQUEST_0_DESC" + i] = cartitem.product_title; encoder["L_PAYMENTREQUEST_0_AMT" + i] = cartitem.final_price.ToString(); encoder["L_PAYMENTREQUEST_0_QTY" + i] = cartitem.quantity.ToString(); i++; } string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token + "&useraction=COMMIT"; retMsg = ECURL; return true; } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return false; } }
public bool DoCheckoutPayment(string finalPaymentAmount, long ShoppingCartID, string token, string PayerID, ref NVPCodec decoder, ref string retMsg) { pEndPointURL = System.Configuration.ConfigurationManager.AppSettings["pEndPointURL"]; host = System.Configuration.ConfigurationManager.AppSettings["host"]; APIUsername = System.Configuration.ConfigurationManager.AppSettings["APIUsername"]; APIPassword = System.Configuration.ConfigurationManager.AppSettings["APIPassword"]; APISignature = System.Configuration.ConfigurationManager.AppSettings["APISignature"]; if (bSandbox) { pEndPointURL = ConfigurationManager.AppSettings["pEndPointURL_SB"]; host = ConfigurationManager.AppSettings["host_SB"]; APIUsername = ConfigurationManager.AppSettings["APIUsername_SB"]; APIPassword = ConfigurationManager.AppSettings["APIPassword_SB"]; APISignature = ConfigurationManager.AppSettings["APISignature_SB"]; } NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "DoExpressCheckoutPayment"; encoder["TOKEN"] = token; encoder["PAYERID"] = PayerID; encoder["PAYMENTREQUEST_0_AMT"] = finalPaymentAmount; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD"; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["NOSHIPPING"] = "1"; encoder["ALLOWNOTE"] = "1"; encoder["BRANDNAME"] = ConfigurationManager.AppSettings["brandName"]; encoder["INVNUM"] = ShoppingCartID.ToString(); Cart cart = controller.LoadCart(ShoppingCartID); int i = 0; foreach (CartItem cartitem in cart.CartItems) { encoder["L_PAYMENTREQUEST_0_NUMBER" + i] = cartitem.product_id.ToString(); encoder["L_PAYMENTREQUEST_0_NAME" + i] = cartitem.product_title; encoder["L_PAYMENTREQUEST_0_DESC" + i] = cartitem.product_title; encoder["L_PAYMENTREQUEST_0_AMT" + i] = cartitem.final_price.ToString(); encoder["L_PAYMENTREQUEST_0_QTY" + i] = cartitem.quantity.ToString(); i++; } string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { return true; } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return false; } }
public bool GetCheckoutDetails(string token, ref NVPCodec decoder, ref string retMsg) { pEndPointURL = System.Configuration.ConfigurationManager.AppSettings["pEndPointURL"]; host = System.Configuration.ConfigurationManager.AppSettings["host"]; APIUsername = System.Configuration.ConfigurationManager.AppSettings["APIUsername"]; APIPassword = System.Configuration.ConfigurationManager.AppSettings["APIPassword"]; APISignature = System.Configuration.ConfigurationManager.AppSettings["APISignature"]; if (bSandbox) { pEndPointURL = ConfigurationManager.AppSettings["pEndPointURL_SB"]; host = ConfigurationManager.AppSettings["host_SB"]; APIUsername = ConfigurationManager.AppSettings["APIUsername_SB"]; APIPassword = ConfigurationManager.AppSettings["APIPassword_SB"]; APISignature = ConfigurationManager.AppSettings["APISignature_SB"]; } NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "GetExpressCheckoutDetails"; encoder["TOKEN"] = token; string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { return true; } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return false; } }