-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
155c779
commit d409590
Showing
1 changed file
with
86 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,290 +1,86 @@ | ||
# Pay with Pi App Backend | ||
|
||
The only variable you need to provide is `Pay with Pi_API_KEY`, which is required to authorize payments. You receive it | ||
upon app registration. For more guidelines on registering your app refe# Pay with pi App Backend | ||
|
||
The only variable you need to provide is `Pay with Pi_API_KEY`, which is required to authorize payments. You receive it | ||
upon app registration. For more guidelines on registering your app refer to | ||
the [Pi Developer Guide](https://Paywithpi-apps.github.io/community-developer-guide/docs/gettingStarted/devPortal/). | ||
|
||
`FRONTEND_URL` specifies the URL of the frontend app, which by default is `http://localhost:3314`. | ||
Depending on sandbox settings you're using to preview Pay with Pi app, you may need to change this value accordingly. | ||
|
||
The Pay with Pi app's backend uses a local MongoDB server to store user data and session details. | ||
|
||
## Setup | ||
|
||
### 1. Install dependencies: | ||
|
||
You will need a working NodeJS installation, and `yarn`. **The Pay with Pi app frontend isn't meant to support npm**. | ||
In most cases, `yarn` will come along with your NodeJS installation. | ||
|
||
Install dependencies by running `yarn install`. | ||
|
||
|
||
### 2. Set up environment variables | ||
|
||
The demo app's backend use several environment variables, from which most have default values. In order to specify | ||
these, create `.env` file in the root backend directory. | ||
|
||
Create your `.env` file from the template: | ||
|
||
```shell | ||
cp .env.example .env | ||
|
||
|
||
# Edit the resulting file: | ||
vi .env | ||
# or: | ||
nano .env | ||
``` | ||
|
||
Obtain the following values from the developer portal: | ||
|
||
**Session secret**: Generate a random string (e.g 64 alphanumeric characters). | ||
|
||
**API key**: obtained by tapping the "Get API Key" button | ||
|
||
![](./img/pay with pi_key.png) | ||
|
||
Then, copy-paste those values in the following two keys of your .env file: | ||
|
||
``` | ||
# Add your API key here: | ||
Pay with Pi_API_KEY= | ||
Https://paywithpi.com/validation-key.txt | ||
# Add your session secret here: | ||
SESSION_SECRET=wgzuxn4pdezkqgu2bihwortnynjbearrtbqnnkjm9ofxfjk14ksoyoc78e1fkgtu | ||
``` | ||
|
||
|
||
### 2. Set up MongoDB | ||
|
||
The default port for MongoDB is `27017`. If you have decided to change either default port or username and password, | ||
make sure to update environment variables in the backend `.env` file accordingly. | ||
Additionally, you can specify MongoDB name env variable, which if not specified will be named `Pay with Pi-app` by default. | ||
|
||
**Option 1: using Docker:** | ||
|
||
Start a MongoDB server using the following command: | ||
|
||
``` | ||
docker run --name Pay with Pi app-mongo -d \ | ||
-e MONGO_INITDB_ROOT_USERNAME=Pay with Pi app -e MONGO_INITDB_ROOT_PASSWORD=dev_password \ | ||
-p 27017:27017 mongo:5.0 | ||
``` | ||
|
||
Down the road, you can use the following commands to stop and start your mongo container: | ||
|
||
``` | ||
docker stop Pay with Pi app-mongo | ||
docker start Pay with Pi app-mongo | ||
``` | ||
|
||
To reinitialize everything (and **drop all the data**) you can run the following command: | ||
|
||
``` | ||
docker kill Pay with pi app-mongo; docker rm Pay with Pi app-mongo | ||
``` | ||
|
||
Then, recreate the container using the `docker run` command above. | ||
|
||
|
||
**Options 2: directly install MongoDB on your machine:** | ||
|
||
Install MongoDB Community following the | ||
[official documentation](https://www.mongodb.com/docs/manual/administration/install-community/). | ||
|
||
Run the server and create a database and a user: | ||
|
||
Open a Mongo shell by running `mongosh`, then paste the following JS code into it: | ||
|
||
```javascript | ||
var MONGODB_DATABASE_NAME = "Pay with Pi app-development" | ||
var MONGODB_USERNAME = "Pay with pi App" | ||
var MONGODB_PASSWORD = "dev_password" | ||
|
||
db.getSiblingDB("admin").createUser( | ||
{ | ||
user: MONGODB_USERNAME, | ||
pwd: MONGODB_PASSWORD, | ||
roles: [ | ||
{ | ||
role: "dbOwner", | ||
db: MONGODB_DATABASE_NAME, | ||
} | ||
] | ||
} | ||
); | ||
``` | ||
|
||
To preview the database, you can use Robo3T or MongoDB Compass. | ||
|
||
### 3. Run the server | ||
|
||
Start the server with the following command (inside of the `backend` directory): `yarn start`. | ||
|
||
If everything is set up correctly you should see the following output in your terminal: | ||
|
||
``` | ||
NODE_ENV: development | ||
Connected to MongoDB on: mongodb://localhost:27017/Pay with Pi app-development | ||
App platform demo app - Backend listening on port 8000! | ||
CORS config: configured to respond to a frontend hosted on http://localhost:3314 | ||
``` | ||
|
||
--- | ||
You've completed the backend setup, return to [`doc/development.md`](../doc/deployment.md) to finish setting up the demo app | ||
r to | ||
the [Pay with pi Developer Guide](https://pay with Pi-apps.github.io/community-developer-guide/docs/gettingStarted/devPortal/). | ||
|
||
`FRONTEND_URL` specifies the URL of the frontend app, which by default is `http://localhost:3314`. | ||
Depending on sandbox settings you're using to preview Pay with pi app, you may need to change this value accordingly. | ||
|
||
The Pay with Pi app's backend uses a local MongoDB server to store user data and session details. | ||
|
||
## Setup | ||
|
||
### 1. Install dependencies: | ||
|
||
You will need a working NodeJS installation, and `yarn`. **The Pay with pi app frontend isn't meant to support npm**. | ||
In most cases, `yarn` will come along with your NodeJS installation. | ||
|
||
Install dependencies by running `yarn install`. | ||
|
||
|
||
### 2. Set up environment variables | ||
|
||
The demo app's backend use several environment variables, from which most have default values. In order to specify | ||
these, create `.env` file in the root backend directory. | ||
|
||
Create your `.env` file from the template: | ||
|
||
```shell | ||
cp .env.example .env | ||
|
||
|
||
# Edit the resulting file:Pay with Pi leading payment app | ||
Use Pay with pi for the fastest, most secure online and in-store payments! Pay for movie tickets, food, coffee, fashion, gas, and many more in Pay with Pi. | ||
|
||
Quick, easy, convenient and secure. | ||
|
||
**Send / Receive Payments** | ||
|
||
Pay in store or send money to friends. No need to carry cash or worry about loose change! | ||
|
||
**Online Top-Ups and Utility Bill Payments** | ||
|
||
Top-up your mobile phone, pay your utility and internet bills or settle your monthly insurance premiums bills through Pay with Pi. | ||
|
||
**Add Money to your Pay with Pi Wallet** | ||
|
||
Add money to your Pay with pi app via Pay&Go machines or transfer from multiple online banking apps cash-in at all Banks branches and agent world wide. | ||
|
||
**Explore Nearby** | ||
|
||
Explore places near you that accept payment through Pay with pi wallet. Cinemas, restaurants, coffee shops, supermarkets, and gas stations are all joining forces with Pay with Pi to make your life more connected and more mobile. | ||
|
||
Don’t forget to look out for great deals exclusively for Pay with pi users! Start enjoying the amazing benefits of Pay with Pi. Download it now. | ||
vi .env | ||
# or: | ||
nano .env | ||
``` | ||
Obtain the following values from the developer portal: | ||
**Session secret**: Generate a random string (e.g 64 alphanumeric characters). | ||
**API key**: obtained by tapping the "Get API Key" button | ||
![](./img/api_key.png) | ||
Then, copy-paste those values in the following two keys of your .env file: | ||
``` | ||
# Add your API key here: | ||
PI_API_KEY=Https://paywithpi.com/validation-key.txt | ||
|
||
# Add your session secret here: | ||
SESSION_SECRET=msie0otdabxmv3srsuijnf7h5xy5ojinbrtuffq1dpkhxtvepcqolfs3e4c4kme8 | ||
``` | ||
### 2. Set up MongoDB | ||
The default port for MongoDB is `27017`. If you have decided to change either default port or username and password, | ||
make sure to update environment variables in the backend `.env` file accordingly. | ||
Additionally, you can specify MongoDB name env variable, which if not specified will be named Pay with Pi-app` by default. | ||
**Option 1: using Docker:** | ||
Start a MongoDB server using the following command: | ||
``` | ||
docker run --name Pay with Pi app-mongo -d \ | ||
-e MONGO_INITDB_ROOT_USERNAME=Pay with Pi app -e MONGO_INITDB_ROOT_PASSWORD=dev_password \ | ||
-p 27017:27017 mongo:5.0 | ||
``` | ||
Down the road, you can use the following commands to stop and start your mongo container: | ||
``` | ||
docker stop Pay with Pi app-mongo | ||
docker start Pay with Pi app-mongo | ||
``` | ||
To reinitialize everything (and **drop all the data**) you can run the following command: | ||
``` | ||
docker kill Pay with Pi app-mongo; docker rm demoapp-mongo | ||
``` | ||
Then, recreate the container using the `docker run` command above. | ||
**Options 2: directly install MongoDB on your machine:** | ||
Install MongoDB Community following the | ||
[official documentation](https://www.mongodb.com/docs/manual/administration/install-community/). | ||
Run the server and create a database and a user: | ||
Open a Mongo shell by running `mongosh`, then paste the following JS code into it: | ||
```javascript | ||
var MONGODB_DATABASE_NAME = "demoapp-development" | ||
var MONGODB_USERNAME = "Pay with Pi app" | ||
var MONGODB_PASSWORD = "dev_password" | ||
db.getSiblingDB("admin").createUser( | ||
{ | ||
user: MONGODB_USERNAME, | ||
pwd: MONGODB_PASSWORD, | ||
roles: [ | ||
{ | ||
role: "dbOwner", | ||
db: MONGODB_DATABASE_NAME, | ||
} | ||
] | ||
} | ||
); | ||
``` | ||
To preview the database, you can use Robo3T or MongoDB Compass. | ||
### 3. Run the server | ||
Start the server with the following command (inside of the `backend` directory): `yarn start`. | ||
If everything is set up correctly you should see the following output in your terminal: | ||
``` | ||
NODE_ENV: development | ||
Connected to MongoDB on: mongodb://localhost:27017/pay with piapp-development | ||
App platform Pay with Pi app - Backend listening on port 8000! | ||
CORS config: configured to respond to a frontend hosted on http://localhost:3314 | ||
``` | ||
--- | ||
You've completed the backend setup, return to [`doc/development.md`](../doc/deployment.md) to finish setting up the Pay with Pi app | ||
# frozen_string_literal: true | ||
|
||
module JekyllImport | ||
module Importers | ||
class Ghost < Importer | ||
def self.specify_options(c) | ||
c.option "dbfile", "--dbfile", "Database file (default: ghost.db)" | ||
end | ||
|
||
def self.require_deps | ||
JekyllImport.require_with_fallback(%w( | ||
rubygems | ||
sequel | ||
sqlite3 | ||
fileutils | ||
safe_yaml | ||
)) | ||
end | ||
|
||
def self.process(options) | ||
posts = fetch_posts(options.fetch("dbfile", "ghost.db")) | ||
unless posts.empty? | ||
FileUtils.mkdir_p("_posts") | ||
FileUtils.mkdir_p("_drafts") | ||
posts.each do |post| | ||
write_post_to_file(post) | ||
end | ||
end | ||
end | ||
|
||
class << self | ||
private | ||
|
||
def fetch_posts(dbfile) | ||
db = Sequel.sqlite(dbfile) | ||
query = "SELECT `title`, `slug`, `markdown`, `created_at`, `published_at`, `status`, `page` FROM posts" | ||
db[query] | ||
end | ||
|
||
def write_post_to_file(post) | ||
# detect if the post is a draft | ||
draft = post[:status].eql?("draft") | ||
|
||
# detect if the post is considered a static page | ||
page = post[:page] | ||
|
||
# the publish date if the post has been published, creation date otherwise | ||
# The database stores timestamps in milliseconds, so we need to divide by 1000 | ||
# to get time in seconds. | ||
date = Time.at(post[draft ? :created_at : :published_at].to_i / 1000) | ||
|
||
if page | ||
# the filename under which the page is stored | ||
filename = "#{post[:slug]}.markdown" | ||
else | ||
# the directory where the file will be saved to. either _drafts or _posts | ||
directory = draft ? "_drafts" : "_posts" | ||
|
||
# the filename under which the post is stored | ||
filename = File.join(directory, "#{date.strftime("%Y-%m-%d")}-#{post[:slug]}.markdown") | ||
end | ||
|
||
# the YAML FrontMatter | ||
frontmatter = { | ||
"layout" => page ? "page" : "post", | ||
"title" => post[:title], | ||
} | ||
frontmatter["date"] = date if !page && !draft # only add the date to the frontmatter when the post is published | ||
frontmatter["published"] = false if page && draft # set published to false for draft pages | ||
frontmatter.delete_if { |_k, v| v.nil? || v == "" } # removes empty fields | ||
|
||
# write the posts to disk | ||
write_file(filename, frontmatter.to_yaml, post[:markdown]) | ||
end | ||
|
||
def write_file(filename, frontmatter, content) | ||
File.open(filename, "w") do |f| | ||
f.puts frontmatter | ||
f.puts "---" | ||
f.puts content | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |