Skip to content

Commit

Permalink
Merge pull request #10 from thepeerstack/refactor-initialize-function
Browse files Browse the repository at this point in the history
Refactored Initialize function
  • Loading branch information
kamsy authored May 25, 2023
2 parents 3d38ace + 6ed56f3 commit 3536565
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 211 deletions.
97 changes: 74 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,10 @@ override fun onCreate(savedInstanceState: Bundle?) {


// initialize Thepeer SDK
val thepeer = Thepeer.Builder(
activity = this,
amount = BigDecimal(10000.00),
currency = "NGN",
userReference = getString(R.string.user_reference),
resultListener = resultListener
).setMeta(mapOf("remark" to "Enjoy")).build()

val thepeer = Thepeer.Initiate(
activity = this,
userReference = "YOUR _USER_REFERENCE",
resultListener = resultListener).build()
}

```
Expand All @@ -83,21 +79,29 @@ JAVA
setContentView(R.layout.activity_main);

// initialize Thepeer SDK
Thepeer thepeer =new Thepeer.Builder(
this,
new BigDecimal("1000.00"),
"NGN",
Thepeer thepeer = new Thepeer.Initiate(
getResources().getString(R.string.user_reference),
activity,
new ThepeerResultListener())

}

```
| Parameter name | Description | Required |
|------------------------ | --------------------------------------|--------------------------------------|
| `userReference` | The user reference returned by Thepeer API when a user has been indexed |`true`|

## Configuration
Every request will require this configuration to initiate a transaction.

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

## Send
Expand All @@ -108,15 +112,16 @@ KOTLIN

```kotlin

thepeer.send()
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
thepeer.send(config = config)

```

JAVA

```java

thepeer.send();
thepeer.send(config);

```

Expand All @@ -128,15 +133,16 @@ KOTLIN

```kotlin

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

```

JAVA

```java

thepeer.checkout(String email);
thepeer.checkout("email@gmail.com", config);

```

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

```kotlin

thepeer.directCharge()
val config = ThepeerConfig(amount = BigDecimal(100000), currency = "NGN", meta = mapOf())
thepeer.directCharge(config)

```

JAVA

```java

thepeer.directCharge();
thepeer.directCharge(config);

```

Expand All @@ -168,9 +174,9 @@ KOTLIN

```Kotlin
private val resultListener = object : ThepeerResultListener {
override fun onSuccess(transaction: ThepeerTransaction) {
override fun onSuccess(response: String) {
// Transaction Successful
Log.v(TAG, transaction.toString())
Log.v(TAG,response)

}

Expand All @@ -195,7 +201,7 @@ JAVA
new ThepeerResultListener() {

@Override
public void onSuccess(@NonNull ThepeerTransaction transaction) {
public void onSuccess(@NonNull String transaction) {
((TextView) findViewById(R.id.resultText)).setText(transaction.toString());
}

Expand All @@ -212,6 +218,51 @@ JAVA
}


```
## Response structure
```JSON
{
"event": "send.success",
"type": "send.success",
"data": {
"id": "744bdf8f-17a6-46ae-bda1-b348c6d22f89",
"amount": 100000,
"channel": "send",
"refund": false,
"checkout": null,
"user": {
"reference": "73f03de5-1043-4ad1-bc2e-aa4d94ebee4f",
"name": "Doreen Okoh",
"identifier": "doreen",
"identifier_type": "username",
"email": "[email protected]",
"created_at": "2021-04-19T19:50:26.000000Z",
"updated_at": "2022-02-14T22:58:25.000000Z"
},
"charge": 1000,
"currency": "NGN",
"mode": "debit",
"reference": "d34dfaebd727e40a8f436a4b43acbf73",
"remark": "food",
"status": "success",
"type": "peer",
"meta": null,
"peer": {
"business": {
"name": "Cash App",
"logo": "https://palaciodepeer.s3.us-east-2.amazonaws.com/business_logos/UJimBqYOu7KQIM3DwCWOuKjkDbBbVLYRuYRTgxKh.png",
"logo_colour": "#77cc33"
},
"user": {
"name": "Trojan Okoh",
"identifier": "trojan",
"identifier_type": "username"
}
},
"updated_at": "2023-05-25T12:32:03.000000Z",
"created_at": "2023-05-25T12:32:03.000000Z"
}
}
```
## Support

