Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV] Added OAuth call to MPesa and Account Balance Query #85

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Put a settings.xml into your ~/.m2 directory with the following content:
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots><enabled>false</enabled></snapshots>
</repository>
Expand All @@ -39,7 +39,7 @@ Put a settings.xml into your ~/.m2 directory with the following content:
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots><enabled>false</enabled></snapshots>
<releases><updatePolicy>never</updatePolicy></releases>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.openmf.psp.mpesa.config;

import javax.annotation.PostConstruct;
import org.openmf.psp.config.ApplicationSettings;
import org.openmf.psp.config.Binding;
import org.openmf.psp.config.Header;
import org.openmf.psp.config.HubSettings;
import org.openmf.psp.config.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("mpesa-settings")
public class MPesaSettings extends ApplicationSettings<MPesaSettings.MPesaHeader, MPesaSettings.MPesaOperation, MPesaSettings.MPesaBinding> {

private String consumerKey;
private String consumerSecret;

HubSettings hubSettings;

MPesaSettings() {

}

@Autowired
public MPesaSettings(HubSettings hubSettings) {
this.hubSettings = hubSettings;
}

@PostConstruct
public void postConstruct() {
postConstruct(hubSettings);
}

public String getConsumerKey() {
return consumerKey;
}

public void setConsumerKey(String consumerKey) {
this.consumerKey = consumerKey;
}

public String getConsumerSecret() {
return consumerSecret;
}

public void setConsumerSecret(String consumerSecret) {
this.consumerSecret = consumerSecret;
}

public enum MPesaHeader implements Header {
TENANT("tenant"); // Arbitrary variable, need to confirm

private final String configName;

MPesaHeader(String configName) {
this.configName = configName;
}

@Override
public String getConfigName() {
return configName;
}
}

public enum MPesaOperation implements Operation {
OAUTH("oauth-token"),
BALANCE("account-balance");

private final String configName;

MPesaOperation(String configName) {
this.configName = configName;
}

@Override
public String getConfigName() {
return configName;
}
}

public enum MPesaBinding implements Binding {
BALANCE("balance"); // Arbitrary variable, need to confirm

private final String configName;

MPesaBinding(String configName) {
this.configName = configName;
}

@Override
public String getConfigName() {
return configName;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openmf.psp.mpesa.dto;

public class AccessTokenResponse {

String access_token;
String expires_in;

public String getAccess_token() {
return access_token;
}

public void setAccess_token(String access_token) {
this.access_token = access_token;
}

public String getExpires_in() {
return expires_in;
}

public void setExpires_in(String expires_in) {
this.expires_in = expires_in;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.openmf.psp.mpesa.dto;

import java.util.Arrays;

public class BalanceRequest {

String CommandID;
String PartyA;
String IdentifierType;
String Remarks;
String Initiator;
String SecurityCredential;
String QueueTimeOutURL;
String ResultURL;

public String getCommandID() {
return CommandID;
}

public void setCommandID(String commandID) {
CommandID = commandID;
}

public String getPartyA() {
return PartyA;
}

public void setPartyA(String partyA) {
PartyA = partyA;
}

public String getIdentifierType() {
return IdentifierType;
}

public void setIdentifierType(String identifierType) {
IdentifierType = identifierType;
}

public String getRemarks() {
return Remarks;
}

public void setRemarks(String remarks) {
Remarks = remarks;
}

public String getInitiator() {
return Initiator;
}

public void setInitiator(String initiator) {
Initiator = initiator;
}

public String getSecurityCredential() {
return SecurityCredential;
}

public void setSecurityCredentials(String securityCredential) {
SecurityCredential = securityCredential;
}

public String getQueueTimeOutURL() {
return QueueTimeOutURL;
}

public void setQueueTimeOutURL(String queueTimeOutURL) {
QueueTimeOutURL = queueTimeOutURL;
}

public String getResultURL() {
return ResultURL;
}

public void setResultURL(String resultURL) {
ResultURL = resultURL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.openmf.psp.mpesa.dto;

public class ReferenceData {

public ReferenceItem referenceItem;

public ReferenceItem getReferenceItem() {
return referenceItem;
}

public void setReferenceItem(ReferenceItem referenceItem) {
this.referenceItem = referenceItem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openmf.psp.mpesa.dto;

public class ReferenceItem {

public String key;
public String value;

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.openmf.psp.mpesa.dto;

public class Result {

public String conversationID;
public String originatorConversationID;
public ReferenceData referenceData;
public Integer resultCode;
public String resultDesc;
public ResultParameters resultParameters;
public Integer resultType;
public String transactionID;

public String getConversationID() {
return conversationID;
}

public void setConversationID(String conversationID) {
this.conversationID = conversationID;
}

public String getOriginatorConversationID() {
return originatorConversationID;
}

public void setOriginatorConversationID(String originatorConversationID) {
this.originatorConversationID = originatorConversationID;
}

public ReferenceData getReferenceData() {
return referenceData;
}

public void setReferenceData(ReferenceData referenceData) {
this.referenceData = referenceData;
}

public Integer getResultCode() {
return resultCode;
}

public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}

public String getResultDesc() {
return resultDesc;
}

public void setResultDesc(String resultDesc) {
this.resultDesc = resultDesc;
}

public ResultParameters getResultParameters() {
return resultParameters;
}

public void setResultParameters(ResultParameters resultParameters) {
this.resultParameters = resultParameters;
}

public Integer getResultType() {
return resultType;
}

public void setResultType(Integer resultType) {
this.resultType = resultType;
}

public String getTransactionID() {
return transactionID;
}

public void setTransactionID(String transactionID) {
this.transactionID = transactionID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openmf.psp.mpesa.dto;

public class ResultParameter {

public String key;
public Integer value;

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public Integer getValue() {
return value;
}

public void setValue(Integer value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.openmf.psp.mpesa.dto;

import java.util.List;

public class ResultParameters {

List<ResultParameter> resultParameter = null;

public List<ResultParameter> getResultParameter() {
return resultParameter;
}

public void setResultParameter(List<ResultParameter> resultParameter) {
this.resultParameter = resultParameter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.openmf.psp.mpesa.dto;

public class TransactionResponse {

public Result result;

public Result getResult() {
return result;
}

public void setResult(Result result) {
this.result = result;
}
}
Loading