Skip to content

Commit 7826512

Browse files
committed
Refactored Initialize function to provide amount and currency asyn
1 parent 3d38ace commit 7826512

File tree

15 files changed

+200
-210
lines changed

15 files changed

+200
-210
lines changed

README.md

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,10 @@ override fun onCreate(savedInstanceState: Bundle?) {
6060

6161

6262
// initialize Thepeer SDK
63-
val thepeer = Thepeer.Builder(
64-
activity = this,
65-
amount = BigDecimal(10000.00),
66-
currency = "NGN",
67-
userReference = getString(R.string.user_reference),
68-
resultListener = resultListener
69-
).setMeta(mapOf("remark" to "Enjoy")).build()
70-
63+
val thepeer = Thepeer.Initiate(
64+
activity = this,
65+
userReference = "YOUR _USER_REFERENCE",
66+
resultListener = resultListener).build()
7167
}
7268

7369
```
@@ -83,21 +79,29 @@ JAVA
8379
setContentView(R.layout.activity_main);
8480

8581
// initialize Thepeer SDK
86-
Thepeer thepeer =new Thepeer.Builder(
87-
this,
88-
new BigDecimal("1000.00"),
89-
"NGN",
82+
Thepeer thepeer = new Thepeer.Initiate(
9083
getResources().getString(R.string.user_reference),
84+
activity,
9185
new ThepeerResultListener())
9286

9387
}
88+
9489
```
90+
| Parameter name | Description | Required |
91+
|------------------------ | --------------------------------------|--------------------------------------|
92+
| `userReference` | The user reference returned by Thepeer API when a user has been indexed |`true`|
93+
94+
## Configuration
95+
Every request will require this configuration to initiate a transaction.
9596

97+
```
98+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
99+
100+
```
96101
| Parameter name | Description | Required |
97102
|------------------------ | --------------------------------------|--------------------------------------|
98103
| `amount` | The amount you intend to send and must be pass as an integer in kobo |`true`|
99104
| `currency ` | Currency which can be `"NGN"` or `"USD"` |`true`|
100-
| `userReference` | The user reference returned by Thepeer API when a user has been indexed |`true`|
101105
| `meta` | This object should contain additional/optional attributes you would like to have on your transaction response |`false`|
102106

103107
## Send
@@ -107,16 +111,16 @@ Initiate the send request by calling the below function
107111
KOTLIN
108112

109113
```kotlin
110-
111-
thepeer.send()
114+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
115+
thepeer.send(config = config)
112116

113117
```
114118

115119
JAVA
116120

117121
```java
118122

119-
thepeer.send();
123+
thepeer.send(config);
120124

121125
```
122126

@@ -128,15 +132,16 @@ KOTLIN
128132

129133
```kotlin
130134

131-
thepeer.checkout(email: String)
135+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
136+
thepeer.checkout("[email protected]", config = config)
132137

133138
```
134139

135140
JAVA
136141

137142
```java
138143

139-
thepeer.checkout(String email);
144+
thepeer.checkout("email@gmail.com", config);
140145

141146
```
142147

@@ -147,16 +152,16 @@ Initiate the Direct Charge request by calling the below function
147152
KOTLIN
148153

149154
```kotlin
150-
151-
thepeer.directCharge()
155+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
156+
thepeer.directCharge(config)
152157

153158
```
154159

155160
JAVA
156161

157162
```java
158163

159-
thepeer.directCharge();
164+
thepeer.directCharge(config);
160165

161166
```
162167

@@ -168,9 +173,9 @@ KOTLIN
168173

