This book will provide useful resources on PayPal Checkout and Subscriptions APIs and SDKs, as well as their applications in ASP.NET Core projects. It uses the latest PayPal products, services, APIs, and SDKs, and integrates them into your ASP.NET Core applications. this book will be useful for .NET programmers, software developers, and students of all skill levels, who are interested in integrating the PayPal REST APIs into their ASP.NET applications. Click here for more information.
Welcome to "Practical PayPal Integration in ASP.NET Core". This book will provide useful resources on PayPal Checkout and Subscriptions APIs and SDKs, as well as their applications in ASP.NET Core projects. I hope that this book will be useful for .NET programmers, software developers, and students of all skill levels, who are interested in integrating the PayPal REST APIs into their ASP.NET applications.
You may often get confused with PayPal because there are so many frameworks and options to do the same thing. In fact, there are over 50 PayPal services, APIs, and SDKs out there – you just do not know which one is suitable for your applications.In this book, I will choose the latest PayPal products, services, APIs, and SDKs, and integrate them into your ASP.NET Core applications. Here are PayPal technologies that I plan to use:
In the first part of this book, I will explain how to use the PayPal Checkout .NET SDK to get start with the PayPal Version 2 Payments and Orders REST APIs. I will use various examples to demonstrate the procedures to complete a PayPal checkout transaction, including how to set up the development environment, how to integrate and render Smart Payment Buttons, how to create and manage orders, and how to capture and verify the transaction.In the second part of this book, I will switch to PayPal Subscriptions API. This API has not been ported to Version 2 yet, so we have to use Version 1 API for subscription. To make matters even worse, PayPal has never released a stable Subscriptions .NET SDK, which makes it difficult for .NET developers to integrate PayPal Subscriptions API into .NET and .NET Core applications. Therefore, I decide to implement a simple PayPal Subscriptions .NET SDK, which simply exposes various static methods that can be used to integrate PayPal Subscriptions API into .NET applications. I will use several examples to illustrate how to use this SDK to complete subscription transactions.
Introduction 1 1 Overview of ASP.NET Core Razor Pages 7 1.1 ASP.NET Core MVC vs Razor Pages 7 1.2 Install Visual Studio and .NET Core 9 1.3 Create the Razor Pages Project 10 1.4 Examine Project Files 12 1.4.1 Pages Folder 12 1.4.2 wwwroot Folder 12 1.4.3 Other files 12 1.5 Create a New Razor Page 12 1.6 Razor Template 13 1.6.1 @Page 13 1.6.2 Code-Behind File 14 1.7 Model Binding 14 1.8 Tag Helpers 17 1.9 Routing 17 1.10 Security 17 1.11 Client-Side Library Management 17 1.11.1 Add Client-Side Library Files 18 1.11.2 Restore Library Files 20 1.11.3 Delete or Uninstall Library Files 21 2 Set Up PayPal Account 23 2.1 Set Up Developer Account 23 2.2 Create Sandbox Account 26 2.2.1 Access Sandbox Email and SMS 27 2.2.2 Check Sandbox Accounts 28 2.3 Sandbox APIs 30 2.4 Configure REST API in ASP.NET Core 32 2.4.1 Store PayPal REST API Credentials 33 2.4.2 Map to Configuration Class 33 2.4.3 Retrieve Options 35 3 PayPal Smart Payment Buttons 37 3.1 PayPal JavaScript SDK 37 3.2 Render Smart Payment Buttons 40 3.3 Customize JavaScript SDK Script 41 3.4 Customize Smart Payment Buttons 45 3.4.1 Change Color 45 3.4.2 Change Label 46 3.4.3 Change Layout 47 3.4.4 Change Shape 48 4 Checkout with Smart Payment Buttons 51 4.1 Basic PayPal Transaction 51 4.1.1 Create Transactions 51 4.1.2 Verify Test Transactions 54 4.1.3 Capture Transactions 55 4.2 Transaction with Order Details 58 4.2.1 Server-Side Code 58 4.2.2 Code for the View 60 4.2.3 JavaScript Code 64 4.2.4 Examine PayPal Transaction 66 4.2.5 Examine Output 68 5 PayPal Checkout .NET SDK 73 5.1 Set Up SDK 74 5.1.1 Install SDK Package 74 5.1.2 Implement SDK Client Class 75 5.1.3 Service Locator for C# Static Methods 76 5.2 Basic PayPal Transaction on Server 78 5.2.1 ASP.NET Core Web API 80 5.2.2 Test Transaction 82 5.2.3 Examine Order Details 85 5.3 Transaction on Server with Order Details 87 5.3.1 Create Order 88 5.3.2 Test Transaction 92 5.3.3 Examine PayPal Transaction 98 5.3.4 Examining Output 100 6 Payment Management Using Checkout SDK 105 6.1 Retrieve Order Information 105 6.1.1 Get Order Details using Web API 105 6.1.2 Test Web API in Razor Page 107 6.2 Refund 110 6.2.1 Implementation 111 6.2.2 Test on Razor Page 112 6.2.3 Verify Refund 115 6.3 Update Order 116 6.3.1 Implementation 117 6.3.2 Test on Razor Page 118 6.4 Capture Authorization 121 6.4.1 Implementation 121 6.4.2 Test on Razor Page 123 6.4.3 Examine Authorize Transaction 126 6.4.4 Capture Payment 128 7 Implement Subscriptions .NET SDK 131 7.1 Subscription Overview 132 7.1.1 PayPal Subscriptions API Endpoints 132 7.1.2 Pricing Plan 133 7.1.3 Subscription integration 134 7.2 Set Up HTTP Client 134 7.3 Catalog Product 137 7.3.1 Product Class 137 7.3.2 Product Methods 140 7.4 Billing Plan 142 7.4.1 Plan Class 142 7.4.2 Plan Methods 147 7.5 Subscription 150 7.5.1 Subscription Class 150 7.5.2 Subscription Methods 157 8 Subscription Examples 163 8.1 Set Up Client 163 8.2 Test Product 165 8.2.1 Create Product 165 8.2.2 Update Product 168 8.3 Test Plan 172 8.3.1 Create Plan 172 8.3.2 Update Plan 176 8.3.3 Activate and Deactivate Plan 180 8.4 Test Subscription 183 8.4.1 Create Subscription 183 8.4.2 Approve Subscription 186 8.4.3 Examine PayPal Transaction 190 8.5 Use Smart Payment Buttons 192 8.5.1 SubscriptionViewModel Class 192 8.5.2 Razor Page Test 194 Index 203
Welcome to Practical PayPal Integration in ASP.NET Core. This book will provide useful resources on PayPal payment APIs and SDKs, as well as their applications in ASP.NET Core projects. I hope that this book will be useful for .NET programmers, software developers, and students of all skill levels, who are interested in integrating the PayPal REST APIs into their ASP.NET applications.
You, like many developers, may often get confused with PayPal because there are so many frameworks and options to do the same thing. In fact, there are over 50 PayPal services, APIs, and SDKs out there – you just do not know which one is suitable for your applications.
There are much more PayPal, products, services, APIs, and SDKs, which are not listed here.
In this book, I will choose the latest PayPal products, services, APIs, and SDKs, and integrate them into your ASP.NET Core applications. Here are PayPal technologies that I plan to use:
In the first part of this book, I will explain how to use the PayPal Checkout .NET SDK to get start with the PayPal Version 2 Payments and Orders REST APIs. I will use various examples to demonstrate the procedures to complete a PayPal checkout transaction, including how to set up the development environment, how to integrate and render Smart Payment Buttons, how to create and manage orders, and how to capture and verify the transaction.
In the second part of this book, I will switch to PayPal Subscriptions API. I should point out that this API has not been ported to Version 2 yet, so we have to use PayPal Version 1 API for subscription. To make matters even worse, PayPal has never released a stable Subscriptions .NET SDK, which makes it very difficult for .NET developers to integrate PayPal Subscriptions API into .NET and .NET Core applications.
In this book, I will implement a simple PayPal Subscriptions .NET SDK from scratch using the .NET standard class library. I will convert it into a NuGet package later if there is still no official PayPal Subscriptions SDK available. This SDK simply exposes various static methods, which can be used to integrate PayPal Subscriptions API into your .NET or .NET core applications.
This book is organized into eight chapters, each of which covers a different topic about PayPal REST API integration using .NET core Razor Pages. The following summaries of each chapter should give you an overview of the book’s content:
Chapter 1: Overview of ASP.NET Core Razor PageThis chapter provides an overview of ASP.NET Core Razor Pages, which explains how to set up the tools and development environment required for building the server-side framework using Razor Pages. It also illustrate how to create Razor Page applications using examples.
Chapter 2, Set Up PayPal AccountThis chapter explains how to set up PayPal Sandbox account environment, which will be used to integrate PayPal payment API into ASP.NET Core applications. This is a good practice to test your code without risking any actual funds.
Chapter 3. PayPal Smart Payment ButtonsThis chapter discusses PayPal Smart Payment Buttons that were introduced in June 2018. I will show you how to render these buttons in your ASP.NET Core applications and how to customize their attributes including colors, labels, shapes, and layout.
Chapter 4. Checkout with Smart Payment ButtonsThis chapter presents a basic integration of the PayPal checkout with Smart Payment Buttons using PayPal JavaScript SDK on the client side.
Chapter 5, PayPal Checkout .NET SDKThis chapter demonstrates how to use PayPal Checkout .NET SDK to get started quickly with the PayPal REST APIs and complete common actions from the server side. Using an SDK over a direct JavaScript integration allows the SDK to handle authentication for you.
Chapter 6, Payment Management using Checkout SDKThis chapter shows how to use PayPal Checkout .NET SDK to perform various actions, including retrieve information for the old orders, refund the captured funds, update existing orders, and capture authorization. In this chapter, we will explore these features.
Chapter 7, Implement Subscription .NET SDKIn this chapter, I will show you how to implement a basic PayPal Subscriptions .NET SDK based on PayPal Version 1 REST API using the .NET standard class library. This SDK simply exposes various static methods, which allow you to easily integrate PayPal Subscriptions API into your .NET or .NET Core applications.
Chapter 8. Subscription ExamplesThis chapter shows how to use the PayPal Subscriptions .NET SDK in the ASP.NET Core applications. It presents several examples in Razor Pages to demonstrate how to create, update, and activate a product, plan, and subscription. It also provides the detailed procedures on how to perform PayPal subscription transactions using the subscription API and Smart Payment Buttons.
This book contains many screenshot images. I have uploaded the original images to my website at https://book.gincker.com, so you can see them more clearly. I also provide corresponding links within the book, which allows you to easily view the original images.
I should emphasize that the PayPal Subscriptions .NET SDK I implement in this book has limited functionalities, and it should be considered as a temporary solution. So use it in your applications at your own risk.
You can download the example source code for this book from https://github.com/jack1232/PaypalProject. The download includes all the supporting resources that are required to re-create the examples without having to type them in. You do not have to download the code, but it is the easiest way of experimenting with the examples and makes it easy to copy and paste code into your own projects.
Gincker Platform allows you to create charts/graphics, build and test machine-learning models, as well as perform technical analysis in finance without the need of writing any code. Click this link to start Gincker.