-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from thepeerstack/refactor-initialize-function
Refactored Initialize function
- Loading branch information
Showing
15 changed files
with
201 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
} | ||
|
||
``` | ||
|
@@ -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 | ||
|
@@ -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); | ||
|
||
``` | ||
|
||
|
@@ -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); | ||
|
||
``` | ||
|
||
|
@@ -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); | ||
|
||
``` | ||
|
||
|
@@ -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) | ||
|
||
} | ||
|
||
|
@@ -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()); | ||
} | ||
|
||
|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
@@ -56,7 +53,5 @@ class MainActivity : AppCompatActivity() { | |
override fun onCancelled() { | ||
binding.resultText.text = " Cancelled" | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.