E-COMMERCE
ACCEPT AN ONLINE PAYMENT
There are various technical solutions for accepting payments-on-line. We could create a Form ourselves and collect credit card information, however, there is a major hurdle, which is customer trust. Let’s imagine that a user arrives at our site, never heard of it, the user might be hesitant to enter credit card information, precisely because being a first visit the user might express a lack of trust in the people behind MyCourse. If we want to set up a Form, assuming the customer trusts it, that collects credit card numbers we must meet these basic security rules.
If we do not want to create the Credit Card Form ourselves, we must rely on outside services.
As you can see there are commissions to be paid, so not all of the amount derived from the purchase of a course will reach our principal. These services offer a payment flow called Checkout.
We would never learn about payment information on stripe.com or PayPal, and this saves us a lot of trouble. What you see represented is the flow of information. Let’s look at the implementation of Checkout in the application. Clicking on sign up will invoke the Pay action, which will redirect us to the PayPal site for payment. Once the payment is completed, it is PayPal itself that will redirect us to the Subscribe action in CoursesController.cs to confirm the payment.
Let’s look at the flow in a little more detail.
ACCEPTING PAYMENTS WITH PAYPAL:THE SANDBOX
The Sandbox is a test environment completely isolated from production, where we can do as much testing as we want. Go with your Browser to the following address and create an app. https://developer.paypal.com/dashboard/applications/sandbox. Once you have authenticated yourself you will be redirected to the following page.
I have already created the MyCourse app and PayPal has provided me with Client ID and secret. Now click on the MyCourse app, which I remind you to create.
Click on Testing Tools and choose the Sandbox Account menu item. PayPal provides you with two accounts, a Business account which is a typical business account and a Personal account that you will need to use to purchase courses. I’ll show you a screenshot.
ACCEPT PAYMENTS WITH PAYPAL:THE REDIRECTION TO THE PAGE
In this section we will see how to create the redirection URL to the PayPal payment page. Let’s look at the implementation.
I created this infrastructure interface.
The concrete implementation can be found in the PaypalPaymentGateway.cs infrastructure service commented step by step.
ACCEPTING PAYMENTS WITH PAYPAL:PAYMENT CAPTURE
Once payment is made, PayPal redirects us to the Subscribe action providing a token that allows us to determine whether payment has been made. If he did we must capture the payment, that is, transfer the funds from the buyer’s card or PayPal account to the seller’s. Knowing how to capture a PayPal payment is not the responsibility of an application service, but of an infrastructure service. The code in the infrastructure service PaypalPaymentGateway.cs is commented out.
LINK TO CODE ON GITHUB
Download the section code19 or the master branch or clone the GITHUB repository to have all the sections available in your favorite editor.
Leave A Comment