Skip to content

Commit 6369ed5

Browse files
committed
update to library
1 parent 11818b1 commit 6369ed5

18 files changed

+374
-369
lines changed

README.md

+101-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,101 @@
1-
# momoapi-java
2-
MTN MoMo API Client for Java
1+
# MomoAPI Java Bindings
2+
3+
You can sign up for a MOMOAPI account at https://https://momodeveloper.mtn.com
4+
5+
## Requirements
6+
7+
Java 1.8 or later.
8+
9+
## Installation
10+
11+
### Maven users
12+
13+
Add this dependency to your project's POM:
14+
15+
```xml
16+
<dependency>
17+
<groupId>ug.sparkpl</groupId>
18+
<artifactId>mtnmomo-java</artifactId>
19+
<version>1.0.0</version>
20+
</dependency>
21+
```
22+
23+
### Gradle users
24+
25+
Add this dependency to your project's build file:
26+
27+
```groovy
28+
compile "ug.sparkpl:mtnmomo-java:1.0.0"
29+
```
30+
31+
32+
## Usage
33+
34+
MomoExample.java
35+
36+
```java
37+
import java.util.HashMap;
38+
import java.util.Map;
39+
40+
import ug.sparkpl.momoapi.network.RequestOptions;
41+
import ug.sparkpl.momoapi.network.collections.CollectionsClient;
42+
43+
44+
public class MomoExample {
45+
46+
public static void main(String[] args) {
47+
RequestOptions opts = RequestOptions.builder()
48+
.setCollectionApiSecret("MY_SECRET_API_KEY")
49+
.setCollectionPrimaryKey("MY_SECRET_SUBSCRIPTION_KEY")
50+
.setCollectionUserId("MYSECRET_USER_ID").build();
51+
52+
53+
HashMap<String, String> collMap = new HashMap<String, String>();
54+
collMap.put("amount", "100");
55+
collMap.put("mobile", "1234");
56+
collMap.put("externalId", "ext123");
57+
collMap.put("payeeNote", "testNote");
58+
collMap.put("payerMessage", "testMessage");
59+
60+
CollectionsClient client = new CollectionsClient(opts);
61+
62+
try {
63+
String transactionRef = client.requestToPay(collMap);
64+
System.out.println(transactionRef);
65+
} catch (MomoApiException e) {
66+
e.printStackTrace();
67+
}
68+
}
69+
}
70+
```
71+
72+
73+
### Per-request Configuration
74+
75+
By default, you can set
76+
77+
78+
79+
``` java
80+
81+
```
82+
83+
84+
85+
## Development
86+
87+
You must have Gradle installed. To run the tests:
88+
89+
./gradlew test
90+
91+
92+
The library uses [Project Lombok][lombok]. While it is not a requirement, you might want to install a [plugin][lombok-plugins] for your favorite IDE to facilitate development.
93+
94+
[connect]: https://stripe.com/connect
95+
[lombok]: https://projectlombok.org
96+
[lombok-plugins]: https://projectlombok.org/setup/overview
97+
[stripe-mock]: https://github.com/stripe/stripe-mock
98+
99+
<!--
100+
# vim: set tw=79:
101+
-->

