<commit_before>package com.surialabs.rn.braintree;

import android.content.Intent;
import android.content.Context;
import android.app.Activity;

import com.braintreepayments.api.PaymentRequest;
import com.braintreepayments.api.models.PaymentMethodNonce;
import com.braintreepayments.api.BraintreePaymentActivity;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class Braintree extends ReactContextBaseJavaModule {
  private static final int PAYMENT_REQUEST = 1;

  private Callback successCallback;
  private Callback errorCallback;

  private Context mActivityContext;

  public Braintree(ReactApplicationContext reactContext, Context activityContext) {
    super(reactContext);
    this.mActivityContext = activityContext;
  }

  @Override
  public String getName() {
    return "Braintree";
  }

  @ReactMethod
  public void paymentRequest(final String clientToken, final Callback successCallback, final Callback errorCallback) {
    this.successCallback = successCallback;
    this.errorCallback = errorCallback;

    PaymentRequest paymentRequest = new PaymentRequest()
    .clientToken(clientToken);

    ((Activity)this.mActivityContext).startActivityForResult(
      paymentRequest.getIntent(this.mActivityContext),
      PAYMENT_REQUEST
    );
  }

  public void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == PAYMENT_REQUEST) {
      switch (resultCode) {
        case Activity.RESULT_OK:
          PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
            BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
          );
          this.successCallback.invoke(paymentMethodNonce.getNonce());
          break;
        case BraintreePaymentActivity.BRAINTREE_RESULT_DEVELOPER_ERROR:
        case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_ERROR:
        case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_UNAVAILABLE:
          this.successCallback.invoke(
            data.getSerializableExtra(BraintreePaymentActivity.EXTRA_ERROR_MESSAGE)
          );
          break;
        default:
          break;
      }
    }
  }
}<commit_msg>Call error callback instead of success callback on error<commit_after>package com.surialabs.rn.braintree;

import android.content.Intent;
import android.content.Context;
import android.app.Activity;

import com.braintreepayments.api.PaymentRequest;
import com.braintreepayments.api.models.PaymentMethodNonce;
import com.braintreepayments.api.BraintreePaymentActivity;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class Braintree extends ReactContextBaseJavaModule {
  private static final int PAYMENT_REQUEST = 1;

  private Callback successCallback;
  private Callback errorCallback;

  private Context mActivityContext;

  public Braintree(ReactApplicationContext reactContext, Context activityContext) {
    super(reactContext);
    this.mActivityContext = activityContext;
  }

  @Override
  public String getName() {
    return "Braintree";
  }

  @ReactMethod
  public void paymentRequest(final String clientToken, final Callback successCallback, final Callback errorCallback) {
    this.successCallback = successCallback;
    this.errorCallback = errorCallback;

    PaymentRequest paymentRequest = new PaymentRequest()
    .clientToken(clientToken);

    ((Activity)this.mActivityContext).startActivityForResult(
      paymentRequest.getIntent(this.mActivityContext),
      PAYMENT_REQUEST
    );
  }

  public void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == PAYMENT_REQUEST) {
      switch (resultCode) {
        case Activity.RESULT_OK:
          PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
            BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
          );
          this.successCallback.invoke(paymentMethodNonce.getNonce());
          break;
        case BraintreePaymentActivity.BRAINTREE_RESULT_DEVELOPER_ERROR:
        case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_ERROR:
        case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_UNAVAILABLE:
          this.errorCallback.invoke(
            data.getSerializableExtra(BraintreePaymentActivity.EXTRA_ERROR_MESSAGE)
          );
          break;
        default:
          break;
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.0688320068832007, 'fraction_numerical': 0.00043020004302000433, 'mean_word_length': 4.160932297447281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213780', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1267, 'n_words': 238}