File tree Expand file tree Collapse file tree
androidTest/kotlin/flizpay2/flizpaysdk
main/kotlin/flizpay2/flizpaysdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ class FlizpaySDKTest {
3030 mockkConstructor(TransactionService ::class )
3131 every {
3232 anyConstructed<TransactionService >().fetchTransactionInfo(
33+ any(),
3334 any(),
3435 any(),
3536 captureLambda()
@@ -62,6 +63,7 @@ class FlizpaySDKTest {
6263 // Override default success mock with failure
6364 every {
6465 anyConstructed<TransactionService >().fetchTransactionInfo(
66+ any(),
6567 any(),
6668 any(),
6769 captureLambda()
Original file line number Diff line number Diff line change @@ -15,17 +15,19 @@ object FlizpaySDK {
1515 * @param context The Context from which to launch the payment WebView.
1616 * @param token The JWT token fetched by the host app.
1717 * @param amount The transaction amount.
18+ * @param metadata The metadata object.
1819 * @param onFailure Optional callback to handle errors (e.g., show alerts).
1920 */
2021 fun initiatePayment (
2122 context : Context ,
2223 token : String ,
2324 amount : String ,
25+ metadata : Map <String , Any ?>? = null,
2426 onFailure : ((Throwable ) -> Unit )? = null,
2527 ) {
2628 val transactionService = TransactionService ()
2729
28- transactionService.fetchTransactionInfo(token, amount) { result ->
30+ transactionService.fetchTransactionInfo(token, amount, metadata ) { result ->
2931 if (result.isSuccess) {
3032 val redirectUrl = result.getOrNull() ? : Constants .BASE_URL
3133
Original file line number Diff line number Diff line change @@ -7,24 +7,32 @@ import flizpay2.flizpaysdk.Constants
77import okhttp3.MediaType.Companion.toMediaTypeOrNull
88import okhttp3.RequestBody.Companion.toRequestBody
99import org.json.JSONObject
10+ import org.json.JSONArray
1011
1112
1213class TransactionService {
1314 private val client = OkHttpClient ()
1415
16+ private fun Map <String , Any ?>.toJsonObject (): JSONObject =
17+ JSONObject ().apply {
18+ forEach { (k, v) -> put(k, JSONObject .wrap(v)) }
19+ }
20+
1521 /* *
1622 * Calls the /transactions endpoint using the provided token and amount.
1723 */
1824 fun fetchTransactionInfo (
1925 token : String ,
2026 amount : String ,
27+ metadata : Map <String , Any ?>? = null,
2128 completion : (Result <String >) -> Unit
2229 ) {
2330 val url = " ${Constants .API_URL } /transactions"
2431 val requestBody = JSONObject ()
2532 .put(" amount" , amount)
2633 .put(" currency" , " EUR" )
2734 .put(" source" , " sdk_integration" )
35+ .put(" metadata" , metadata?.toJsonObject() ? : JSONObject ())
2836 .toString()
2937 .toRequestBody(" application/json; charset=utf-8" .toMediaTypeOrNull())
3038
You can’t perform that action at this time.
0 commit comments