Skip to content

Commit 3536565

Browse files
authored
Merge pull request #10 from thepeerstack/refactor-initialize-function
Refactored Initialize function
2 parents 3d38ace + 6ed56f3 commit 3536565

File tree

15 files changed

+201
-211
lines changed

15 files changed

+201
-211
lines changed

README.md

Lines changed: 74 additions & 23 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
@@ -108,15 +112,16 @@ KOTLIN
108112

109113
```kotlin
110114

111-
thepeer.send()
115+
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
116+
thepeer.send(config = config)
112117

113118
```
114119

115120
JAVA
116121

117122
```java
118123

119-
thepeer.send();
124+
thepeer.send(config);
120125

121126
```
122127

@@ -128,15 +133,16 @@ KOTLIN
128133

129134
```kotlin
130135

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

133139
```
134140

135141
JAVA
136142

137143
```java
138144

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

141147
```
142148

@@ -147,16 +153,16 @@ Initiate the Direct Charge request by calling the below function
147153
KOTLIN
148154

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

153159
```
154160

155161
JAVA
156162

157163
```java
158164

159-
thepeer.directCharge();
165+
thepeer.directCharge(config);
160166

161167
```
162168

@@ -168,9 +174,9 @@ KOTLIN
168174

169175
```Kotlin
170176
private val resultListener = object : ThepeerResultListener {
171-
override fun onSuccess(transaction: ThepeerTransaction) {
177+
override fun onSuccess(response: String) {
172178
// Transaction Successful
173-
Log.v(TAG, transaction.toString())
179+
Log.v(TAG,response)
174180

175181
}
176182

@@ -195,7 +201,7 @@ JAVA
195201
new ThepeerResultListener() {
196202

197203
@Override
198-
public void onSuccess(@NonNull ThepeerTransaction transaction) {
204+
public void onSuccess(@NonNull String transaction) {
199205
((TextView) findViewById(R.id.resultText)).setText(transaction.toString());
200206
}
201207

@@ -212,6 +218,51 @@ JAVA
212218
}
213219

214220

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

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/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
implementation 'androidx.appcompat:appcompat:1.4.1'
3333
implementation 'com.google.android.material:material:1.5.0'
3434
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
35-
implementation 'androidx.core:core-ktx:+'
35+
implementation 'androidx.core:core-ktx:1.7.0'
3636
testImplementation 'junit:junit:4.+'
3737
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
3838
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

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)