The other day, the challenge arose of implementing
PayPal on a commercial site running ASP.NET. After a detailed study of this issue, it turned out that there was very little information on it in runet. Therefore, I think it would be appropriate to highlight this issue. We begin, as always, with the formulation of the problem.
Formulation of the problem
We have an online store where the user selects a product, enters data about his credit card and pays for it through the Internet. Infa credit card is entered directly on the site. The withdrawal transaction must go through
PayPal .
Decision
Step 1. Registering at PayPal Sandbox
To be able to test you need to register in a test environment called
Sandbox . This is done as follows:
1. Go to
developer.paypal.com register a new account there.
2. Login to
developer.paypal.com , go to the
Test Accounts tab and create a new test account for the seller. During creation, select the option
seller . In the password field there will be a password that is required in order to login to SandBox. After creation, an account will appear with an email like blabla_1234567890_biz [at] email.com and the password that was in the password field. Using them
3. Login to
www.sandbox.paypal.com . After login it is necessary to accept the Billing Agreement.
')
Step 2. Website Integration
Gimor option1. On the
PayPal API page
: SOAP Interface, download the
SDK for the .NET platform2. Install the installer, go to the installation directory and retrieve from there from the bin directory of the library log4net.dll and paypal_base.dll. In theory, they contain everything necessary to make the payment system work. Examples of working with these libraries are in the sample site that comes with the SDK.
Negimorny, but trimmed versionThe cutback is that in this way it is possible to do only DirectPayment, but we don’t need more. So, I think this option is optimal.
1.
Download the wrapper for PayPal SDK, which is able to make DirectPayment. The wrapper is a library of log4net.dll and paypal_base.dll, as well as the actual wrapper of SiteMechanics.PayPalDirect.dll. It contains interfaces, IMerchantProfile and IBuyerProfile, as well as default heirs from them. These interfaces are used by the PayPalHelper class, which actually performs payment through PayPal. Thus, in order to use the wrapper, it is necessary to inherit two interfaces, fill in all the fields of the heirs and transfer the inheritors objects to the DoDirectPayment method. The returned object contains the Ack field, if it is equal to Success, then the payment was successful, if not, then the Errors field contains all errors that occurred. If you inherit the vpadlu interfaces, then you can use the already ready heirs of MerchantProfile and BuyerProfile. Example code, see below:
MerchantProfile merchant = new MerchantProfile(
"blabla_1234567890_biz[at]email.com",
"1234567890",
"odifhp9p83948rlwkcmnwli430948f3ojldkjflskdjlsdkjsf0o98209",
"sandbox");
BuyerProfile buyer = new BuyerProfile(
"John","Doe",
"1 Main St","", "San Jose","CA","95131",
"Visa", "4197058882575379","926",
10,2010
);
PayPalResponse PayPalResponse = PayPalHelper.DoDirectPayment("13.45", merchant, buyer);
Underwater rocks
1. Buyer's test credit card:
CreditCardType: Visa
CreditCardNumber: 4197058882575379
VerificationCode: 926
ExpirationDate 2010-10
2. We have a test environment, so we use the “sandbox” as the Environment parameter to enable the “real” PayPal, we need to specify the “live”, but this should be clarified in the official dock.
3. Infu for MerchantProfile take in the API Credentials section on
developer.paypal.com4. This wrapper uses a transfer method between the PayPal server and the site, which is called 3-token, there is still the possibility to do this based on certificates, but it seemed to me gorny, so I did not understand this. RTFM.
5. If you get the error "Security header is not valid", then the parameters for the MerchantProfile are incorrect
6. If you get the error “This transaction cannot be processed due to an invalid merchant configuration”, then the Billing Agreement was not accepted. See the third paragraph of the “Registering with PayPal Sandbox” section.
I warn you at once that the wrapper did not pass the enhanced testing and you, as always, use everything at your own peril and risk. But everything seems to be working there. If anything, write here paradoxs.mail@gmail.com
ReferenceIntegration Center , What is
Sandbox , Download
SDK for different platforms