build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ repositories {
4040

4141
apply plugin: 'io.codearte.nexus-staging'
4242

43+
apply plugin: 'maven-publish'
44+
apply plugin: 'signing'
45+
4346

4447
sourceCompatibility = 1.8
4548
targetCompatibility = 1.8
@@ -92,6 +95,7 @@ dependencies {
9295
testImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
9396
testCompile("org.apache.jclouds:jclouds-core:2.0.2:tests")
9497
testCompile("org.apache.jclouds.driver:jclouds-slf4j:2.0.2")
98+
testCompile('org.testng:testng:6.11')
9599
testCompile('org.assertj:assertj-core:3.8.0')
96100
compile "org.apache.jclouds:jclouds-core:2.0.2"
97101
}

deploy.gradle

+108-96
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,138 @@
1-
/*
2-
* Based on the example at Chris Banes's repository that allows signing
3-
* without manually creating a maven file.
4-
*
5-
* The original can be found at
6-
* https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle
7-
*/
8-
9-
apply plugin: 'maven'
1+
apply plugin: 'java'
2+
apply plugin: 'maven-publish'
103
apply plugin: 'signing'
11-
apply plugin: 'io.codearte.nexus-staging'
124

13-
nexusStaging {
14-
packageGroup = GROUP
5+
repositories {
6+
mavenCentral()
157
}
168

17-
def isReleaseBuild() {
18-
return VERSION_NAME.contains("SNAPSHOT") == false
19-
}
209

21-
def getReleaseRepositoryUrl() {
22-
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
23-
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
10+
task sourceJar(type: Jar) {
11+
classifier "sources"
12+
from sourceSets.main.allJava
2413
}
2514

26-
def getSnapshotRepositoryUrl() {
27-
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
28-
: "https://oss.sonatype.org/content/repositories/snapshots/"
15+
task javadocJar(type: Jar, dependsOn: javadoc) {
16+
classifier "javadoc"
17+
from javadoc.destinationDir
2918
}
3019

31-
def getRepositoryUsername() {
32-
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
20+
artifacts {
21+
archives jar
22+
archives sourceJar
23+
archives javadocJar
3324
}
3425

35-
def getRepositoryPassword() {
36-
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
26+
signing {
27+
sign configurations.archives
3728
}
3829

39-
afterEvaluate { project ->
40-
uploadArchives {
41-
repositories {
42-
mavenDeployer {
43-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
44-
45-
pom.groupId = GROUP
46-
pom.artifactId = POM_ARTIFACT_ID
47-
pom.version = VERSION_NAME
48-
49-
repository(url: getReleaseRepositoryUrl()) {
50-
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
51-
}
52-
53-
snapshotRepository(url: getSnapshotRepositoryUrl()) {
54-
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
30+
publishing {
31+
publications {
32+
mavenJava(MavenPublication) {
33+
customizePom(pom)
34+
groupId 'ug.sparkpl'
35+
artifactId 'mtnmomo-java'
36+
version '1.0.0'
37+
38+
from components.java
39+
40+
// create the sign pom artifact
41+
pom.withXml {
42+
def pomFile = file("${project.buildDir}/generated-pom.xml")
43+
writeTo(pomFile)
44+
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
45+
artifact(pomAscFile) {
46+
classifier = null
47+
extension = 'pom.asc'
5548
}
49+
}
5650

57-
pom.project {
58-
name POM_NAME
59-
description POM_DESCRIPTION
60-
url POM_URL
61-
packaging POM_PACKAGING
62-
63-
scm {
64-
url POM_SCM_URL
65-
connection POM_SCM_CONNECTION
66-
developerConnection POM_SCM_DEV_CONNECTION
67-
}
68-
69-
licenses {
70-
license {
71-
name POM_LICENCE_NAME
72-
url POM_LICENCE_URL
73-
distribution POM_LICENCE_DIST
74-
}
75-
}
76-
77-
developers {
78-
developer {
79-
id POM_DEVELOPER_ID
80-
name POM_DEVELOPER_NAME
81-
email POM_DEVELOPER_EMAIL
82-
}
83-
}
51+
artifact(sourceJar) {
52+
classifier = 'sources'
53+
}
54+
artifact(javadocJar) {
55+
classifier = 'javadoc'
56+
}
8457

85-
organization {
86-
name POM_DEVELOPER_NAME
87-
url POM_ORGANIZATION_URL
58+
// create the signed artifacts
59+
project.tasks.signArchives.signatureFiles.each {
60+
artifact(it) {
61+
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
62+
if (matcher.find()) {
63+
classifier = matcher.group(1)
64+
} else {
65+
classifier = null
8866
}
67+
extension = 'jar.asc'
8968
}
9069
}
9170
}
9271
}
93-
94-
signing {
95-
required { isReleaseBuild() &&
96-
(gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))}
97-
useGpgCmd()
98-
sign configurations.archives
72+
repositories {
73+
maven {
74+
url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
75+
credentials {
76+
username sonatypeUsername
77+
password sonatypePassword
78+
}
79+
}
9980
}
81+
}
10082

101-
tasks.withType(Sign) {
102-
onlyIf { isReleaseBuild() && project.hasProperty('signing.gnupg.keyName') }
103-
}
83+
def customizePom(pom) {
84+
pom.withXml {
85+
def root = asNode()
10486

105-
task makeJavadocs(type: Javadoc, dependsOn: delombok) {
106-
source = delombok.outputDir
107-
classpath = configurations.compile + configurations.annotationProcessor
108-
failOnError = true
109-
}
87+
// eliminate test-scoped dependencies (no need in maven central POMs)
88+
root.dependencies.removeAll { dep ->
89+
dep.scope == "test"
90+
}
11091

111-
task makeJavadocsJar(type: Jar, dependsOn: makeJavadocs) {
112-
classifier = 'javadoc'
113-
from makeJavadocs.destinationDir
114-
}
92+
// add all items necessary for maven central publication
93+
root.children().last() + {
94+
resolveStrategy = Closure.DELEGATE_FIRST
11595

116-
task sourcesJar(type: Jar, dependsOn: delombok) {
117-
classifier = 'sources'
118-
from delombok.outputDir
96+
description 'MTN MOMO Java Bindings'
97+
name 'https://momodeveloper.mtn.com/ Java'
98+
url 'https://github.com/sparkplug/momoapi-java'
99+
organization {
100+
name 'ug.sparkpl'
101+
url 'https://sparkpl.ug'
102+
}
103+
issueManagement {
104+
system 'GitHub'
105+
url 'https://github.com/sparkplug/momoapi-java/issues'
106+
}
107+
licenses {
108+
license {
109+
name 'The MIT License'
110+
url 'https://raw.githubusercontent.com/sparkplug/momoapi-java/master/LICENSE'
111+
distribution 'repo'
112+
}
113+
}
114+
scm {
115+
url 'https://github.com/sparkplug/momoapi-java'
116+
connection 'scm:git@github.com/sparkplug/momoapi-java.git'
117+
developerConnection 'scm:git:ssh://git@github.com:sparkplug/momoapi-java.git'
118+
}
119+
developers {
120+
developer {
121+
name 'Sparkplug'
122+
}
123+
}
124+
}
119125
}
126+
}
120127

121-
artifacts {
122-
archives jar
123-
archives sourcesJar
124-
archives makeJavadocsJar
128+
model {
129+
tasks.generatePomFileForMavenJavaPublication {
130+
destination = file("$buildDir/generated-pom.xml")
131+
}
132+
tasks.publishMavenJavaPublicationToMavenLocal {
133+
dependsOn project.tasks.signArchives
134+
}
135+
tasks.publishMavenJavaPublicationToMavenRepository {
136+
dependsOn project.tasks.signArchives
125137
}
126138
}

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
* in the user guide at https://docs.gradle.org/5.1/userguide/multi_project_builds.html
88
*/
99

10-
rootProject.name = 'momoapi-java'
10+
rootProject.name = 'mtnmomo-java'

0 commit comments

Comments
 (0)