diff --git a/dist/doc/guides/terminal-flutter/create-method-channel.js b/dist/doc/guides/terminal-flutter/create-method-channel.js new file mode 100644 index 0000000..852f50f --- /dev/null +++ b/dist/doc/guides/terminal-flutter/create-method-channel.js @@ -0,0 +1,27 @@ +const kt = `// other imports +import io.flutter.embedding.engine.FlutterEngine +import io.flutter.plugin.common.MethodChannel + +class MainActivity: FlutterActivity() { + private val CHANNEL = "com.example.sample_registration/payment" + // other code snippet + override fun configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + + MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + call, result -> + if (call.method == "makePayment") { + val amount = call.argument("amount") ?: 0 + makePayment(amount) + + result.success(transactionStatus) + } else { + result.notImplemented() + } + } + } + + // other code snippet +}` + +export {kt} \ No newline at end of file diff --git a/dist/doc/guides/terminal-flutter/create-models.js b/dist/doc/guides/terminal-flutter/create-models.js new file mode 100644 index 0000000..ffd4140 --- /dev/null +++ b/dist/doc/guides/terminal-flutter/create-models.js @@ -0,0 +1,54 @@ +const paystack_intent_response = ` +// PaystackIntentResponse.kt +data class PaystackIntentResponse ( + val intentKey: String, + val intentResponseCode: Int, + val intentResponse: TerminalResponse +)` + +const terminal_response = ` +// TerminalResponse.kt +data class TerminalResponse( + val statusCode: String, + val message: String, + val data: String +)` + +const transaction_request = ` +// TransactionRequest.kt +data class TransactionRequest( + val amount: Int, + val offlineReference: String?, + val supplementaryReceiptData: SupplementaryReceiptData?, + val metadata: Map? +) + +data class SupplementaryReceiptData( + val developerSuppliedText: String?, + val developerSuppliedImageUrlPath: String?, + val barcodeOrQrcodeImageText: String?, + val textImageType: TextImageFormat? +) + +enum class TextImageFormat { + QR_CODE, + AZTEC_BARCODE +}` + +const transaction_response = `// TransactionResponse.kt +import com.google.gson.annotations.SerializedName + +data class TransactionResponse( + val id: String?, + val amount: Int?, + val reference: String?, + val status: String?, + val currency: String?, + @SerializedName("country_code") + val countryCode: String?, + @SerializedName("paid_at") + val paidAt: String?, + val terminal: String? +)` + +export {paystack_intent_response, terminal_response, transaction_request, transaction_response} \ No newline at end of file diff --git a/dist/doc/guides/terminal-flutter/create-payment-intent.js b/dist/doc/guides/terminal-flutter/create-payment-intent.js new file mode 100644 index 0000000..d0bb6e7 --- /dev/null +++ b/dist/doc/guides/terminal-flutter/create-payment-intent.js @@ -0,0 +1,78 @@ +const kt = `// MainActivity.kt +import android.content.Intent +import android.util.Log +import android.widget.Toast +import com.example.sample_registration.model.CustomField +import com.example.sample_registration.model.PaystackIntentResponse +import com.example.sample_registration.model.TerminalResponse +import com.example.sample_registration.model.TransactionRequest +import com.example.sample_registration.model.TransactionResponse +import com.google.gson.Gson +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { + private val gson = Gson() + private var transactionStatus: String? = "" + + private val CHANNEL = "com.example.sample_registration/payment" + private val PACKAGE_NAME = "com.paystack.pos" + private val TRANSACTION = "com.paystack.pos.TRANSACT" + private val TRANSACTION_RESULT_CODE = 14 + + + private fun makePayment(amount: Int?) { + val transactionRequest = amount?.let { + TransactionRequest( + amount = it, + offlineReference = null, + supplementaryReceiptData = null, + metadata = mapOf( + "custom_fields" to listOf( + CustomField( + displayName = "App Name", + variableName = "app_name", + value = "Sample Registration" + ) + ) + ) + ) + } + + val transactionIntent = Intent(Intent.ACTION_VIEW).apply { + setPackage(PACKAGE_NAME) + putExtra(TRANSACTION, gson.toJson(transactionRequest)) + } + + startActivityForResult(transactionIntent, 1) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + val paystackIntentResponse: PaystackIntentResponse + + if (resultCode == TRANSACTION_RESULT_CODE) { + paystackIntentResponse = gson.fromJson( + data?.getStringExtra(TRANSACTION), + PaystackIntentResponse::class.java + ) + + processResponse(paystackIntentResponse) + } + else { + // handle invalid result code + } + } + + private fun processResponse(response: PaystackIntentResponse) { + + val terminalResponse: TerminalResponse = response.intentResponse + val transactionResponse = gson.fromJson( + terminalResponse.data, + TransactionResponse::class.java + ) + + transactionStatus = transactionResponse.reference + } +}` + +export {kt} \ No newline at end of file diff --git a/dist/doc/guides/terminal-flutter/link-method-channel.js b/dist/doc/guides/terminal-flutter/link-method-channel.js new file mode 100644 index 0000000..56ae88d --- /dev/null +++ b/dist/doc/guides/terminal-flutter/link-method-channel.js @@ -0,0 +1,29 @@ +const dart = `static const _methodChannel = + MethodChannel('com.example.sample_registration/payment'); + +Future makePayment() async { + String reference = ''; + try { + var options = { + 'amount': 5000, + 'supplementaryData': { + 'developerSuppliedText': null, + 'developerSuppliedImageUrlPath': + "https://assets.paystack.com/assets/img/press/Terminal-x-Bature-x-World-Cup-Receipt.jpg", + 'barcodeOrQrcodeImageText': null, + 'textImageType': null + } + }; + reference = await _methodChannel.invokeMethod('makePayment', options); + print("Reference: $reference"); + } on PlatformException catch (e) { + print("Error: $e"); + reference = ''; + } + + setState(() { + _transactionReference = reference; + }); + }` + +export {dart} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-models.js b/dist/doc/guides/terminal-react-native/create-models.js new file mode 100644 index 0000000..e397062 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-models.js @@ -0,0 +1,135 @@ +const paystack_intent_response = ` +// PaystackIntentResponse.java +public class PaystackIntentResponse { + private final String intentkey; + private final int intentResponseCode; + private final TerminalResponse intentResponse; + + public PaystackIntentResponse(String intentkey, int intentResponseCode, TerminalResponse intentResponse) { + this.intentkey = intentkey; + this.intentResponseCode = intentResponseCode; + this.intentResponse = intentResponse; + } + + public String getIntentkey() { + return intentkey; + } + + public int getIntentResponseCode() { + return intentResponseCode; + } + + public TerminalResponse getIntentResponse() { + return intentResponse; + } +}` + +const terminal_response = ` +// TerminalResponse.java +public class TerminalResponse { + private final String statusCode; + private final String message; + private final String data; + + public TerminalResponse(String statusCode, String message, String data) { + this.statusCode = statusCode; + this.message = message; + this.data = data; + } + + public String getStatusCode() { + return statusCode; + } + + public String getMessage() { + return message; + } + + public String getData() { + return data; + } +}` + +const transaction_request = ` +// TransactionRequest.java +import java.util.Map; + +public class TransactionRequest { + private int amount; + private Map metadata; + + public TransactionRequest() { + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } +}` + +const transaction_response = ` +// TransactionResponse.java +import com.google.gson.annotations.SerializedName; + +public class TransactionResponse { + private final String id; + private final int amount; + private final String reference; + private final String status; + private final String currency; + @SerializedName("country_code") + private final String countryCode; + @SerializedName("paid_at") + private final String paidAt; + private final String terminal; + + public TransactionResponse( + String id, int amount, String reference, String status, + String currency, String countryCode, String paidAt, String terminal) { + this.id = id; + this.amount = amount; + this.reference = reference; + this.status = status; + this.currency = currency; + this.countryCode = countryCode; + this.paidAt = paidAt; + this.terminal = terminal; + } + + public String getId() { + return id; + } + + public int getAmount() { + return amount; + } + + public String getReference() { + return reference; + } + + public String getStatus() { + return status; + } + + public String getCurrency() { + return currency; + } + + public String getCountryCode() { + return countryCode; + } + + public String getPaidAt() { + return paidAt; + } + + public String getTerminal() { + return terminal; + } +}` + +export {paystack_intent_response, terminal_response, transaction_request, transaction_response} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-module/paystack-module-callback.js b/dist/doc/guides/terminal-react-native/create-module/paystack-module-callback.js new file mode 100644 index 0000000..74e7fc0 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-module/paystack-module-callback.js @@ -0,0 +1,36 @@ +const java = `import android.app.Activity; +import android.content.Intent; + +import com.facebook.react.bridge.ActivityEventListener; +import com.facebook.react.bridge.BaseActivityEventListener; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.google.gson.Gson; + +public class PaystackModule extends ReactContextBaseJavaModule { + + private final Gson gson = new Gson(); + private Callback mCallback; + + private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { + @Override + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { + PaystackIntentResponse paystackIntentResponse; + TerminalResponse terminalResponse; + + paystackIntentResponse = gson.fromJson( + data != null ? data.getStringExtra("com.paystack.pos.TRANSACT") : null, + PaystackIntentResponse.class); + terminalResponse = paystackIntentResponse.getIntentResponse(); + TransactionResponse transactionResponse = gson.fromJson( + terminalResponse.getData(), + TransactionResponse.class); + mCallback.invoke(transactionResponse.getReference()); + } + }; + + // the rest of the code previously added +}` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-module/paystack-module-final.js b/dist/doc/guides/terminal-react-native/create-module/paystack-module-final.js new file mode 100644 index 0000000..70efcf9 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-module/paystack-module-final.js @@ -0,0 +1,66 @@ +const java = `import android.app.Activity; +import android.content.Intent; +import android.util.Log; + +import com.facebook.react.bridge.ActivityEventListener; +import com.facebook.react.bridge.BaseActivityEventListener; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.google.gson.Gson; + +public class PaystackModule extends ReactContextBaseJavaModule { + + private final Gson gson = new Gson(); + private Callback mCallback; + + private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { + @Override + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { + PaystackIntentResponse paystackIntentResponse; + TerminalResponse terminalResponse; + + paystackIntentResponse = gson.fromJson( + data != null ? data.getStringExtra("com.paystack.pos.TRANSACT") : null, + PaystackIntentResponse.class); + terminalResponse = paystackIntentResponse.getIntentResponse(); + TransactionResponse transactionResponse = gson.fromJson( + terminalResponse.getData(), + TransactionResponse.class); + mCallback.invoke(transactionResponse.getReference()); + } + }; + + PaystackModule(ReactApplicationContext context) { + super(context); + + context.addActivityEventListener(mActivityEventListener); + } + + @Override + public String getName() { + return "PaystackModule"; + } + + @ReactMethod + public void makePayment(int amount, Callback callback) { + TransactionRequest transactionRequest = new TransactionRequest(); + transactionRequest.setAmount(amount); + + Activity currentActivity = getCurrentActivity(); + mCallback = callback; + + try { + final Intent transactionIntent = new Intent(Intent.ACTION_VIEW); + transactionIntent.setPackage("com.paystack.pos"); + transactionIntent.putExtra("com.paystack.pos.TRANSACT", + gson.toJson(transactionRequest)); + currentActivity.startActivityForResult(transactionIntent, 1); + } catch (Exception e) { + Log.d("PaystackModule", "Error: " + e.getMessage()); + } + } +}` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-module/paystack-module-make-payment.js b/dist/doc/guides/terminal-react-native/create-module/paystack-module-make-payment.js new file mode 100644 index 0000000..ec36550 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-module/paystack-module-make-payment.js @@ -0,0 +1,20 @@ +const java = `@ReactMethod +public void makePayment(int amount, Callback callback) { + TransactionRequest transactionRequest = new TransactionRequest(); + transactionRequest.setAmount(amount); + + Activity currentActivity = getCurrentActivity(); + mCallback = callback; + + try { + final Intent transactionIntent = new Intent(Intent.ACTION_VIEW); + transactionIntent.setPackage("com.paystack.pos"); + transactionIntent.putExtra("com.paystack.pos.TRANSACT", + gson.toJson(transactionRequest)); + currentActivity.startActivityForResult(transactionIntent, 1); + } catch (Exception e) { + Log.d("PaystackModule", "Error: " + e.getMessage()); + } +}` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-module/paystack-module-register.js b/dist/doc/guides/terminal-react-native/create-module/paystack-module-register.js new file mode 100644 index 0000000..d114691 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-module/paystack-module-register.js @@ -0,0 +1,7 @@ +const java = `PaystackModule(ReactApplicationContext context) { + super(context); + + context.addActivityEventListener(mActivityEventListener); +}` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-module/paystack-module-setup.js b/dist/doc/guides/terminal-react-native/create-module/paystack-module-setup.js new file mode 100644 index 0000000..8dd1c02 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-module/paystack-module-setup.js @@ -0,0 +1,16 @@ +const java = `import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; + +public class PaystackModule extends ReactContextBaseJavaModule { + + PaystackModule(ReactApplicationContext context) { + super(context); + } + + @Override + public String getName() { + return "PaystackModule"; + } +}` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/create-package.js b/dist/doc/guides/terminal-react-native/create-package.js new file mode 100644 index 0000000..af4d2fc --- /dev/null +++ b/dist/doc/guides/terminal-react-native/create-package.js @@ -0,0 +1,26 @@ +const java = `import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class SampleRegistrationPackage implements ReactPackage { + + @Override + public List createViewManagers(ReactApplicationContext reactApplicationContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules(ReactApplicationContext reactApplicationContext) { + List modules = new ArrayList<>(); + modules.add(new PaystackModule(reactApplicationContext)); + + return modules; + } +}` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/expose-package.js b/dist/doc/guides/terminal-react-native/expose-package.js new file mode 100644 index 0000000..1f20c6a --- /dev/null +++ b/dist/doc/guides/terminal-react-native/expose-package.js @@ -0,0 +1,3 @@ +const java = `packages.add(new MyAppPackage());` + +export {java} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/use-module/initialization.js b/dist/doc/guides/terminal-react-native/use-module/initialization.js new file mode 100644 index 0000000..d9d4aa8 --- /dev/null +++ b/dist/doc/guides/terminal-react-native/use-module/initialization.js @@ -0,0 +1,4 @@ +const js = `import { NativeModules } from 'react-native'; +const { PaystackModule } = NativeModules;` + +export {js} \ No newline at end of file diff --git a/dist/doc/guides/terminal-react-native/use-module/usage.js b/dist/doc/guides/terminal-react-native/use-module/usage.js new file mode 100644 index 0000000..82299ef --- /dev/null +++ b/dist/doc/guides/terminal-react-native/use-module/usage.js @@ -0,0 +1,8 @@ +const js = `const onPress = async () => { + PaystackModule.makePayment(3000, transactionReference => { + console.log('transaction ref: ', transactionReference); + + }); +};` + +export {js} \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-method-channel/config.yml b/src/doc/guides/terminal-flutter/create-method-channel/config.yml new file mode 100644 index 0000000..4541ce7 --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-method-channel/config.yml @@ -0,0 +1,2 @@ +languages: + - kt \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-method-channel/index.kt b/src/doc/guides/terminal-flutter/create-method-channel/index.kt new file mode 100644 index 0000000..aafba04 --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-method-channel/index.kt @@ -0,0 +1,25 @@ +// other imports +import io.flutter.embedding.engine.FlutterEngine +import io.flutter.plugin.common.MethodChannel + +class MainActivity: FlutterActivity() { + private val CHANNEL = "com.example.sample_registration/payment" + // other code snippet + override fun configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + + MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + call, result -> + if (call.method == "makePayment") { + val amount = call.argument("amount") ?: 0 + makePayment(amount) + + result.success(transactionStatus) + } else { + result.notImplemented() + } + } + } + + // other code snippet +} \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-models/config.yml b/src/doc/guides/terminal-flutter/create-models/config.yml new file mode 100644 index 0000000..237e59a --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-models/config.yml @@ -0,0 +1,3 @@ +type: single-lang +languages: + - kt \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-models/paystack-intent-response.kt b/src/doc/guides/terminal-flutter/create-models/paystack-intent-response.kt new file mode 100644 index 0000000..9fe2d1d --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-models/paystack-intent-response.kt @@ -0,0 +1,7 @@ + +// PaystackIntentResponse.kt +data class PaystackIntentResponse ( + val intentKey: String, + val intentResponseCode: Int, + val intentResponse: TerminalResponse +) \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-models/terminal-response.kt b/src/doc/guides/terminal-flutter/create-models/terminal-response.kt new file mode 100644 index 0000000..8828913 --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-models/terminal-response.kt @@ -0,0 +1,7 @@ + +// TerminalResponse.kt +data class TerminalResponse( + val statusCode: String, + val message: String, + val data: String +) \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-models/transaction-request.kt b/src/doc/guides/terminal-flutter/create-models/transaction-request.kt new file mode 100644 index 0000000..136adff --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-models/transaction-request.kt @@ -0,0 +1,20 @@ + +// TransactionRequest.kt +data class TransactionRequest( + val amount: Int, + val offlineReference: String?, + val supplementaryReceiptData: SupplementaryReceiptData?, + val metadata: Map? +) + +data class SupplementaryReceiptData( + val developerSuppliedText: String?, + val developerSuppliedImageUrlPath: String?, + val barcodeOrQrcodeImageText: String?, + val textImageType: TextImageFormat? +) + +enum class TextImageFormat { + QR_CODE, + AZTEC_BARCODE +} \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-models/transaction-response.kt b/src/doc/guides/terminal-flutter/create-models/transaction-response.kt new file mode 100644 index 0000000..88d5bb1 --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-models/transaction-response.kt @@ -0,0 +1,15 @@ +// TransactionResponse.kt +import com.google.gson.annotations.SerializedName + +data class TransactionResponse( + val id: String?, + val amount: Int?, + val reference: String?, + val status: String?, + val currency: String?, + @SerializedName("country_code") + val countryCode: String?, + @SerializedName("paid_at") + val paidAt: String?, + val terminal: String? +) \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-payment-intent/config.yml b/src/doc/guides/terminal-flutter/create-payment-intent/config.yml new file mode 100644 index 0000000..4541ce7 --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-payment-intent/config.yml @@ -0,0 +1,2 @@ +languages: + - kt \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/create-payment-intent/index.kt b/src/doc/guides/terminal-flutter/create-payment-intent/index.kt new file mode 100644 index 0000000..4ec0007 --- /dev/null +++ b/src/doc/guides/terminal-flutter/create-payment-intent/index.kt @@ -0,0 +1,76 @@ +// MainActivity.kt +import android.content.Intent +import android.util.Log +import android.widget.Toast +import com.example.sample_registration.model.CustomField +import com.example.sample_registration.model.PaystackIntentResponse +import com.example.sample_registration.model.TerminalResponse +import com.example.sample_registration.model.TransactionRequest +import com.example.sample_registration.model.TransactionResponse +import com.google.gson.Gson +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { + private val gson = Gson() + private var transactionStatus: String? = "" + + private val CHANNEL = "com.example.sample_registration/payment" + private val PACKAGE_NAME = "com.paystack.pos" + private val TRANSACTION = "com.paystack.pos.TRANSACT" + private val TRANSACTION_RESULT_CODE = 14 + + + private fun makePayment(amount: Int?) { + val transactionRequest = amount?.let { + TransactionRequest( + amount = it, + offlineReference = null, + supplementaryReceiptData = null, + metadata = mapOf( + "custom_fields" to listOf( + CustomField( + displayName = "App Name", + variableName = "app_name", + value = "Sample Registration" + ) + ) + ) + ) + } + + val transactionIntent = Intent(Intent.ACTION_VIEW).apply { + setPackage(PACKAGE_NAME) + putExtra(TRANSACTION, gson.toJson(transactionRequest)) + } + + startActivityForResult(transactionIntent, 1) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + val paystackIntentResponse: PaystackIntentResponse + + if (resultCode == TRANSACTION_RESULT_CODE) { + paystackIntentResponse = gson.fromJson( + data?.getStringExtra(TRANSACTION), + PaystackIntentResponse::class.java + ) + + processResponse(paystackIntentResponse) + } + else { + // handle invalid result code + } + } + + private fun processResponse(response: PaystackIntentResponse) { + + val terminalResponse: TerminalResponse = response.intentResponse + val transactionResponse = gson.fromJson( + terminalResponse.data, + TransactionResponse::class.java + ) + + transactionStatus = transactionResponse.reference + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/link-method-channel/config.yml b/src/doc/guides/terminal-flutter/link-method-channel/config.yml new file mode 100644 index 0000000..e57284b --- /dev/null +++ b/src/doc/guides/terminal-flutter/link-method-channel/config.yml @@ -0,0 +1,2 @@ +languages: + - dart \ No newline at end of file diff --git a/src/doc/guides/terminal-flutter/link-method-channel/index.dart b/src/doc/guides/terminal-flutter/link-method-channel/index.dart new file mode 100644 index 0000000..06280fc --- /dev/null +++ b/src/doc/guides/terminal-flutter/link-method-channel/index.dart @@ -0,0 +1,27 @@ +static const _methodChannel = + MethodChannel('com.example.sample_registration/payment'); + +Future makePayment() async { + String reference = ''; + try { + var options = { + 'amount': 5000, + 'supplementaryData': { + 'developerSuppliedText': null, + 'developerSuppliedImageUrlPath': + "https://assets.paystack.com/assets/img/press/Terminal-x-Bature-x-World-Cup-Receipt.jpg", + 'barcodeOrQrcodeImageText': null, + 'textImageType': null + } + }; + reference = await _methodChannel.invokeMethod('makePayment', options); + print("Reference: $reference"); + } on PlatformException catch (e) { + print("Error: $e"); + reference = ''; + } + + setState(() { + _transactionReference = reference; + }); + } \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-models/config.yml b/src/doc/guides/terminal-react-native/create-models/config.yml new file mode 100644 index 0000000..d2b7b48 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-models/config.yml @@ -0,0 +1,3 @@ +type: single-lang +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-models/paystack-intent-response.java b/src/doc/guides/terminal-react-native/create-models/paystack-intent-response.java new file mode 100644 index 0000000..e8af5ff --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-models/paystack-intent-response.java @@ -0,0 +1,25 @@ + +// PaystackIntentResponse.java +public class PaystackIntentResponse { + private final String intentkey; + private final int intentResponseCode; + private final TerminalResponse intentResponse; + + public PaystackIntentResponse(String intentkey, int intentResponseCode, TerminalResponse intentResponse) { + this.intentkey = intentkey; + this.intentResponseCode = intentResponseCode; + this.intentResponse = intentResponse; + } + + public String getIntentkey() { + return intentkey; + } + + public int getIntentResponseCode() { + return intentResponseCode; + } + + public TerminalResponse getIntentResponse() { + return intentResponse; + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-models/terminal-response.java b/src/doc/guides/terminal-react-native/create-models/terminal-response.java new file mode 100644 index 0000000..b5a481f --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-models/terminal-response.java @@ -0,0 +1,25 @@ + +// TerminalResponse.java +public class TerminalResponse { + private final String statusCode; + private final String message; + private final String data; + + public TerminalResponse(String statusCode, String message, String data) { + this.statusCode = statusCode; + this.message = message; + this.data = data; + } + + public String getStatusCode() { + return statusCode; + } + + public String getMessage() { + return message; + } + + public String getData() { + return data; + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-models/transaction-request.java b/src/doc/guides/terminal-react-native/create-models/transaction-request.java new file mode 100644 index 0000000..bc42d54 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-models/transaction-request.java @@ -0,0 +1,19 @@ + +// TransactionRequest.java +import java.util.Map; + +public class TransactionRequest { + private int amount; + private Map metadata; + + public TransactionRequest() { + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-models/transaction-response.java b/src/doc/guides/terminal-react-native/create-models/transaction-response.java new file mode 100644 index 0000000..538a172 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-models/transaction-response.java @@ -0,0 +1,61 @@ + +// TransactionResponse.java +import com.google.gson.annotations.SerializedName; + +public class TransactionResponse { + private final String id; + private final int amount; + private final String reference; + private final String status; + private final String currency; + @SerializedName("country_code") + private final String countryCode; + @SerializedName("paid_at") + private final String paidAt; + private final String terminal; + + public TransactionResponse( + String id, int amount, String reference, String status, + String currency, String countryCode, String paidAt, String terminal) { + this.id = id; + this.amount = amount; + this.reference = reference; + this.status = status; + this.currency = currency; + this.countryCode = countryCode; + this.paidAt = paidAt; + this.terminal = terminal; + } + + public String getId() { + return id; + } + + public int getAmount() { + return amount; + } + + public String getReference() { + return reference; + } + + public String getStatus() { + return status; + } + + public String getCurrency() { + return currency; + } + + public String getCountryCode() { + return countryCode; + } + + public String getPaidAt() { + return paidAt; + } + + public String getTerminal() { + return terminal; + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-callback/config.yml b/src/doc/guides/terminal-react-native/create-module/paystack-module-callback/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-callback/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-callback/index.java b/src/doc/guides/terminal-react-native/create-module/paystack-module-callback/index.java new file mode 100644 index 0000000..70933b9 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-callback/index.java @@ -0,0 +1,34 @@ +import android.app.Activity; +import android.content.Intent; + +import com.facebook.react.bridge.ActivityEventListener; +import com.facebook.react.bridge.BaseActivityEventListener; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.google.gson.Gson; + +public class PaystackModule extends ReactContextBaseJavaModule { + + private final Gson gson = new Gson(); + private Callback mCallback; + + private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { + @Override + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { + PaystackIntentResponse paystackIntentResponse; + TerminalResponse terminalResponse; + + paystackIntentResponse = gson.fromJson( + data != null ? data.getStringExtra("com.paystack.pos.TRANSACT") : null, + PaystackIntentResponse.class); + terminalResponse = paystackIntentResponse.getIntentResponse(); + TransactionResponse transactionResponse = gson.fromJson( + terminalResponse.getData(), + TransactionResponse.class); + mCallback.invoke(transactionResponse.getReference()); + } + }; + + // the rest of the code previously added +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-final/config.yml b/src/doc/guides/terminal-react-native/create-module/paystack-module-final/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-final/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-final/index.java b/src/doc/guides/terminal-react-native/create-module/paystack-module-final/index.java new file mode 100644 index 0000000..7a293d4 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-final/index.java @@ -0,0 +1,64 @@ +import android.app.Activity; +import android.content.Intent; +import android.util.Log; + +import com.facebook.react.bridge.ActivityEventListener; +import com.facebook.react.bridge.BaseActivityEventListener; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.google.gson.Gson; + +public class PaystackModule extends ReactContextBaseJavaModule { + + private final Gson gson = new Gson(); + private Callback mCallback; + + private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { + @Override + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { + PaystackIntentResponse paystackIntentResponse; + TerminalResponse terminalResponse; + + paystackIntentResponse = gson.fromJson( + data != null ? data.getStringExtra("com.paystack.pos.TRANSACT") : null, + PaystackIntentResponse.class); + terminalResponse = paystackIntentResponse.getIntentResponse(); + TransactionResponse transactionResponse = gson.fromJson( + terminalResponse.getData(), + TransactionResponse.class); + mCallback.invoke(transactionResponse.getReference()); + } + }; + + PaystackModule(ReactApplicationContext context) { + super(context); + + context.addActivityEventListener(mActivityEventListener); + } + + @Override + public String getName() { + return "PaystackModule"; + } + + @ReactMethod + public void makePayment(int amount, Callback callback) { + TransactionRequest transactionRequest = new TransactionRequest(); + transactionRequest.setAmount(amount); + + Activity currentActivity = getCurrentActivity(); + mCallback = callback; + + try { + final Intent transactionIntent = new Intent(Intent.ACTION_VIEW); + transactionIntent.setPackage("com.paystack.pos"); + transactionIntent.putExtra("com.paystack.pos.TRANSACT", + gson.toJson(transactionRequest)); + currentActivity.startActivityForResult(transactionIntent, 1); + } catch (Exception e) { + Log.d("PaystackModule", "Error: " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-make-payment/config.yml b/src/doc/guides/terminal-react-native/create-module/paystack-module-make-payment/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-make-payment/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-make-payment/index.java b/src/doc/guides/terminal-react-native/create-module/paystack-module-make-payment/index.java new file mode 100644 index 0000000..7d580cc --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-make-payment/index.java @@ -0,0 +1,18 @@ +@ReactMethod +public void makePayment(int amount, Callback callback) { + TransactionRequest transactionRequest = new TransactionRequest(); + transactionRequest.setAmount(amount); + + Activity currentActivity = getCurrentActivity(); + mCallback = callback; + + try { + final Intent transactionIntent = new Intent(Intent.ACTION_VIEW); + transactionIntent.setPackage("com.paystack.pos"); + transactionIntent.putExtra("com.paystack.pos.TRANSACT", + gson.toJson(transactionRequest)); + currentActivity.startActivityForResult(transactionIntent, 1); + } catch (Exception e) { + Log.d("PaystackModule", "Error: " + e.getMessage()); + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-register/config.yml b/src/doc/guides/terminal-react-native/create-module/paystack-module-register/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-register/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-register/index.java b/src/doc/guides/terminal-react-native/create-module/paystack-module-register/index.java new file mode 100644 index 0000000..e4cc3ab --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-register/index.java @@ -0,0 +1,5 @@ +PaystackModule(ReactApplicationContext context) { + super(context); + + context.addActivityEventListener(mActivityEventListener); +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-setup/config.yml b/src/doc/guides/terminal-react-native/create-module/paystack-module-setup/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-setup/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-module/paystack-module-setup/index.java b/src/doc/guides/terminal-react-native/create-module/paystack-module-setup/index.java new file mode 100644 index 0000000..7b5dc89 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-module/paystack-module-setup/index.java @@ -0,0 +1,14 @@ +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; + +public class PaystackModule extends ReactContextBaseJavaModule { + + PaystackModule(ReactApplicationContext context) { + super(context); + } + + @Override + public String getName() { + return "PaystackModule"; + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-package/config.yml b/src/doc/guides/terminal-react-native/create-package/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-package/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/create-package/index.java b/src/doc/guides/terminal-react-native/create-package/index.java new file mode 100644 index 0000000..55d0e23 --- /dev/null +++ b/src/doc/guides/terminal-react-native/create-package/index.java @@ -0,0 +1,24 @@ +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class SampleRegistrationPackage implements ReactPackage { + + @Override + public List createViewManagers(ReactApplicationContext reactApplicationContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules(ReactApplicationContext reactApplicationContext) { + List modules = new ArrayList<>(); + modules.add(new PaystackModule(reactApplicationContext)); + + return modules; + } +} \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/expose-package/config.yml b/src/doc/guides/terminal-react-native/expose-package/config.yml new file mode 100644 index 0000000..5054c75 --- /dev/null +++ b/src/doc/guides/terminal-react-native/expose-package/config.yml @@ -0,0 +1,2 @@ +languages: + - java \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/expose-package/index.java b/src/doc/guides/terminal-react-native/expose-package/index.java new file mode 100644 index 0000000..1d6605b --- /dev/null +++ b/src/doc/guides/terminal-react-native/expose-package/index.java @@ -0,0 +1 @@ +packages.add(new MyAppPackage()); \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/use-module/initialization/config.yml b/src/doc/guides/terminal-react-native/use-module/initialization/config.yml new file mode 100644 index 0000000..745904c --- /dev/null +++ b/src/doc/guides/terminal-react-native/use-module/initialization/config.yml @@ -0,0 +1,2 @@ +languages: + - js \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/use-module/initialization/index.js b/src/doc/guides/terminal-react-native/use-module/initialization/index.js new file mode 100644 index 0000000..2967e80 --- /dev/null +++ b/src/doc/guides/terminal-react-native/use-module/initialization/index.js @@ -0,0 +1,2 @@ +import { NativeModules } from 'react-native'; +const { PaystackModule } = NativeModules; \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/use-module/usage/config.yml b/src/doc/guides/terminal-react-native/use-module/usage/config.yml new file mode 100644 index 0000000..745904c --- /dev/null +++ b/src/doc/guides/terminal-react-native/use-module/usage/config.yml @@ -0,0 +1,2 @@ +languages: + - js \ No newline at end of file diff --git a/src/doc/guides/terminal-react-native/use-module/usage/index.js b/src/doc/guides/terminal-react-native/use-module/usage/index.js new file mode 100644 index 0000000..6f86d53 --- /dev/null +++ b/src/doc/guides/terminal-react-native/use-module/usage/index.js @@ -0,0 +1,6 @@ +const onPress = async () => { + PaystackModule.makePayment(3000, transactionReference => { + console.log('transaction ref: ', transactionReference); + + }); +}; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 6bd2d18..19f1e1a 100644 --- a/src/index.js +++ b/src/index.js @@ -34,13 +34,13 @@ function getAllFiles(directory, directoryContent) { return directoryContent } -function getEventFileContent(directory) { +function getSingleLanguageFileContent(language, directory) { const files = fs.readdirSync(directory); let exportVariables = [] let content = "" files.forEach((file) => { - if (path.extname(file) === ".json") { + if (path.extname(file) === `.${language}`) { try { const filename = file.split(".")[0].replace(/-/g, "_") const data = fs.readFileSync(path.join(directory, file), 'utf8'); @@ -124,8 +124,8 @@ function writeToFile(config, directory, tag) { makeDirectory(parent) - content = allConfig.type && allConfig.type === "event" - ? getEventFileContent(directory) + content = allConfig.type && allConfig.type === "event" || allConfig.type === "single-lang" + ? getSingleLanguageFileContent(allConfig.languages[0], directory) : readFiles(allConfig.languages, directory) } else if (tag === "api") {