Skip to content

Commit

Permalink
Moved everything into the common repository
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiQvik committed Sep 24, 2019
0 parents commit e160a20
Show file tree
Hide file tree
Showing 53 changed files with 3,264 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## The MIT License (MIT)

#### Copyright (c) 2019 Swedbank

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# PayEx Mobile SDK Merchant Backend Guide

This repository holds information about how to implement a Merchant Backend application to act as an endpoint between a merchant's mobile application and the PayEx APIs.

It features a step by step guide on what the merchant backend MUST do and also offers insights on what the merchant backend SHOULD do to complete its function in an efficient and secure manner.

Implementation examples in some popular programming languages are included.

## Implementation Guide

TODO

## Resources

Here are listed the essential resources needed for the implementation work:

* [PayEx eCommerce API Technical Reference](https://developer.payex.com/xwiki/wiki/developer/view/Main/ecommerce/technical-reference/)

## Examples

See the subdirectory `examples/` for implementation examples in some popular programming languages. Currently examples exist for:

* Java
* Node.js



4 changes: 4 additions & 0 deletions examples/java/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.gcloudignore
README.md
src
17 changes: 17 additions & 0 deletions examples/java/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Include build/libs directory in Cloud build
#!build/libs/

build/classes
build/generated
build/reports
build/resources
build/test-results
build/tmp

# Exclude everything else pretty much
src
README.md
bin
gradle*
settings.gradle

33 changes: 33 additions & 0 deletions examples/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
bin
12 changes: 12 additions & 0 deletions examples/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM openjdk:8-jdk-alpine

# Create app directory
WORKDIR /usr/src/app

# Copy our input jar file to fixed app.jar
COPY build/libs/merchant-sample-java-1.0.0.jar app.jar

# Expose a TCP port for incoming traffic
EXPOSE 8080

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
101 changes: 101 additions & 0 deletions examples/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Sample Merchant Backend implementation, Java

This is a sample implementation of a PayEx merchant backend implemented in Java.

The core technology stack used is Java8, Gradle, Spring Boot.

The application implemeents the [PayEx Mobile Backend API](TODO) specification and further calls the PayEx eCommerce platform APIs ('PSP') to perform the authentication and payment functions. The server code ships with the secrets required to talk to the PSP. It also presents a naive in-memory data storage solution for storing the merchant data.

## Configuration file

The application needs to ship some secrets. It does this naively via `src/main/resources/application.properties` file. This file is not included in the Git repository; instead, there is `src/main/resources/example.application.properties` which you can use as a template for your `application.properties` file. Just replace all the values in `<brackets>` with proper values and you are set.

## Data format

The data format for the `merchantData` parameter in the `POST /paymentorders` API call is as follows:

```json
{
"basketId": "123",
"currency": "SEK",
"languageCode": "sv-SE",
"items": [
{
"itemId": "1",
"quantity": 1,
"price": 1200,
"vat": 300
},
{
"itemId": "2",
"quantity": 2,
"price": 400,
"vat": 75
}
]
}
```

The monetary amounts (`price` and `vat`) are represented as multiplies of the lowest denominating unit in the defined currency, eg. for `SEK` currency a value of `100` would mean 1 SEK (100 öre). Both the `price` and `vat` represent the complete sum of purchasing `quantity` x `itemId`. Find out the unit price by dividing by `quantity`.

## Running locally

Run the application locally using the following command:

```sh
./gradlew bootRun
```

## Docker

This application has been packaged as a Docker container.

### Testing the image locally

Build the application into a .jar:

```sh
./gradlew bootJar
```

Build the Docker image:

```sh
docker build --build-arg jarfile=build/libs/merchant-sample-java-1.0.0.jar -t payex/merchant-sample-java .
```

Run the Docker image:

```sh
docker run -p 8080:8080 -d payex/merchant-sample-java
```

Now the merchant API is running at `http://localhost:8080`.

### Deploying the Docker container

Here are some examples for deploying the application's Docker container into cloud environments.

#### Google Cloud Run

The simplest way to run a Docker container in a cloud is to use [Google Cloud Run](https://cloud.google.com/run/).

Replace `<PROJECT-ID>` with your GCP project ID.

Build your image using Cloud Build:

```
gcloud builds submit --project=<PROJECT-ID> --tag gcr.io/<PROJECT-ID>/payex/merchant-sample-java
```

Deploy to Cloud Run:

```
gcloud beta run deploy --project=<PROJECT-ID> --image gcr.io/<PROJECT-ID>/payex/merchant-sample-java --platform managed
```

See the output of this command to find out the public endpoint address.

## References

* [PayEx eCommerce platform API](https://developer.payex.com/xwiki/wiki/developer/view/Main/ecommerce/technical-reference/)
20 changes: 20 additions & 0 deletions examples/java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id 'org.springframework.boot' version '2.1.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}

group = 'com.payex.samples.merchant'
version = '1.0.0'
sourceCompatibility = '1.8'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
}
Binary file added examples/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit e160a20

Please sign in to comment.