/// <summary> /// Credentials added to the NVP string /// </summary> /// <param name="profile"></param> /// <returns></returns> private string buildCredentialsNVPString() { var codec = new NVPCodec(); if (!IsEmpty(APIUsername)) { codec["USER"] = APIUsername; } if (!IsEmpty(APIPassword)) { codec["PWD"] = APIPassword; } if (!IsEmpty(APISignature)) { codec["SIGNATURE"] = APISignature; } if (!IsEmpty(Subject)) { codec["SUBJECT"] = Subject; } codec["VERSION"] = "63.0"; return(codec.Encode()); }
/// <summary> /// ShortcutExpressCheckout: The method that calls SetExpressCheckout API /// </summary> /// <param name="amt"></param> /// <param ref name="token"></param> /// <param ref name="retMsg"></param> /// <returns></returns> public bool SetExpressCheckout(string amt, string description, string localeId, ref string token, ref string retMsg) { var url = pendpointurl; var host = "www.paypal.com"; if (_bSandbox) { url = sandboxapiurl; host = "www.sandbox.paypal.com"; APIUsername = WebConfigurationManager.AppSettings["paypal:API_USERNAME-Sandbox"]; APIPassword = WebConfigurationManager.AppSettings["paypal:API_PASSWORD-Sandbox"]; APISignature = WebConfigurationManager.AppSettings["paypal:API_SIGNATURE-Sandbox"]; } else { APIUsername = WebConfigurationManager.AppSettings["paypal:API_USERNAME"]; APIPassword = WebConfigurationManager.AppSettings["paypal:API_PASSWORD"]; APISignature = WebConfigurationManager.AppSettings["paypal:API_SIGNATURE"]; } var encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["USER"] = APIUsername; encoder["PWD"] = APIPassword; encoder["LOCALECODE"] = localeId; encoder["SIGNATURE"] = APISignature; encoder["RETURNURL"] = returnURL; encoder["CANCELURL"] = cancelURL; encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt; encoder["PAYMENTREQUEST_0_SHIPPINGAMT"] = "0.00"; encoder["PAYMENTREQUEST_0_DESC"] = description; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = WebConfigurationManager.AppSettings["paypal:CURRENCYCODE"]; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; var pStrrequestforNvp = encoder.Encode(); var pStresponsenvp = HttpCall(pStrrequestforNvp, url); var decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); var strAck = decoder["ACK"].ToLower(); if ((strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; var ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token; retMsg = ECURL; return(true); } retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); }
/// <summary> /// ConfirmPayment: The method that calls SetExpressCheckout API, invoked from the /// Billing Page EC placement /// </summary> /// <param name="token"></param> /// <param ref name="retMsg"></param> /// <returns></returns> public bool DoExpressCheckoutPayment(string amt, string description, string token, string PayerId, ref NVPCodec decoder, ref string retMsg) { var url = pendpointurl; if (_bSandbox) { url = sandboxapiurl; APIUsername = WebConfigurationManager.AppSettings["paypal:API_USERNAME-Sandbox"]; APIPassword = WebConfigurationManager.AppSettings["paypal:API_PASSWORD-Sandbox"]; APISignature = WebConfigurationManager.AppSettings["paypal:API_SIGNATURE-Sandbox"]; } else { APIUsername = WebConfigurationManager.AppSettings["paypal:API_USERNAME"]; APIPassword = WebConfigurationManager.AppSettings["paypal:API_PASSWORD"]; APISignature = WebConfigurationManager.AppSettings["paypal:API_SIGNATURE"]; } var encoder = new NVPCodec(); encoder["METHOD"] = "DoExpressCheckoutPayment"; encoder["TOKEN"] = token; encoder["USER"] = APIUsername; encoder["PWD"] = APIPassword; encoder["SIGNATURE"] = APISignature; encoder["PAYERID"] = PayerId; encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt; encoder["PAYMENTREQUEST_0_SHIPPINGAMT"] = "0.00"; encoder["PAYMENTREQUEST_0_DESC"] = description; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = WebConfigurationManager.AppSettings["paypal:CURRENCYCODE"]; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; var pStrrequestforNvp = encoder.Encode(); var pStresponsenvp = HttpCall(pStrrequestforNvp, url); decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); var strAck = decoder["ACK"].ToLower(); if (strAck != null && (strAck == "success" || strAck == "successwithwarning")) { return(true); } retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); }
/// <summary> /// GetShippingDetails: The method that calls SetExpressCheckout API, invoked from the /// Billing Page EC placement /// </summary> /// <param name="token"></param> /// <param ref name="retMsg"></param> /// <returns></returns> public bool GetExpressCheckoutDetails(string token, ref string PayerId, ref NVPCodec shippingAddress, ref string retMsg) { var url = pendpointurl; if (_bSandbox) { url = sandboxapiurl; APIUsername = WebConfigurationManager.AppSettings["paypal:API_USERNAME-Sandbox"]; APIPassword = WebConfigurationManager.AppSettings["paypal:API_PASSWORD-Sandbox"]; APISignature = WebConfigurationManager.AppSettings["paypal:API_SIGNATURE-Sandbox"]; } else { APIUsername = WebConfigurationManager.AppSettings["paypal:API_USERNAME"]; APIPassword = WebConfigurationManager.AppSettings["paypal:API_PASSWORD"]; APISignature = WebConfigurationManager.AppSettings["paypal:API_SIGNATURE"]; } var encoder = new NVPCodec(); encoder["METHOD"] = "GetExpressCheckoutDetails"; encoder["TOKEN"] = token; encoder["USER"] = APIUsername; encoder["PWD"] = APIPassword; encoder["SIGNATURE"] = APISignature; var pStrrequestforNvp = encoder.Encode(); var pStresponsenvp = HttpCall(pStrrequestforNvp, url); var decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); var strAck = decoder["ACK"].ToLower(); if ((strAck == "success" || strAck == "successwithwarning")) { shippingAddress = decoder; PayerId = decoder["PAYERID"]; return(true); } retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); }