This tip explains about the Direct Payment API i.e how we can do online payment using Direct Payment API.

In case of Direct Payment API,
the customer need not require to have a PayPal account for payment, rather they can pay directly using the credit cards. We just need to display the user a page with text fields, where the user will enter his credit card info and the amount to pay and of course a submit button. In our case let’s name the page as “Payment.aspx” and the button as “btnPayment”.

After entering the details of credit card info and the amount to pay, when the user click on Submit button, the payment information is sent to PayPal using the PayPal DoDirectPayment API operation. PayPal processes the payment information and the amount sumitted by the user get transferred to the seller’s paypal account. All these API operation get executed in the background and when these are getting excuted, the customer is still in the same payment page.

We first need a PayPal sandbox account in the PayPal Sandbox site https://developer.paypal.com/. Once we have completed the sign up and verification process, we should be able to log into our sandbox account.

Processs – 2: Create Test Accounts

After logged in, in the sandbox “Home” page we have a section called “Test Accounts”. Here we need to create one “Seller” and one “Buyer” test account. In the Test Account section, click on “create a preconfigured account” link.

Create a seller account :

Select Website Payments Pro (Use to represent yourself as a merchant using Pro) for the Account type, enter email and password, enter some amount, check “Add bank account” and Click on create account. Once done, generate the API credentials from this account and use it for testing. Lets say, the API credentials generated as below, these credentials will be get used while doing online payment using DoDirectPaypalAPI.

After all the above set up, now the time is for Application level implementation.

Step-1: Add a web reference to the project.Enter the web service URL as “https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl” and add the service. A new web refernce named as “com.paypal.sandbox.www” will be found inside the WebReference folder.

Step – 2: Add a appsetting key in the web.config file in order to switch between developmnet environment and production environment.

With the absence of values for these required fields, the paypal transaction will get failed.

The exection of DoDirectPayment API operation results a response type of DoDirectPaymentResponseType, which will contain the info like Ack code (Success, SuccessWithWarning, or Failure), Amount of the transaction, PayPal transaction ID, Error codes and messages etc.

we can also use DoDirectPaymentResponseType further to obtain various data about the transaction made like PaymentStatus,paymenterrors,TransactionID etc

The information collected here is hardcoded, we can replace it with the value of the corresponding text fields present in the Payment.aspx page. For the credit card info, we are using the details generated for the buyer account .Below is the code for the button click event.

After the execution if we go to the test account page and click the “view details” link of seller/business account, then we can found the amount sumitted by the customer (here hardcoded to $1000.00) has been added to the seller’s account.