Skip to content

Commit 2c91612

Browse files
authored
Merge pull request #4 from global-accelerex/update-models-and-code-structure
Update models and code structure
2 parents 6ea9f28 + e1f23bf commit 2c91612

File tree

41 files changed

+711
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+711
-445
lines changed

README.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# ga-android-pos-client
2+
<a href='https://bintray.com/globalaccelerex/globalaccelerex-android/ga-android-pos-client/_latestVersion'><img src='https://api.bintray.com/packages/globalaccelerex/globalaccelerex-android/ga-android-pos-client/images/download.svg'></a>
3+
4+
This library has been designed for easy integration of Global Accelerex android POS services into third party android applications.
5+
6+
# Requirements
7+
8+
Any application making use of this library should run on Global Accelerex android POS devices or on an android device with Global Accelerex Mock base app installed on it.
9+
10+
# Getting Started
11+
12+
## Installation
13+
You do not need to clone this repository or download the files. Just add the following lines to your app's `build.gradle`:
14+
15+
`implementation 'com.globalaccelerex.android:ga-android-pos-client:1.0.0'`
16+
17+
## Setup
18+
19+
After including the library in your application's `build.gradle`, create an instance of `GAClientLib` like this:
20+
21+
```kotlin
22+
val supportLibrary = GAClientLib.Builder()
23+
.setCountryCode(Countries.NIGERIA)
24+
.build()
25+
```
26+
N.B `Countries` should represent the country in which the pos device will be used.
27+
28+
Now that you have an instance of the library in your project, it can be used to make all necessary and supported transactions.
29+
30+
Suggestion: This initialization should be in singleton format because new initializations may carry different configurations.
31+
32+
## Key Exchange
33+
34+
```kotlin
35+
class MainActivity : AppCompatActivity() {
36+
37+
val supportLibrary = GAClientLib.Builder()
38+
.setCountryCode(Countries.NIGERIA)
39+
.build()
40+
41+
override fun onCreate(savedInstanceState: Bundle?) {
42+
super.onCreate(savedInstanceState)
43+
setContentView(R.layout.activity_main)
44+
45+
supportLibrary.makeKeyExchangeRequest(callingComponent = this) // calling component should either be an Activity or a fragment
46+
}
47+
}
48+
```
49+
Note that the function must be called from withing an Activity or a Fragment.
50+
51+
## Parameters Request
52+
To get the details of the POS terminal being used, follow this example:
53+
54+
```kotlin
55+
class MainActivity : AppCompatActivity() {
56+
57+
val supportLibrary = GAClientLib.Builder()
58+
.setCountryCode(Countries.NIGERIA)
59+
.build()
60+
61+
override fun onCreate(savedInstanceState: Bundle?) {
62+
super.onCreate(savedInstanceState)
63+
setContentView(R.layout.activity_main)
64+
65+
supportLibrary.makeParametersRequest(callingComponent = this) // calling component should either be an Activity or a fragment
66+
}
67+
68+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
69+
super.onActivityResult(requestCode, resultCode, data)
70+
if (resultCode == Activity.RESULT_OK) {
71+
if (requestCode == GaResponseKeys.PARAMETERS_REQUEST_CODE) {
72+
val posInformation: PosInformation? = supportLibrary.getPosParametersResponse(data)
73+
}
74+
}
75+
}
76+
}
77+
```
78+
When this request is made, the Pos details are returned as an object of `PosInformation` in the `onActivityResult` of your Activity or Fragment.
79+
80+
# Usage
81+
82+
### Sample Usage
83+
84+
```kotlin
85+
class MainActivity : AppCompatActivity() {
86+
87+
val supportLibrary = GAClientLib.Builder() //Step 1
88+
.setCountryCode(Countries.NIGERIA)
89+
.build()
90+
91+
override fun onCreate(savedInstanceState: Bundle?) {
92+
super.onCreate(savedInstanceState)
93+
setContentView(R.layout.activity_main)
94+
95+
//Assuming Key exchange and Parameters requests have been carried out.
96+
97+
//Step 2
98+
supportLibrary.makeCardPresentTransactionRequest(
99+
amount = 2.0, //step 2.1
100+
transactionType = TransactionType.CP_PURCHASE, //step 2.2
101+
customPrint = true, //step 2.3
102+
callingComponent = this //step 2.4
103+
)
104+
}
105+
106+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
107+
super.onActivityResult(requestCode, resultCode, data)
108+
109+
//Step 3
110+
if (resultCode == Activity.RESULT_OK) {
111+
if (requestCode == GaResponseKeys.CARD_PURCHASE_REQUEST_CODE) { //step 3.1
112+
val cardTransactionResponse: CardTransactionResponse? = supportLibrary.getCardTransactionResponse(data) //step 3.2
113+
// Perform actions with the returned data
114+
}
115+
}
116+
}
117+
}
118+
```
119+
### Step 1 (Setup)
120+
This step has been covered already in the Getting Started section
121+
122+
### Step 2 (Initializing a transaction)
123+
Global accelerex POS may support different transactions such as Card Present Transactions (CP), Card Not Present Transactions (CNP) and Mobile Money Transactions (MM) depending on your location. Select a corresponding function to carry out your preferred transaction.
124+
125+
### Step 2.1 (Setting the amount)
126+
Any amount entered should be in `Double` format.
127+
128+
### Step 2.2 (Setting the transaction type)
129+
A wide variety of transactions types can be made with (CP, CNP AND MM) transactions. `TransactionType` contains an exhaustive list of possible transactions to choose from.
130+
Note:
131+
CP - Card Present
132+
CNP - Card Not Present
133+
MM - Mobile Money
134+
135+
### Step 2.3 (Setting the print mode)
136+
After making a transaction, you can decide to design your own custom receipt format in which case `customPrint` is set to `true`, or use the default print format in which case `customPrint` is set to `false`
137+
138+
### Step 2.4 (Setting the calling component)
139+
As stated earlier, these functions should be called from an `Activity` or a `Fragment`.
140+
The calling component set to `this` refers to the activity or fragment that the functions are called from.
141+
142+
### Step 3 (Retrieving transaction response)
143+
After a transaction is called, the POS device takes over and performs all the neccesary procedures involved in carrying that transaction. When this is done, the transaction details are returned to your application. To retrieve this response, you'll have to listen for it in the activity or fragment's `onActivityResult`.
144+
145+
### Step 3.1 (Listening for your transaction)
146+
For every `TransactionType` value, there is a corresponding `GAResponseKeys` key for it. To listen for the response details compare the requestCode to the matching transaction type.
147+
148+
### Step 3.2 (Retrieving transaction response data)
149+
After listening for a particular transaction, you can get the response by calling a get function related to the transaction that was called from the client library.
150+
151+
152+
153+
All transactions usually follow the same format. However you can take a look at the example project for more details.
154+
155+
156+
# Issues
157+
If you're experiencing technical difficulties or you have suggestions for the library, please raise an issue at:
158+
https://github.com/global-accelerex/ga-android-pos-client/issues
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+