169174
```Kotlin
170175
private val resultListener = object : ThepeerResultListener {
171-
override fun onSuccess(transaction: ThepeerTransaction) {
176+
override fun onSuccess(response: String) {
172177
// Transaction Successful
173-
Log.v(TAG, transaction.toString())
178+
Log.v(TAG,response)
174179

175180
}
176181

@@ -195,7 +200,7 @@ JAVA
195200
new ThepeerResultListener() {
196201

197202
@Override
198-
public void onSuccess(@NonNull ThepeerTransaction transaction) {
203+
public void onSuccess(@NonNull String transaction) {
199204
((TextView) findViewById(R.id.resultText)).setText(transaction.toString());
200205
}
201206

@@ -212,6 +217,51 @@ JAVA
212217
}
213218

214219

220+
```
221+
## Response structure
222+
```JSON
223+
{
224+
"event": "send.success",
225+
"type": "send.success",
226+
"data": {
227+
"id": "744bdf8f-17a6-46ae-bda1-b348c6d22f89",
228+
"amount": 100000,
229+
"channel": "send",
230+
"refund": false,
231+
"checkout": null,
232+
"user": {
233+
"reference": "73f03de5-1043-4ad1-bc2e-aa4d94ebee4f",
234+
"name": "Doreen Okoh",
235+
"identifier": "doreen",
236+
"identifier_type": "username",
237+
"email": "[email protected]",
238+
"created_at": "2021-04-19T19:50:26.000000Z",
239+
"updated_at": "2022-02-14T22:58:25.000000Z"
240+
},
241+
"charge": 1000,
242+
"currency": "NGN",
243+
"mode": "debit",
244+
"reference": "d34dfaebd727e40a8f436a4b43acbf73",
245+
"remark": "food",
246+
"status": "success",
247+
"type": "peer",
248+
"meta": null,
249+
"peer": {
250+
"business": {
251+
"name": "Cash App",
252+
"logo": "https://palaciodepeer.s3.us-east-2.amazonaws.com/business_logos/UJimBqYOu7KQIM3DwCWOuKjkDbBbVLYRuYRTgxKh.png",
253+
"logo_colour": "#77cc33"
254+
},
255+
"user": {
256+
"name": "Trojan Okoh",
257+
"identifier": "trojan",
258+
"identifier_type": "username"
259+
}
260+
},
261+
"updated_at": "2023-05-25T12:32:03.000000Z",
262+
"created_at": "2023-05-25T12:32:03.000000Z"
263+
}
264+
}
215265
```
216266
## Support
217267

demo-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies {
4545
implementation 'androidx.appcompat:appcompat:1.4.1'
4646
implementation 'com.google.android.material:material:1.5.0'
4747
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
48-
implementation 'androidx.core:core-ktx:+'
48+
implementation 'androidx.core:core-ktx:1.10.1'
4949
testImplementation 'junit:junit:4.+'
5050
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
5151
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

demo-app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<meta-data
2323
android:name="co.thepeer.PublicKey"
24-
android:value="pspk_test_m7pbk9fbjaofi92shcgxq8is4pfgxl0t0bq3g3bmrp7iq" />
24+
android:value="pspk_test_2aj8xasztf4domzd2nphinvzkvecpbuyxldkvr3pkuvko" />
2525
</application>
2626

2727
</manifest>
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,49 @@
11
package co.thepeer
22

3-
import android.content.Intent
43
import android.os.Bundle
5-
import android.util.Log
64
import androidx.appcompat.app.AppCompatActivity
75
import co.thepeer.databinding.ActivityMainBinding
86
import co.thepeer.sdk.Thepeer
9-
import co.thepeer.sdk.model.ThepeerTransaction
7+
import co.thepeer.sdk.model.ThepeerConfig
108
import co.thepeer.sdk.ui.ThepeerResultListener
119
import co.thepeer.sdk.utils.ThepeerCurrency
1210
import java.math.BigDecimal
1311

1412
class MainActivity : AppCompatActivity() {
15-
private val INITIATE_PAYMENT_REQUEST_CODE = 1
16-
private val KEY_RESULT = "result_key"
1713

1814
private lateinit var binding: ActivityMainBinding
1915

16+
lateinit var thepeer: Thepeer
2017
override fun onCreate(savedInstanceState: Bundle?) {
2118
super.onCreate(savedInstanceState)
2219
binding = ActivityMainBinding.inflate(layoutInflater)
2320
setContentView(binding.root)
2421

2522
// initialize Thepeer SDK
26-
val thepeer = Thepeer.Builder(
23+
val thepeer = Thepeer.Initiate(
2724
activity = this,
28-
amount = BigDecimal(10000000),
29-
currency = ThepeerCurrency.NGN,
3025
userReference = getString(R.string.user_reference),
31-
resultListener = resultListener
32-
).setMeta(mapOf("city" to "Uyo")).build()
26+
resultListener = resultListener,
27+
).build()
3328

3429
binding.btnSendMoney.setOnClickListener {
3530
// calling ThePeer SDK
36-
thepeer.send()
31+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = ThepeerCurrency.NGN)
32+
thepeer.send(config = config)
3733
}
3834
binding.btnCheckout.setOnClickListener {
39-
thepeer.checkout("[email protected]")
35+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = ThepeerCurrency.NGN)
36+
thepeer.checkout("[email protected]", config = config)
4037
}
4138
binding.btnDirectDebit.setOnClickListener {
42-
thepeer.directCharge()
39+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = ThepeerCurrency.NGN)
40+
thepeer.directCharge(config)
4341
}
4442
}
4543

