Skip to content

Commit 63774fd

Browse files
author
Javier Garcia
committed
Initial Commit
0 parents  commit 63774fd

8 files changed

Lines changed: 612 additions & 0 deletions

File tree

.gitignore

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
2+
# Created by https://www.gitignore.io/api/java,maven,eclipse
3+
4+
### Eclipse ###
5+
6+
.metadata
7+
bin/
8+
tmp/
9+
*.tmp
10+
*.bak
11+
*.swp
12+
*~.nib
13+
local.properties
14+
.settings/
15+
.loadpath
16+
.recommenders
17+
.classpath
18+
.project
19+
20+
# External tool builders
21+
.externalToolBuilders/
22+
23+
# Locally stored "Eclipse launch configurations"
24+
*.launch
25+
26+
# PyDev specific (Python IDE for Eclipse)
27+
*.pydevproject
28+
29+
# CDT-specific (C/C++ Development Tooling)
30+
.cproject
31+
32+
# CDT- autotools
33+
.autotools
34+
35+
# Java annotation processor (APT)
36+
.factorypath
37+
38+
# PDT-specific (PHP Development Tools)
39+
.buildpath
40+
41+
# sbteclipse plugin
42+
.target
43+
44+
# Tern plugin
45+
.tern-project
46+
47+
# TeXlipse plugin
48+
.texlipse
49+
50+
# STS (Spring Tool Suite)
51+
.springBeans
52+
53+
# Code Recommenders
54+
.recommenders/
55+
56+
# Annotation Processing
57+
.apt_generated/
58+
59+
# Scala IDE specific (Scala & Java development for Eclipse)
60+
.cache-main
61+
.scala_dependencies
62+
.worksheet
63+
64+
### Eclipse Patch ###
65+
# Eclipse Core
66+
.project
67+
68+
# JDT-specific (Eclipse Java Development Tools)
69+
.classpath
70+
71+
# Annotation Processing
72+
.apt_generated
73+
74+
### Java ###
75+
# Compiled class file
76+
*.class
77+
78+
# Log file
79+
*.log
80+
81+
# BlueJ files
82+
*.ctxt
83+
84+
# Mobile Tools for Java (J2ME)
85+
.mtj.tmp/
86+
87+
# Package Files #
88+
*.jar
89+
*.war
90+
*.nar
91+
*.ear
92+
*.zip
93+
*.tar.gz
94+
*.rar
95+
96+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
97+
hs_err_pid*
98+
99+
### Maven ###
100+
target/
101+
pom.xml.tag
102+
pom.xml.releaseBackup
103+
pom.xml.versionsBackup
104+
pom.xml.next
105+
release.properties
106+
dependency-reduced-pom.xml
107+
buildNumber.properties
108+
.mvn/timing.properties
109+
.mvn/wrapper/maven-wrapper.jar
110+
111+
112+
# End of https://www.gitignore.io/api/java,maven,eclipse
113+
114+
/certs/
115+
*.p12
116+
*.cer
117+
*.zip
118+
119+
120+
.idea/

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
This repository shows how to implement a merchant server in order to successfully perform a [GooglePay](https://pay.google.com) payment using using our web-services. For more information about the web-services, please refer to the official documentation.
2+
3+
* This example uses [Spark](http://sparkjava.com/) framework that allows to create a simple server easily
4+
* In order to call the Web Services SOAP v5 to perform the payment, this example uses the existing [Web Services SDK](https://github.com/payzen/payzen-webservices-v5-sdk-java). Feel free to use your own solution based in JAX-WS, [CXF](https://github.com/apache/cxf), [Axis](https://github.com/apache/axis2-java), etc.
5+
6+
## Table of contents
7+
8+
* [Getting started](#getting-started)
9+
* [What's included](#whats-included)
10+
* [Configuration](#configuration)
11+
12+
## Getting started
13+
14+
* Clone the repo: `git clone https://github.com/lyra/googlepay-payment-sparkjava-integration-sample.git`.
15+
* Set your shop data in the _app-configuration.properties_ file as described in [configuration instructions](#configuration).
16+
* Run `mvn package`, to build jar executable
17+
* Run `java -jar inApp-server-1.0-jar-with-dependencies.jar`
18+
19+
The application should have and output like this:
20+
21+
INFO org.eclipse.jetty.util.log - Logging initialized @698ms
22+
INFO spark.embeddedserver.jetty.EmbeddedJettyServer - == Spark has ignited ...
23+
INFO spark.embeddedserver.jetty.EmbeddedJettyServer - >> Listening on 0.0.0.0:9090
24+
INFO org.eclipse.jetty.server.Server - jetty-9.3.6.v20151106
25+
INFO org.eclipse.jetty.server.ServerConnector - Started ServerConnector@30946381{HTTP/1.1,[http/1.1]}{0.0.0.0:5678}
26+
INFO org.eclipse.jetty.server.Server - Started @1065ms
27+
28+
By default the application run on 9090 port. See [configuration instructions](#configuration) if you want to change this value.
29+
30+
## What's included
31+
32+
```
33+
|---com.lyra
34+
| |-- Server.java
35+
| |-- ServerConfiguration.java
36+
|---com.lyra.googlepay
37+
| |-- GooglePayController.java
38+
| |-- GooglePayService.java
39+
|---resources
40+
| |-- app-configuration.properties
41+
```
42+
43+
## Configuration
44+
45+
Server port can be easily configured via [Spark](http://sparkjava.com/) modifying the _Server.java_ file.
46+
47+
```java
48+
port(9090);
49+
```
50+
51+
All the shop configuration data must be set in the _app-configuration.properties_ file:
52+
53+
```
54+
#
55+
# EDIT YOUR MERCHANT SETTINGS HERE
56+
#
57+
58+
merchantSiteId=#Your merchant Id here
59+
merchantTestKey=#Your test certificate here
60+
merchantProdKey=#Your production certificate here
61+
62+
#
63+
# URL of your payment platform. See official documentation for further details.
64+
#
65+
paymentPlatformUrl=#Your payment platform URL here
66+
```

pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.lyra</groupId>
5+
<artifactId>inApp-server</artifactId>
6+
<version>1.0</version>
7+
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<artifactId>maven-compiler-plugin</artifactId>
12+
<version>3.1</version>
13+
<configuration>
14+
<source>1.8</source>
15+
<target>1.8</target>
16+
</configuration>
17+
</plugin>
18+
<plugin>
19+
<artifactId>maven-assembly-plugin</artifactId>
20+
<executions>
21+
<execution>
22+
<phase>package</phase>
23+
<goals>
24+
<goal>single</goal>
25+
</goals>
26+
</execution>
27+
</executions>
28+
<configuration>
29+
<descriptorRefs>
30+
<!-- This tells Maven to include all dependencies -->
31+
<descriptorRef>jar-with-dependencies</descriptorRef>
32+
</descriptorRefs>
33+
<archive>
34+
<manifest>
35+
<mainClass>com.lyra.Server</mainClass>
36+
</manifest>
37+
</archive>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-simple</artifactId>
47+
<version>1.7.26</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.sparkjava</groupId>
51+
<artifactId>spark-core</artifactId>
52+
<version>2.9.0</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>eu.payzen.sdk</groupId>
56+
<artifactId>payzen-ws-sdk</artifactId>
57+
<version>1.3</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>com.google.code.gson</groupId>
61+
<artifactId>gson</artifactId>
62+
<version>2.8.5</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.apache.commons</groupId>
66+
<artifactId>commons-lang3</artifactId>
67+
<version>3.9</version>
68+
</dependency>
69+
</dependencies>
70+
71+
<properties>
72+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
73+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
74+
</properties>
75+
</project>

src/main/java/com/lyra/Server.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lyra;
2+
3+
import com.lyra.googlepay.GooglePayController;
4+
5+
import static spark.Spark.port;
6+
import static spark.Spark.post;
7+
8+
/**
9+
* This is the entry point for Spark Java Server. <p></p>
10+
*
11+
* It defines the port and the route for the GooglePay payment
12+
*
13+
* @author Lyra Network
14+
*/
15+
public class Server {
16+
public static void main(String[] args) {
17+
// Configure Spark
18+
port(9090);
19+
20+
//Routes
21+
post("/", GooglePayController.createPayment);
22+
}
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.lyra;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Properties;
8+
9+
/**
10+
* This class encapsulates all configuration data needed to perform payments calling payment platform.<p></p>
11+
* <p>
12+
* It reads the configuration from app-configuration.properties file. Please make sure that you have set all the configuration
13+
* parameters before running the server.
14+
*
15+
* @author Lyra Network
16+
*/
17+
public class ServerConfiguration {
18+
private static Map<String, String> appConfiguration = new HashMap<>();
19+
private static String CONF_FILENAME = "app-configuration.properties";
20+
21+
//No public constructor
22+
private ServerConfiguration() {
23+
}
24+
25+
/**
26+
* This method calculates the configuration data needed to connect to payment platform.<p></p>
27+
* It sets also the mode of payment (TEST or PRODUCTION)
28+
*
29+
* @param mode TEST or PRODUCTION
30+
* @return a {@link Map} object that contains the configuration to use
31+
*/
32+
public static Map<String, String> getConfiguration(String mode) {
33+
34+
if (appConfiguration.isEmpty()) {
35+
Properties configurationProperties = new Properties();
36+
37+
try (InputStream is = ServerConfiguration.class.getClassLoader()
38+
.getResourceAsStream(CONF_FILENAME)) {
39+
40+
if (is != null) {
41+
configurationProperties.load(is);
42+
} else {
43+
throw new IOException("Could not read configuration file: " + CONF_FILENAME);
44+
}
45+
46+
appConfiguration = (Map) configurationProperties;
47+
} catch (IOException e) {
48+
//This will be captured and handled by controller
49+
throw new RuntimeException("Cannot read configuration data. Please, provide a valid app.configuration file", e);
50+
}
51+
52+
appConfiguration.put("mode", mode);
53+
if ("PRODUCTION".equals(mode)) {
54+
appConfiguration.put("usedMerchantKey", appConfiguration.get("merchantProdKey"));
55+
} else {
56+
appConfiguration.put("usedMerchantKey", appConfiguration.get("merchantTestKey"));
57+
}
58+
}
59+
60+
return appConfiguration;
61+
}
62+
}

0 commit comments

Comments
 (0)