Skip to content

Commit

Permalink
Merge pull request #9 from razorpay/f/android_update
Browse files Browse the repository at this point in the history
Update Checkout Android SDK to v1.2.0, add compatibilty changes for RN 0.39
  • Loading branch information
Akshay Bhalotia authored Dec 12, 2016
2 parents b88f34c + d1453d9 commit b70089b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.library'

repositories {
mavenCentral()
}
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
Expand All @@ -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'
}

53 changes: 26 additions & 27 deletions android/src/main/java/com/razorpay/rn/RazorpayModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ protected List<ReactPackage> getPackages() {
new RazorpayPackage()
);
}

@Override
protected String getJSMainModuleName() {
return "index";
}
};

@Override
Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ const styles = StyleSheet.create({
}
});

AppRegistry.registerComponent('example', () => example);
AppRegistry.registerComponent('example', () => example);
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"name": "react-native-razorpay",
"version": "1.0.0",
Expand All @@ -19,5 +18,5 @@
],
"author": "Razorpay Developers <[email protected]> (https://razorpay.com/)",
"license": "MIT",
"homepage" : "https://github.com/razorpay/react-native-razorpay#readme"
"homepage": "https://github.com/razorpay/react-native-razorpay#readme"
}

0 comments on commit b70089b

Please sign in to comment.