Expand Down
2 changes: 1 addition & 1 deletion demo-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.core:core-ktx:+'
implementation 'androidx.core:core-ktx:1.10.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
2 changes: 1 addition & 1 deletion demo-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<meta-data
android:name="co.thepeer.PublicKey"
android:value="pspk_test_m7pbk9fbjaofi92shcgxq8is4pfgxl0t0bq3g3bmrp7iq" />
android:value="pspk_test_2aj8xasztf4domzd2nphinvzkvecpbuyxldkvr3pkuvko" />
</application>

</manifest>
31 changes: 13 additions & 18 deletions demo-app/src/main/java/co/thepeer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
package co.thepeer

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import co.thepeer.databinding.ActivityMainBinding
import co.thepeer.sdk.Thepeer
import co.thepeer.sdk.model.ThepeerTransaction
import co.thepeer.sdk.model.ThepeerConfig
import co.thepeer.sdk.ui.ThepeerResultListener
import co.thepeer.sdk.utils.ThepeerCurrency
import java.math.BigDecimal

class MainActivity : AppCompatActivity() {
private val INITIATE_PAYMENT_REQUEST_CODE = 1
private val KEY_RESULT = "result_key"

private lateinit var binding: ActivityMainBinding

lateinit var thepeer: Thepeer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

// initialize Thepeer SDK
val thepeer = Thepeer.Builder(
val thepeer = Thepeer.Initiate(
activity = this,
amount = BigDecimal(10000000),
currency = ThepeerCurrency.NGN,
userReference = getString(R.string.user_reference),
resultListener = resultListener
).setMeta(mapOf("city" to "Uyo")).build()
resultListener = resultListener,
).build()

binding.btnSendMoney.setOnClickListener {
// calling ThePeer SDK
thepeer.send()
val config = ThepeerConfig(amount = BigDecimal(100000), currency = ThepeerCurrency.NGN)
thepeer.send(config = config)
}
binding.btnCheckout.setOnClickListener {
thepeer.checkout("[email protected]")
val config = ThepeerConfig(amount = BigDecimal(100000), currency = ThepeerCurrency.NGN)
thepeer.checkout("[email protected]", config = config)
}
binding.btnDirectDebit.setOnClickListener {
thepeer.directCharge()
val config = ThepeerConfig(amount = BigDecimal(100000), currency = ThepeerCurrency.NGN)
thepeer.directCharge(config)
}
}

private val resultListener = object : ThepeerResultListener {
override fun onSuccess(transaction: ThepeerTransaction) {
binding.resultText.text = transaction.toString()

override fun onSuccess(response: String) {
binding.resultText.text = response
}

override fun onError(error: Throwable) {
Expand All @@ -56,7 +53,5 @@ class MainActivity : AppCompatActivity() {
override fun onCancelled() {
binding.resultText.text = " Cancelled"
}

}

}
2 changes: 1 addition & 1 deletion demo-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<string name="send_money">Send Money</string>
<string name="checkout">Checkout</string>
<string name="direct_charge">Direct Charge</string>
<string name="user_reference">fd92e93b-8907-4429-86e5-9cf2fea2a9d8</string>
<string name="user_reference">73f03de5-1043-4ad1-bc2e-aa4d94ebee4f</string>
</resources>
2 changes: 1 addition & 1 deletion java-demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.core:core-ktx:+'
implementation 'androidx.core:core-ktx:1.7.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
15 changes: 6 additions & 9 deletions java-demo/src/main/java/com/example/java_demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@
import java.util.HashMap;

import co.thepeer.sdk.Thepeer;
import co.thepeer.sdk.model.ThepeerTransaction;
import co.thepeer.sdk.model.ThepeerConfig;
import co.thepeer.sdk.ui.ThepeerResultListener;
import co.thepeer.sdk.utils.ThepeerCurrency;

public class MainActivity extends AppCompatActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

HashMap<String, String> meta = new HashMap<>();
// initialize Thepeer SDK
Thepeer thepeer =new Thepeer.Builder(
this,
new BigDecimal("100000.00"),
ThepeerCurrency.NGN,
Thepeer thepeer = new Thepeer.Initiate(
getResources().getString(R.string.user_reference),
this,
new ThepeerResultListener() {
@Override
public void onSuccess(@NonNull ThepeerTransaction transaction) {
public void onSuccess(@NonNull String transaction) {
((TextView) findViewById(R.id.resultText)).setText(transaction.toString());
}

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

}

}).setMeta(meta)
})
.build();

((Button) findViewById(R.id.btnSendMoney)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
thepeer.send();
thepeer.send(new ThepeerConfig(new BigDecimal("100000"), ThepeerCurrency.NGN, meta));
}
});

Expand Down
Loading

0 comments on commit 3536565

Please sign in to comment.