Before cloud era, implementing a payment function was really hard, but now it’s really easy by Payment as a Service. In this tutorial, I explain how to develop a basic shopping service with PayPal.
Information
Ingredients
- Template: Simple Search
- API Loigcs: PayPal Payments API, MongoDB
Functions
- Using PayPal payments.
- Storing products and payments in MongoDB.
Requirements
Database
To run this program, you need to create MongoDB collections.
- collections
sample_product
Create the application
Frontend
Choose
Simple SearchTemplate.Customize the UI in K5 Playground.
Backend
Edit API Logics to set credentials for PayPal.
Click
POST paymentendpoint.Edit the code of
Create a PaymentAPI Logic.Edit the parameter of
configuremethod.1
2
3
4
5paypal.configure({
mode: 'sandbox',
client_id: '[client id]',
client_secret: '[client secret]',
});Click
GET payment/{paymentId}endpoint.Same as 1-2.
Click
POST payment/{paymentId}/executeendpoint.Same as 1-2.
Set URL to redirect from PayPal site to your site.
Click
POST paymentendpoint.Edit the code of
Create Paypal ParametersAPI Logic.Edit the property of
redirect_urls.1
2
3
4redirect_urls: {
return_url: 'http://[FRONTEND_DOMAIN]/payment',
cancel_url: 'http://[FRONTEND_DOMAIN]/',
},
Download the application.
Deploy the application
Setup datastore and data
Prepare for product images used in the application.
- Put all images into
frontend/public/imgdirectory.
- Put all images into
Set up MongoDB.
Create a new database named
FrontendDB.Create a new collection named
sample_productin the database.Insert product information into the collection.
This product data will be used to show products on the frontend. The format is as follows.
1
2
3
4
5
6
7{
"category" : "Stationary",
"name" : "Blue Fountain Pen",
"description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do iusmod tempor incididunt ut labore et dolore magna aliqua.",
"image_url" : "/img/pen.jpg",
"price" : "100"
}
Backend
1 | cd backend |
Frontend
1 | cd frontend |
Download
Version
- Simple Search Template: v1.0.0