/// <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 GetShippingDetails(string token, ref string PayerId, ref string ShippingAddress, ref string retMsg) { if (bSandbox) { pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; } NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "GetExpressCheckoutDetails"; encoder["TOKEN"] = token; 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")) { 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'> Shipping Address</td></tr>"; ShippingAddress += "<td> Name </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTONAME"] + "." + "</td></tr>"; ShippingAddress += "<td> Street1 </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOSTREET"] + "." + "</td></tr>"; ShippingAddress += "<td> Street2 </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOSTREET2"] + "." + "</td></tr>"; ShippingAddress += "<td> City </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOCITY"] + "." + "</td></tr>"; ShippingAddress += "<td> State </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOSTATE"] + "." + "</td></tr>"; ShippingAddress += "<td> Zip </td><td>" + ":" + decoder["PAYMENTREQUEST_0_SHIPTOZIP"] + "." + "</td>"; ShippingAddress += "</tr></table>"; return(true); } else { 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 ConfirmPayment(string finalPaymentAmount, string token, string PayerId, ref NVPCodec decoder, ref string retMsg) { if (bSandbox) { pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; } NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "DoExpressCheckoutPayment"; encoder["TOKEN"] = token; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["PAYERID"] = PayerId; encoder["PAYMENTREQUEST_0_AMT"] = finalPaymentAmount; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD"; 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); } }
/// <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 ShortcutExpressCheckout(string amt, ref string token, ref string retMsg, List <Cart> cartItems, decimal dshipping) { string host = "www.paypal.com"; if (bSandbox) { pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; host = "www.sandbox.paypal.com"; } string returnURL = "http://localhost:5032/CheckOutPaypal/ConfirmPaiement"; string cancelURL = "http://localhost:5032/CheckOutPaypal/CancelPaiement"; NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["RETURNURL"] = returnURL; encoder["CANCELURL"] = cancelURL; encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD"; int i = 0; foreach (var items in cartItems) { encoder["L_PAYMENTREQUEST_0_NAME" + i] = items.Product.Name; string TotaltwoDec = items.TotalPerItem.ToString("0.00"); // Important de mettre 2 chiffres après la virgule sinon ça f**k paypal. TotaltwoDec = TotaltwoDec.Replace(",", "."); // On remplace les virgules française pour des points! encoder["L_PAYMENTREQUEST_0_AMT" + i] = TotaltwoDec; // On envoie le string à PayPal, PayPal aime les string. encoder["L_PAYMENTREQUEST_0_QTY" + i] = items.Count.ToString(); i++; } encoder["L_PAYMENTREQUEST_0_NAME" + i] = "Shipping"; string sshipping = dshipping.ToString("0.00").Replace(',', '.'); encoder["L_PAYMENTREQUEST_0_AMT" + i] = sshipping; encoder["L_PAYMENTREQUEST_0_QTY" + i] = "1"; 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; retMsg = ECURL; return(true); } else { 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="amt"></param> /// <param ref name="token"></param> /// <param ref name="retMsg"></param> /// <returns></returns> public bool MarkExpressCheckout(string amt, string shipToName, string shipToStreet, string shipToStreet2, string shipToCity, string shipToState, string shipToZip, string shipToCountryCode, ref string token, ref string retMsg) { string host = "www.paypal.com"; if (bSandbox) { pendpointurl = "https://api-3t.sandbox.paypal.com/nvp"; host = "www.sandbox.paypal.com"; } string returnURL = "http://localhost:5032/CheckOutPaypal/ConfirmPaiement"; string cancelURL = "http://localhost:5032/CheckOutPaypal/CancelPaiement"; NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "SetExpressCheckout"; encoder["RETURNURL"] = returnURL; encoder["CANCELURL"] = cancelURL; encoder["PAYMENTREQUEST_0_AMT"] = amt; encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale"; encoder["PAYMENTREQUEST_0_CURRENCYCODE"] = "CAD"; //Optional Shipping Address entered on the merchant site encoder["PAYMENTREQUEST_0_SHIPTONAME"] = shipToName; encoder["PAYMENTREQUEST_0_SHIPTOSTREET"] = shipToStreet; encoder["PAYMENTREQUEST_0_SHIPTOSTREET2"] = shipToStreet2; encoder["PAYMENTREQUEST_0_SHIPTOCITY"] = shipToCity; encoder["PAYMENTREQUEST_0_SHIPTOSTATE"] = shipToState; encoder["PAYMENTREQUEST_0_SHIPTOZIP"] = shipToZip; encoder["PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE"] = shipToCountryCode; 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; retMsg = ECURL; return(true); } else { retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + "Desc2=" + decoder["L_LONGMESSAGE0"]; return(false); } }