"Website internationalization Essentials" ASP. NET MVC integration PayPal (PayPal) Express Checkout Payment interface, with source demo

Source: Internet
Author: User
Tags ack ming

First of all to tell you a story of history, Bo is the main person in Xiangyang, Hubei. Xiangyang Wuhua Tianbao, outstanding people, used to name Xiangfan. In more than 2,800 years of history and culture appeared a generation of famous Zhuge Liang (Wolong), the Three Kingdoms Pang Tong (chicken Young), Wei Jin hermit Sima (Shui), the Tang Dynasty poet Meng Haoran (Meng Liang), Zhang Ji, du, writer by Pi Rixiu, the Song Dynasty famous painter Mi fu (rice xiangyang), "Allow the Crown Hundred King" of the Light Emperor Liu Xiu, A large number of historical and cultural celebrities, such as Oriental Sage Release Road Ann. The novel "Kingdoms" 120 back story of more than 30 times mentioned Xiangyang.

Legend has it that Zhuge Liang's wife huangyueying yellow hair black skin, but knowledgeable. Zhuge Liang invented wooden ox, which was developed from the skill of Huangyueying's teaching. Not only that huangyueying also has a big very important invention, is the head dish, inherits many years to now has become the Hubei Xiangyang's a specialty, is also an important food culture, early several years related department according to Zhuge Ming's illustrious name for the head dish to take a more internationalized name: The Ming Yang Food (advertisement language: Eats the Ming Yang Food, seeks the world matter! )。

It is precisely because of the famous Ming dish reputation, in recent years hometown of the prosperous development of the Ming, selling five continents, at home and abroad. In order to better build foreign markets, Bo Master was fortunate enough to become Xiangyang city, Yang Ming cuisine internet e-commerce platform to build a task of a member, responsible for docking international payment interface PayPal.

The above story is only for introduction, part of fiction, if there is similar, it is very honored. If you are going to make money with a foreigner in the future, then follow the rhythm of the blogger to internationalize it!

How does docking PayPal pay? Bo Master chose one of the docking means (fast checkout), but also the current mainstream docking method, specific steps and details see the official Introduction: https://www.paypal-biz.com/developer/internet/ec/, Bo master Friendship tips, The procedure needs to be followed, as the documentation for each step can be looked at roughly.

Because Bo master a debut from the MVC, the traditional WebForm congenital control, nor that leisure time to go back to study, the official source of the download has not been transferred (if there is a big God tune, look at the liberal enlighten! )。 So Bo Master painstaking research, take its technical essence, integrated out a MVC3 version of the demo for you crossing reference.

