ASP. NET Core MVC PayPal payment, callback--app payment

Source: Internet
Author: User

Recently joined a cross-border internet of things company, just came to receive the demand is to pay and PayPal payment, pay to do a lot of people, no big difficulty, before the essay mentioned, today mainly to talk about PayPal payment.

First, you should apply for a sandbox environment payment account and collection account, convenient to set up the account information test payment.

Just started to work on a hole is a document, because PayPal as long as the cross-border payment, so his documents are also in English, so for a poor English foundation is really flawed (the most headache is a computer translation on the card), no way can only bite the bullet a little bit to see, Really can not understand the Baidu section of the translation. After reading the document, I downloaded the sdk,sdk version of PayPal and chose the right one for myself, because I was using. NET core to refer to the PayPal DLL directly inside NuGet. Just paste the core code for reference only:

Since we are writing the Wabapi interface for the app-side call, so the PayPal payment is mainly done by the app, but at the beginning of the process is not clear, I also study the next PC side of the tune-up mode, reference to the SDK after the things are very simple

My side to adjust the main use of the public static Payment Create (Apicontext apicontext, Payment Payment); Parameters are populated according to the entity class.

Our API is mainly done after the payment of the background processing operations, so get the app to pay the ID can be obtained through the SDK to pay details payment.get (apicontext, Paypalid), the interface can be put into the information.

Thought this would be over, and later for insurance, plus PayPal's asynchronous callback IPN

var BODY = string. Empty;
using (var reader = new StreamReader (Request.body, Encoding.UTF8))
{
BODY = await reader. Readtoendasync ();
}
BODY = "cmd=_notify-validate&" + body;

var paras = body. Slice ("&"). ToDictionary (x = x.slice ("=", 2) [0], x = = Webutility.urldecode (X.slice ("=", 2) [1]);

such as Orderid=paras. Peek ("txn_id")

var content = new Formurlencodedcontent (paras);

_paypalconfig.validateurl configured sandbox address: HTTPS://WWW.SANDBOX.PAYPAL.COM/CGI-BIN/WEBSCR
var response = await client. Postasync (_paypalconfig.validateurl, content);
var message = await response. Content.readasstringasync ();

The message is judged after the callback is received . Equals ("verified") &&paras. Peek ("Payment_status"). Equals ("completed") at the same time to meet the background and then to the user to complete the recharge.

OK, the basic process is this, of course, this is only a personal approach, for reference only!!!

ASP. NET Core MVC PayPal payment, callback--app payment

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.