example/src/main/java/com/globalaccelerex/androidposclientlibrary/ActivitySample.kt

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import androidx.appcompat.app.AppCompatActivity
66
import android.os.Bundle
77
import android.util.Log
88
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.GAClientLib
9-
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.baseAppUtils.PosInformation
9+
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.baseAppUtils.PosParameters
1010
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.printing.FontSize
11-
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.printing.TextAlignment
1211
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.printing.ReceiptFormat
12+
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.printing.TextAlignment
1313
import com.globalaccelerex.globalaccelerexandroidposclientlibrary.util.*
1414
import kotlinx.android.synthetic.main.activity_main.*
1515

@@ -21,7 +21,7 @@ import kotlinx.android.synthetic.main.activity_main.*
2121
class ActivitySample : AppCompatActivity() {
2222

2323
private val clientLib = GAClientLib.Builder()
24-
.setCountryCode(Countries.NIGERIA)
24+
.setCountryCode(Countries.KENYA)
2525
.build()
2626

2727
override fun onCreate(savedInstanceState: Bundle?) {
@@ -40,36 +40,30 @@ class ActivitySample : AppCompatActivity() {
4040

4141
//Make Card Present Transactions (CP)
4242
transaction_request.setOnClickListener {
43-
clientLib.makeCardPresentTransactionRequest(
43+
clientLib.cardTransactions.purchase(
44+
amount = 0.01,
45+
callingComponent = this,
46+
customPrint = true
47+
)
48+
}
49+
mobile_money_request.setOnClickListener {
50+
clientLib.mobileMoneyTransaction.purchase(
51+
phoneNumber = "08143051805",
4452
amount = 1.0,
45-
customPrint = true,
46-
transactionType = TransactionType.CP_PURCHASE,
53+
mobileOperator = MobileMoneyOperators.MTN,
4754
callingComponent = this
4855
)
4956
}
50-
51-
//Make Card Not Present Transactions (CNP)
5257
cnp_purchase.setOnClickListener {
53-
clientLib.makeCardNotPresentTransactionRequest(
58+
clientLib.cardNotPresentTransactions.purchase(
5459
cardNumber = "5196010125746208",
5560
cardExpiryDate = "2302",
5661
callingComponent = this,
5762
amount = 1.0,
58-
transactionType = TransactionType.CNP_PURCHASE,
5963
customPrint = false
6064
)
6165
}
6266

63-
//Make Mobile Money Transactions (MM)
64-
mobile_money_request.setOnClickListener {
65-
clientLib.makeMobileMoneyTransactionRequest(
66-
phoneNumber = "08143051805",
67-
amount = 1.0,
68-
mobileOperator = MobileMoneyOperators.MTN,
69-
callingComponent = this
70-
)
71-
}
72-
7367
print_receipt.setOnClickListener {
7468
val receiptFormat = ReceiptFormat(applicationContext)
7569
receiptFormat.addSingleLine("This is a default line")
@@ -80,7 +74,7 @@ class ActivitySample : AppCompatActivity() {
8074
receiptFormat.addSingleLine("Just to confirm!", TextAlignment.ALIGN_RIGHT)
8175
receiptFormat.addLineDivider()
8276
receiptFormat.addKeyValuePair(key = "Header", value = "this value", isMultiLine = false, isBold = true, fontSize = FontSize.LARGE)
83-
clientLib.printReceipt(receipt = receiptFormat.generatePaymentReceipt(), callingComponent = this)
77+
clientLib.printer.printReceipt(receipt = receiptFormat.generatePaymentReceipt(), callingComponent = this)
8478
}
8579
}
8680

@@ -90,26 +84,24 @@ class ActivitySample : AppCompatActivity() {
9084
//Note that the Request key will always match the transaction type with "REQUEST_CODE" appended to it.
9185

9286
if (resultCode == Activity.RESULT_OK) {
93-
if (requestCode == GaRequestKeys.KEY_EXCHANGE_REQUEST_CODE) {
94-
Log.e("Key exchange", "Key exchange successful!")
95-
}
9687
if (requestCode == GaRequestKeys.PARAMETERS_REQUEST_CODE) {
97-
val posInfo: PosInformation? = clientLib.getPosParametersResponse(data)
88+
val posInfo: PosParameters? = clientLib.getPosParametersResponse(data)
89+
Log.e("PosInfo", "$posInfo")
90+
}
91+
if (requestCode == GaRequestKeys.CNP_PURCHASE_REQUEST_CODE) {
92+
val posInfo: PosParameters? = clientLib.getPosParametersResponse(data)
9893
Log.e("PosInfo", "$posInfo")
9994
}
95+
if (requestCode == GaRequestKeys.KEY_EXCHANGE_REQUEST_CODE) {
96+
Log.e("Key exchange", "Key exchange successful!")
97+
}
10098
if (requestCode == GaRequestKeys.CP_PURCHASE_REQUEST_CODE) {
10199
val cardResponseDetails = clientLib.getCardTransactionResponse(data)
102100
Log.e("Purchase response", "$cardResponseDetails")
103101
}
104-
if (requestCode == GaRequestKeys.CNP_PURCHASE_REQUEST_CODE) {
105-
// CNP Response types haven't been defined yet
106-
}
107102
if (requestCode == GaRequestKeys.MOBILE_MONEY_PURCHASE_REQUEST_CODE) {
108-
val mobileMoneyTransactionResponse = clientLib.getMobileMoneyTransactionResponse(data)
109-
Log.e("Purchase response", "$mobileMoneyTransactionResponse")
110-
}
111-
if (requestCode == GaRequestKeys.PRINTING_REQUEST_CODE) {
112-
Log.e("Printing response", "Successful!")
103+
val cardResponseDetails = clientLib.getMobileMoneyTransactionResponse(data)
104+
Log.e("Purchase response", "$cardResponseDetails")
113105
}
114106
}
115107
}

example/src/main/java/com/globalaccelerex/androidposclientlibrary/PrintingSample.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

javasampe/src/main/java/com/example/javasampe/MainActivity.java renamed to javasample/src/main/java/com/example/javasampe/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void onClick(View v) {
3232
format.addSingleLine("This is a java test line", TextAlignment.ALIGN_LEFT, null , false);
3333
format.addSingleLine("Just to confirm!!", TextAlignment.ALIGN_CENTER, null, false);
3434
Receipt receipt = format.generatePaymentReceipt();
35-
clientLib.printReceipt(receipt, MainActivity.this);
35+
clientLib.getPrinter().printReceipt(receipt, MainActivity.this);
3636
}
3737
});
3838

0 commit comments

Comments
 (0)