What is Nova MVC

How to integrate PayPal payments into an MVC application

The payment process

Authentication

The config manager from the PayPal namespace. API reads the setting from the web.config so that the app receives an OAuth token with which it can identify itself to the PayPal services.

confirmation

Now the PayPal payment must be created and sent to PayPal so that the customer authenticates himself and confirms the payment. The PayPal API has provided several classes for this:

  • Payment: Creates the payment and executes the payment.
  • Payer: Information about the customer.
  • RedirectUrl: Defines to which URLs PayPal should forward after a payment or after the cancellation of a payment.
  • Transaction: Contains the most important information about a payment
    Amount: Contains information about the amount such as monetary currency, tax information and total amount.
    ItemList: Is a collection of items (item with all related information such as price, number, description, etc.)

The classPayment offers the methodCreate to make the payment:

A request is sent to PayPal with all payment information. In response to this, the app receives a URL to which the user is redirected. In order to recognize the user, the payment ID is saved in the session.

The user has to log in to PayPal and make the payment. Which payment method he uses to pay at PayPal is not important to us. PayPal accepts the payment and directs the user to the redirect URL that we received or to the cancel URL if the user cancels the payment.

PayPal adds parameters to the URL it has received from us and forwards the user to them. Based on the parameters and the information stored in the session, the process is recognized and the payment is continued.

execution

After the user has confirmed the payment, the classPayment executed. For this the methodExecute called.

The method queries the status of the transaction from PayPal and receives the status of the payment in response. If the status is "approved", the payment was successful, otherwise it was not. A payment can have 3 different statuses:

  • Created: The transaction has been created but has not yet been confirmed by the payer.
  • Approved: The payer has confirmed the payment with PayPal.
  • Failed: The transaction was unsuccessful.

The application should then - depending on the status - forward the user to another page or display a corresponding message.