/// <summary> /// Credentials added to the NVP string /// </summary> /// <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"] = "2.3"; return(codec.Encode()); }
/// <summary> /// GetShippingDetails: The method that calls SetExpressCheckout API, invoked from the /// Billing Page EC placement /// </summary> /// <param name="token"></param> /// <param name="shippingAddress"> </param> /// <param ref="" name="retMsg"></param> /// <returns></returns> public bool GetShippingDetails(string token, ref string payerId, ref ShippingAddress shippingAddress, ref PaypalErrorModel retMsg) { if (UseSandbox) { _pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; } var encoder = new NvpCodec(); encoder["METHOD"] = "GetExpressCheckoutDetails"; encoder["TOKEN"] = token; var pStrrequestforNvp = encoder.Encode(); var pStresponsenvp = HttpCall(pStrrequestforNvp); var decoder = new NvpCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); payerId = decoder["PAYERID"].ToLower(); if ((strAck == "success" || strAck == "successwithwarning")) { shippingAddress.FirstName = decoder["FIRSTNAME"]; shippingAddress.LastName = decoder["LASTNAME"]; shippingAddress.ShipToName = decoder["SHIPTONAME"]; shippingAddress.Street1 = decoder["SHIPTOSTREET"]; shippingAddress.Street2 = decoder["SHIPTOSTREET2"]; shippingAddress.City = decoder["SHIPTOCITY"]; shippingAddress.State = decoder["SHIPTOSTATE"]; shippingAddress.Zip = decoder["SHIPTOZIP"]; //ShippingAddress = "<table><tr>"; //ShippingAddress += "<td> First Name </td><td>" + decoder["FIRSTNAME"] + "</td></tr>"; //ShippingAddress += "<td> Last Name </td><td>" + decoder["LASTNAME"] + "</td></tr>"; //ShippingAddress += "<td colspan='2'> Address</td></tr>"; //ShippingAddress += "<td> Name </td><td>" + decoder["SHIPTONAME"] + "</td></tr>"; //ShippingAddress += "<td> Street1 </td><td>" + decoder["SHIPTOSTREET"] + "</td></tr>"; //ShippingAddress += "<td> Street2 </td><td>" + decoder["SHIPTOSTREET2"] + "</td></tr>"; //ShippingAddress += "<td> City </td><td>" + decoder["SHIPTOCITY"] + "</td></tr>"; //ShippingAddress += "<td> State </td><td>" + decoder["SHIPTOSTATE"] + "</td></tr>"; //ShippingAddress += "<td> Zip </td><td>" + decoder["SHIPTOZIP"] + "</td>"; //ShippingAddress += "</tr>"; return(true); } retMsg = new PaypalErrorModel { ErrorCode = decoder["L_ERRORCODE0"], Desc = decoder["L_SHORTMESSAGE0"], Desc2 = decoder["L_LONGMESSAGE0"] }; //retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + // "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + // "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); }
/// <summary> /// ShortcutExpressCheckout: The method that calls SetExpressCheckout API /// </summary> /// <param name="amount"></param> /// <param ref="" name="token"></param> /// <param name="retMsg"> <ref></ref> </param> /// <returns></returns> public bool ShortcutExpressCheckout(string amount, ref string token, ref string retMsg) { var host = "www.paypal.com"; if (UseSandbox) { _pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; host = "www.sandbox.paypal.com"; } //const string returnURL = "http://localhost:12458/Account/ConfirmPaypal"; //const string cancelURL = "http://localhost:12458/Account/CancelFromPaypal"; var encoder = new NvpCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["RETURNURL"] = ReturnURL; encoder["CANCELURL"] = CancelURL; encoder["AMT"] = amount; encoder["PAYMENTACTION"] = "Sale"; encoder["CURRENCYCODE"] = CurrentCode; string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); var decoder = new NvpCodec(); decoder.Decode(pStresponsenvp); string 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="finalPaymentAmount"> </param> /// <param name="token"></param> /// <param name="retMsg"> <ref></ref> </param> /// <param name="payerId"> </param> /// <returns></returns> public bool ConfirmPayment(string finalPaymentAmount, string token, string payerId, ref NvpCodec decoder, ref PaypalErrorModel retMsg) { if (UseSandbox) { _pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; } var encoder = new NvpCodec(); encoder["METHOD"] = "DoExpressCheckoutPayment"; encoder["TOKEN"] = token; encoder["PAYMENTACTION"] = "Sale"; encoder["PAYERID"] = payerId; encoder["AMT"] = finalPaymentAmount; encoder["CURRENCYCODE"] = CurrentCode; string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); decoder = new NvpCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if ((strAck == "success" || strAck == "successwithwarning")) { return(true); } retMsg = new PaypalErrorModel { ErrorCode = decoder["L_ERRORCODE0"], Desc = decoder["L_SHORTMESSAGE0"], Desc2 = decoder["L_LONGMESSAGE0"] }; //retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + // "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + // "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); }
/// <summary> /// MarkExpressCheckout: The method that calls SetExpressCheckout API, invoked from the /// Billing Page EC placement /// </summary> /// <param name="amount"></param> /// <param name="shipToCountryCode"> </param> /// <param name="token"> <ref></ref> </param> /// <param ref name="retMsg"></param> /// <param name="shipToName"> </param> /// <param name="shipToStreet"> </param> /// <param name="shipToStreet2"> </param> /// <param name="shipToCity"> </param> /// <param name="shipToState"> </param> /// <param name="shipToZip"> </param> /// <returns></returns> public bool MarkExpressCheckout(string amount, string shipToName, string shipToStreet, string shipToStreet2, string shipToCity, string shipToState, string shipToZip, string shipToCountryCode, ref string token, ref PaypalErrorModel retMsg) { string host = "www.paypal.com"; if (UseSandbox) { _pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; host = "www.sandbox.paypal.com"; } //const string returnURL = "http://localhost:12458/Account/ConfirmPaypal"; //const string cancelURL = "http://localhost:12458/Account/CancelFromPaypal"; var encoder = new NvpCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["RETURNURL"] = ReturnURL; encoder["CANCELURL"] = CancelURL; encoder["AMT"] = amount; encoder["PAYMENTACTION"] = "Sale"; encoder["CURRENCYCODE"] = CurrentCode; //Optional Shipping Address entered on the merchant site encoder["SHIPTONAME"] = shipToName; encoder["SHIPTOSTREET"] = shipToStreet; encoder["SHIPTOSTREET2"] = shipToStreet2; encoder["SHIPTOCITY"] = shipToCity; encoder["SHIPTOSTATE"] = shipToState; encoder["SHIPTOZIP"] = shipToZip; encoder["SHIPTOCOUNTRYCODE"] = shipToCountryCode; string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = HttpCall(pStrrequestforNvp); var decoder = new NvpCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"].ToLower(); if ((strAck == "success" || strAck == "successwithwarning")) { token = decoder["TOKEN"]; string ecurl = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token; //retMsg = ECURL; retMsg = new PaypalErrorModel { ErrorCode = "200", Desc = ecurl, }; return(true); } retMsg = new PaypalErrorModel { ErrorCode = decoder["L_ERRORCODE0"], Desc = decoder["L_SHORTMESSAGE0"], Desc2 = decoder["L_LONGMESSAGE0"] }; //retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + // "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + // "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); }