4644
private val resultListener = object : ThepeerResultListener {
47-
override fun onSuccess(transaction: ThepeerTransaction) {
48-
binding.resultText.text = transaction.toString()
49-
45+
override fun onSuccess(response: String) {
46+
binding.resultText.text = response
5047
}
5148

5249
override fun onError(error: Throwable) {
@@ -56,7 +53,5 @@ class MainActivity : AppCompatActivity() {
5653
override fun onCancelled() {
5754
binding.resultText.text = " Cancelled"
5855
}
59-
6056
}
61-
6257
}

demo-app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<string name="send_money">Send Money</string>
44
<string name="checkout">Checkout</string>
55
<string name="direct_charge">Direct Charge</string>
6-
<string name="user_reference">fd92e93b-8907-4429-86e5-9cf2fea2a9d8</string>
6+
<string name="user_reference">73f03de5-1043-4ad1-bc2e-aa4d94ebee4f</string>
77
</resources>

java-demo/src/main/java/com/example/java_demo/MainActivity.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,26 @@
1212
import java.util.HashMap;
1313

1414
import co.thepeer.sdk.Thepeer;
15-
import co.thepeer.sdk.model.ThepeerTransaction;
15+
import co.thepeer.sdk.model.ThepeerConfig;
1616
import co.thepeer.sdk.ui.ThepeerResultListener;
1717
import co.thepeer.sdk.utils.ThepeerCurrency;
1818

1919
public class MainActivity extends AppCompatActivity {
2020

2121

22-
2322
@Override
2423
protected void onCreate(Bundle savedInstanceState) {
2524
super.onCreate(savedInstanceState);
2625
setContentView(R.layout.activity_main);
2726

2827
HashMap<String, String> meta = new HashMap<>();
2928
// initialize Thepeer SDK
30-
Thepeer thepeer =new Thepeer.Builder(
31-
this,
32-
new BigDecimal("100000.00"),
33-
ThepeerCurrency.NGN,
29+
Thepeer thepeer = new Thepeer.Initiate(
3430
getResources().getString(R.string.user_reference),
31+
this,
3532
new ThepeerResultListener() {
3633
@Override
37-
public void onSuccess(@NonNull ThepeerTransaction transaction) {
34+
public void onSuccess(@NonNull String transaction) {
3835
((TextView) findViewById(R.id.resultText)).setText(transaction.toString());
3936
}
4037

@@ -48,13 +45,13 @@ public void onError(@NonNull Throwable error) {
4845

4946
}
5047

51-
}).setMeta(meta)
48+
})
5249
.build();
5350

5451
((Button) findViewById(R.id.btnSendMoney)).setOnClickListener(new View.OnClickListener() {
5552
@Override
5653
public void onClick(View v) {
57-
thepeer.send();
54+
thepeer.send(new ThepeerConfig(new BigDecimal("100000"), ThepeerCurrency.NGN, meta));
5855
}
5956
});
6057

0 commit comments

Comments
 (0)