What does the MVC docking PayPal do? We need to prepare the following materials:

  1. Official registration of the PayPal Premium Account: https://www.paypal.com/c2/webapps/mpp/get-started
    Then in the developer center to create at least one seller and a buyer account (for you to test before going online, the official call sandbox account, as can be understood as the test environment account): https://developer.paypal.com/webapps/ Developer/applications/accounts, such as red on behalf of the seller account, green represents the buyer account


  2. Add the official DLL file to the project, quoting the PayPal class library Paypal_base.dll and Log4net.dll, which are already attached in the source code.

  3. Get the Seller Account API configuration item (the key to the configuration item needs to be obtained from one of the seller's accounts you created, and get it in such a way):


  4. Configure the Seller account API to your website:
    <!--PayPal Payment account Configuration--    <add key= "Apiusername" value= "wen_api1.shipfinder.cn"/> <add key=    " Apipassword "value=" 1376359127 "/>    <add key=" apisinature "value=" An5ns1kso7mwudw4erqkjjj4qi4-akqbvnonvjforjjuxatciravn7v4 "/>    <add key=" Environment "value=" sandbox "/ >    <!--test environment: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=    <!--Real World: https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=--    <add key= " RedirectURL "value=" https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&amp;token= "/>

  5. Setexpresscheckout (Submit an order to PayPal, your own website to do the Order warehousing operation) The core code is as follows:

    Public ActionResult Setexpresscheckout () {
    String currency = request.form["Currencycodetype"];
    String name = request.form["Name"];
    String shiptostreet = request.form["Shiptostreet"];
    String shiptocity = request.form["shiptocity"];
    String shiptostate = request.form["Shiptostate"];
    String shiptocountrycode = request.form["Shiptocountrycode"];
    String shiptozip = request.form["Shiptozip"];
    String l_name1 = request.form["l_name1"];
    String l_amt1 = request.form["L_AMT1"];
    String l_qty1 = request.form["L_qty1"];
    String L_NAME0 = request.form["L_NAME0"];
    String l_amt0 = request.form["L_amt0"];
    String l_qty0 = request.form["L_qty0"];

    String hots = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/";

    NVPCODEC encoder = new Nvpcodec ();
    Encoder. ADD ("Paymentaction", "Sale");

    //Do not allow customers to change addresses
    Encoder. ADD ("Addroverride", "1");
    Encoder. ADD ("Cancelurl", Hots + "/pay/index");
    Encoder. ADD ("CurrencyCode", currency);
    Encoder. ADD ("Shiptoname", name);
    Encoder. ADD ("Shiptostreet", Shiptostreet);
    Encoder. ADD ("Shiptocity", shiptocity);
    Encoder. ADD ("Shiptostate", shiptostate);
    Encoder. ADD ("Shiptocountrycode", Shiptocountrycode);
    Encoder. ADD ("Shiptozip", shiptozip);
    Encoder. ADD ("L_NAME0", L_NAME0);
    Encoder. ADD ("L_number0", "1000");
    Encoder. ADD ("L_desc0", "size:8.8-oz");
    Encoder. ADD ("L_amt0", l_amt0);
    Encoder. ADD ("L_qty0", l_qty0);
    Encoder. ADD ("l_name1", l_name1);
    Encoder. ADD ("L_number1", "10001");
    Encoder. ADD ("L_desc1", "Size:two 24-piece boxes");
    Encoder. ADD ("L_amt1", L_AMT1);
    Encoder. ADD ("L_qty1", l_qty1);
    Encoder. ADD ("l_itemweightvalue1", "0.5");
    Encoder. ADD ("L_itemweightunit1", "lbs");

    Double ft = double. Parse (l_qty0) * Double. Parse (l_amt0) + double. Parse (l_qty1) * Double. Parse (L_AMT1);
    Encoder. ADD ("Itemamt", Ft. ToString ());
    Encoder. ADD ("Taxamt", "2.00");

    Double amt = System.Math.Round (ft + 5.00f + 2.00f + 1.00f, 2);
    Double Maxamt = System.Math.Round (Amt + 25.00f, 2);

    Encoder. ADD ("Shipdiscamt", "3.00");
    Encoder. ADD ("Amt", Amt. ToString ());

    String ReturnURL = Hots + "/pay/getexpresscheckoutdetails?amount=" +amt. ToString ();//Get the address of the order details, also the address after this step

    Encoder. ADD ("RETURNURL", RETURNURL);
    Encoder. ADD ("Shippingamt", "8.00");
    Encoder. ADD ("Maxamt", Maxamt. ToString ());

    Encoder. ADD ("insuranceoptionoffered", "true");
    Encoder. ADD ("Insuranceamt", "1.00");

    Encoder. ADD ("Localecode", "US");

    Encoder. ADD ("Noshipping", "1");

    Encoder. ADD ("L_shippingoptionisdefault0", "false");
    Encoder. ADD ("L_SHIPPINGOPTIONNAME0", "Ground");
    Encoder. ADD ("L_shippingoptionlabel0", "UPS Ground 7 Days");
    Encoder. ADD ("L_shippingoptionamount0", "3.00");
    Encoder. ADD ("L_shippingoptionisdefault1", "true");
    Encoder. ADD ("L_shippingoptionname1", "UPS Air");
    Encoder. ADD ("L_shippingoptionlabel1", "UPS Next day Air");
    Encoder. ADD ("L_shippingoptionamount1", "8.00");

    Encoder. ADD ("Callbacktimeout", "4");

    Nvpcodec decoder = paypalprovider.setexpresscheckout (encoder);

    String ack = decoder["ack"];
    String l_errorcode0 = decoder["L_errorcode0"];
    String l_shortmessage0 = decoder["L_shortmessage0"];
    String l_longmessage0 = decoder["L_longmessage0"];
    String l_severitycode0 = decoder["L_severitycode0"];

    if (!string. IsNullOrEmpty (ACK) &&
    (ACK.) Equals ("Success", System.StringComparison.OrdinalIgnoreCase) | | Ack. Equals ("successwithwarning", System.StringComparison.OrdinalIgnoreCase))
    )
    {
    Send e-mail
    New Mailmanager (email, "order", "Order Information"). Send ();
    session["token"] = decoder["token"];
    Return Redirect (configurationmanager.appsettings["RedirectURL"] + decoder["token"]);

    }
    Else
    {
    Return Redirect ("/pay/index");
    }
    }


    Public ActionResult Setexpresscheckout () {String currency = request.form["Currencycodetype"];            String name = request.form["Name"];            String shiptostreet = request.form["Shiptostreet"];            String shiptocity = request.form["shiptocity"];            String shiptostate = request.form["Shiptostate"];            String shiptocountrycode = request.form["Shiptocountrycode"];            String shiptozip = request.form["Shiptozip"];            String l_name1 = request.form["l_name1"];            String l_amt1 = request.form["L_AMT1"];            String l_qty1 = request.form["L_qty1"];            String L_NAME0 = request.form["L_NAME0"];            String l_amt0 = request.form["L_amt0"];            String l_qty0 = request.form["L_qty0"];            String hots = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/";            NVPCODEC encoder = new Nvpcodec (); Encoder.            ADD ("Paymentaction", "Sale");     Customers are not allowed to change addresses       Encoder.            ADD ("Addroverride", "1"); Encoder.            ADD ("Cancelurl", Hots + "/pay/index"); Encoder.            ADD ("CurrencyCode", currency); Encoder.            ADD ("Shiptoname", name); Encoder.            ADD ("Shiptostreet", Shiptostreet); Encoder.            ADD ("Shiptocity", shiptocity); Encoder.            ADD ("Shiptostate", shiptostate); Encoder.            ADD ("Shiptocountrycode", Shiptocountrycode); Encoder.            ADD ("Shiptozip", shiptozip); Encoder.            ADD ("L_NAME0", L_NAME0); Encoder.            ADD ("L_number0", "1000"); Encoder.            ADD ("L_desc0", "size:8.8-oz"); Encoder.            ADD ("L_amt0", l_amt0); Encoder.            ADD ("L_qty0", l_qty0); Encoder.            ADD ("l_name1", l_name1); Encoder.            ADD ("L_number1", "10001"); Encoder.            ADD ("L_desc1", "Size:two 24-piece boxes"); Encoder.            ADD ("L_amt1", L_AMT1); Encoder.            ADD ("L_qty1", l_qty1); Encoder.            ADD ("l_itemweightvalue1", "0.5"); Encoder. ADD ("L_itemweightunit1 "," lbs "); Double ft = double. Parse (l_qty0) * Double. Parse (l_amt0) + double. Parse (l_qty1) * Double.            Parse (L_AMT1); Encoder. ADD ("Itemamt", Ft.            ToString ()); Encoder.            ADD ("Taxamt", "2.00");            Double amt = System.Math.Round (ft + 5.00f + 2.00f + 1.00f, 2);            Double Maxamt = System.Math.Round (Amt + 25.00f, 2); Encoder.            ADD ("Shipdiscamt", "3.00"); Encoder. ADD ("Amt", Amt.             ToString ()); String ReturnURL = Hots + "/pay/getexpresscheckoutdetails?amount=" +amt. ToString ();//Gets the address of the order details, which is also the address encoder after this step.            ADD ("RETURNURL", RETURNURL); Encoder.            ADD ("Shippingamt", "8.00"); Encoder. ADD ("Maxamt", Maxamt.            ToString ()); Encoder.            ADD ("insuranceoptionoffered", "true"); Encoder.            ADD ("Insuranceamt", "1.00"); Encoder.            ADD ("Localecode", "US"); Encoder.            ADD ("Noshipping", "1"); Encoder.            ADD ("L_shippingoptionisdefault0", "false"); EncodeR.add ("L_SHIPPINGOPTIONNAME0", "Ground"); Encoder.            ADD ("L_shippingoptionlabel0", "UPS Ground 7 Days"); Encoder.            ADD ("L_shippingoptionamount0", "3.00"); Encoder.            ADD ("L_shippingoptionisdefault1", "true"); Encoder.            ADD ("L_shippingoptionname1", "UPS Air"); Encoder.            ADD ("L_shippingoptionlabel1", "UPS Next day Air"); Encoder.            ADD ("L_shippingoptionamount1", "8.00"); Encoder.            ADD ("Callbacktimeout", "4");            Nvpcodec decoder = paypalprovider.setexpresscheckout (encoder);            String ack = decoder["ack"];            String l_errorcode0 = decoder["L_errorcode0"];            String l_shortmessage0 = decoder["L_shortmessage0"];            String l_longmessage0 = decoder["L_longmessage0"];                       String l_severitycode0 = decoder["L_severitycode0"]; if (!string. IsNullOrEmpty (ACK) && (ack. Equals ("Success", System.StringComparison.OrdinalIgnoreCase) | | Ack. Equals ("SuccessWithwarning ", System.StringComparison.OrdinalIgnoreCase)) {//Send e-mail New Mailmanager (email, "order", "Order Information").                Send ();                session["token"] = decoder["token"];            Return Redirect (configurationmanager.appsettings["RedirectURL"] + decoder["token"]);            } else {return Redirect ("/pay/index"); }        }

  6. Getexpresscheckoutdetails (Get the current order details based on the token returned after the order was submitted), the core code is as follows:
    //Get payment details String token = session["token"].            ToString ();            Nvpcodec NVP = new Nvpcodec (); Nvp.            ADD ("token", token); Nvp.            ADD ("CurrencyCode", "USD");            Nvpcodec RESPONSENVP = paypalprovider.getexpresscheckoutdetails (NVP);            String ack = responsenvp["ack"]; if (string.                IsNullOrEmpty (ACK) | | (!ack. Equals ("Success", System.StringComparison.OrdinalIgnoreCase) &&!ack.                              Equals ("successwithwarning", System.StringComparison.OrdinalIgnoreCase))) {            Return Redirect ("/pay/index");            } string payerstatus = responsenvp["Payerstatus"];            string email = responsenvp["email"];            String Payerid = responsenvp["Payerid"];            string FirstName = responsenvp["FirstName"]; string lastname = responsenvp["LastName"]; 

  7. Doexpresscheckoutpayment (verify and pay according to order details, then update the payment status and order status on your own website), the core code is as follows:
    Start paying nvpcodec donvp = new Nvpcodec (); DONVP.            ADD ("token", token); DONVP.            ADD ("AMT", amount); DONVP.            ADD ("Payerid", Payerid); DONVP.            ADD ("Paymentaction", "Sale"); DONVP.            ADD ("CurrencyCode", "USD");            Nvpcodec Response_do = paypalprovider.doexpresscheckoutpayment (DONVP);            String do_ack = response_do["ack"];            String l_errorcode0 = response_do["L_errorcode0"];            String l_shortmessage0 = response_do["L_shortmessage0"];            String l_longmessage0 = response_do["L_longmessage0"];            String l_severitycode0 = response_do["L_severitycode0"]; if (string.                IsNullOrEmpty (do_ack) | | (!do_ack. Equals ("Success", System.StringComparison.OrdinalIgnoreCase) &&!do_ack. Equals ("successwithwarning", System.StringComparison.OrdinalIgnoreCase))) {Retu         RN Redirect ("/pay/index");   } else {string paymenttype = response_do["Paymenttype"];                String TransactionID = response_do["TransactionID"];                String note = response_do["Note"];                String ordertime = response_do["Ordertime"];                String paymentstatus = response_do["Paymentstatus"];                String reason=response_do["Pendingreason"]; Double Feeamt = Double.                Parse (response_do["Feeamt"]); Return Content ("Congratulations on your successful payment!")            "); }

  8. The real core is 5, 6, 7 steps, with the PayPal technician skilled Tone said is Set,get,do, the final step is to deal with our website business logic process. Bo Master here to provide a buyer account for everyone to test (account: [email protected], password: 11111111), the following attached demo running effect:




Source

"Website internationalization Essentials" ASP. NET MVC integration PayPal (PayPal) Express Checkout Payment interface, with source demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.