diff --git a/android/build.gradle b/android/build.gradle index 06ed3c9bb..dc678100f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.library' - +repositories { + mavenCentral() +} android { compileSdkVersion 23 buildToolsVersion "24.0.0" @@ -14,6 +16,6 @@ android { dependencies { compile 'com.facebook.react:react-native:0.20.+' - compile 'com.razorpay:checkout:1.0.2' + compile 'com.razorpay:checkout:1.2.0' } diff --git a/android/src/main/java/com/razorpay/rn/RazorpayModule.java b/android/src/main/java/com/razorpay/rn/RazorpayModule.java index 0e6d5846a..8ec9a9a3a 100644 --- a/android/src/main/java/com/razorpay/rn/RazorpayModule.java +++ b/android/src/main/java/com/razorpay/rn/RazorpayModule.java @@ -16,6 +16,9 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.razorpay.CheckoutActivity; +import com.razorpay.PaymentData; +import com.razorpay.PaymentResultWithDataListener; +import com.razorpay.Checkout; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -29,7 +32,7 @@ -public class RazorpayModule extends ReactContextBaseJavaModule implements ActivityEventListener { +public class RazorpayModule extends ReactContextBaseJavaModule implements ActivityEventListener, PaymentResultWithDataListener { public static final int RZP_REQUEST_CODE = 72967729; @@ -56,7 +59,8 @@ public void open(ReadableMap options) { JSONObject optionsJSON = readableMapToJson(options); Intent intent = new Intent(currentActivity, CheckoutActivity.class); intent.putExtra("OPTIONS", optionsJSON.toString()); - currentActivity.startActivityForResult(intent, RZP_REQUEST_CODE); + intent.putExtra("FRAMEWORK", "react_native"); + currentActivity.startActivityForResult(intent, Checkout.RZP_REQUEST_CODE); } catch (Exception e) {} } @@ -107,34 +111,14 @@ private static JSONObject readableMapToJson(ReadableMap readableMap) { } return jsonObject; } + + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { + onActivityResult(requestCode, resultCode, data); + } @Override public void onActivityResult(int requestCode, int resultCode, Intent data){ - if (requestCode != RZP_REQUEST_CODE) return; - String result = null; - if (data != null) { - Bundle extras = data.getExtras(); - if (extras != null) { - result = extras.getString("RESULT"); - } - } - if (resultCode == 1) { - try { - JSONObject resultJson = new JSONObject(result); - WritableMap successParams = Arguments.createMap(); - successParams.putString(MAP_KEY_PAYMENT_ID, resultJson.getString(MAP_KEY_RZP_PAYMENT_ID)); - sendEvent("Razorpay::PAYMENT_SUCCESS", successParams); - } catch(Exception e){} - } - else { - if (resultCode == Activity.RESULT_CANCELED) { - result = "Payment Cancelled"; - } - WritableMap errorParams = Arguments.createMap(); - errorParams.putInt(MAP_KEY_ERROR_CODE, resultCode); - errorParams.putString(MAP_KEY_ERROR_DESC, result); - sendEvent("Razorpay::PAYMENT_ERROR", errorParams); - } + Checkout.handleActivityResult(getCurrentActivity(), requestCode, resultCode, data, this); } private void sendEvent(String eventName, @Nullable WritableMap params) { @@ -143,4 +127,19 @@ private void sendEvent(String eventName, @Nullable WritableMap params) { .emit(eventName, params); } + @Override + public void onPaymentSuccess(String razorpayPaymentId, PaymentData paymentData) { + WritableMap successParams = Arguments.createMap(); + successParams.putString(MAP_KEY_PAYMENT_ID, razorpayPaymentId); + sendEvent("Razorpay::PAYMENT_SUCCESS", successParams); + } + + @Override + public void onPaymentError(int code, String description, PaymentData paymentData) { + WritableMap errorParams = Arguments.createMap(); + errorParams.putInt(MAP_KEY_ERROR_CODE, code); + errorParams.putString(MAP_KEY_ERROR_DESC, description); + sendEvent("Razorpay::PAYMENT_ERROR", errorParams); + } + } diff --git a/example/android/app/src/main/java/com/example/MainApplication.java b/example/android/app/src/main/java/com/example/MainApplication.java index 0e772ca0a..94bab8835 100644 --- a/example/android/app/src/main/java/com/example/MainApplication.java +++ b/example/android/app/src/main/java/com/example/MainApplication.java @@ -28,6 +28,11 @@ protected List getPackages() { new RazorpayPackage() ); } + + @Override + protected String getJSMainModuleName() { + return "index"; + } }; @Override diff --git a/example/index.js b/example/index.js index 6b9a66983..83f97f075 100644 --- a/example/index.js +++ b/example/index.js @@ -66,4 +66,4 @@ const styles = StyleSheet.create({ } }); -AppRegistry.registerComponent('example', () => example); +AppRegistry.registerComponent('example', () => example); \ No newline at end of file diff --git a/package.json b/package.json index 67d3c2ec7..d4aa5ac33 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,3 @@ - { "name": "react-native-razorpay", "version": "1.0.0", @@ -19,5 +18,5 @@ ], "author": "Razorpay Developers (https://razorpay.com/)", "license": "MIT", - "homepage" : "https://github.com/razorpay/react-native-razorpay#readme" + "homepage": "https://github.com/razorpay/react-native-razorpay#readme" }