Android paypal帐户:我如何检查用户是否已经是会员

时间:2016-11-01 09:50:06

标签: android paypal

我有一个应用程序,用户可以通过支付Paypal帐户订阅会员资格。如何回复确认用户是否已支付订阅费用?请帮我一些代码或编辑我的代码。我如何知道用户是否已订阅会员资格或尚未订阅?这是我的代码。

public class MainActivity extends Activity {

private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;

// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID = "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp";

private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;

private static PayPalConfiguration config = new PayPalConfiguration()
        .environment(CONFIG_ENVIRONMENT)
        .clientId(CONFIG_CLIENT_ID)
        // The following are only used in PayPalFuturePaymentActivity.
        .merchantName("Hipster Store")
        .merchantPrivacyPolicyUri(
                Uri.parse("https://www.example.com/privacy"))
        .merchantUserAgreementUri(
                Uri.parse("https://www.example.com/legal"));

PayPalPayment thingToBuy;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(this, PayPalService.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    startService(intent);
    //Intent intent = new Intent(this, PayPalService.class);
    //intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    //startService(intent);


    findViewById(R.id.order).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            thingToBuy = new PayPalPayment(new BigDecimal("1"), "USD",
                    "HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
            Intent intent = new Intent(MainActivity.this,
                    PaymentActivity.class);

            intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

            startActivityForResult(intent, REQUEST_CODE_PAYMENT);
        }
    });

}

public void onFuturePaymentPressed(View pressed) {
    Intent intent = new Intent(MainActivity.this,
            PayPalFuturePaymentActivity.class);

    startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_PAYMENT) {
        if (resultCode == Activity.RESULT_OK) {
            PaymentConfirmation confirm = data
                    .getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if (confirm != null) {
                try {

                    System.out.println("Responseeee" + confirm);
                    Log.i("paymentExample", confirm.toJSONObject().toString());

                    System.out.println(confirm.toJSONObject().toString(4));
                    System.out.println(confirm.getPayment().toJSONObject()
                            .toString(4));

                    Toast.makeText(getApplicationContext(), "Order placed"+confirm.toString(),
                            Toast.LENGTH_LONG).show();

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            System.out.println("The user canceled.");
        } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
            System.out
                    .println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
        }
    } else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
        if (resultCode == Activity.RESULT_OK) {
            PayPalAuthorization auth = data
                    .getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
            if (auth != null) {
                try {
                    Log.e("FuturePaymentExample", auth.toJSONObject()
                            .toString(4));

                    String authorization_code = auth.getAuthorizationCode();
                    Log.e("FuturePaymentExample", authorization_code);

                    sendAuthorizationToServer(auth);
                    Toast.makeText(getApplicationContext(),
                            "Future Payment code received from PayPal",
                            Toast.LENGTH_LONG).show();

                } catch (JSONException e) {
                    Log.e("FuturePaymentExample",
                            "an extremely unlikely failure occurred: ", e);
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.e("FuturePaymentExample", "The user canceled.");
        } else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
            Log.e("FuturePaymentExample",
                    "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
        }
    }
}

private void sendAuthorizationToServer(PayPalAuthorization authorization) {

}

public void onFuturePaymentPurchasePressed(View pressed) {
    // Get the Application Correlation ID from the SDK
    String correlationId = PayPalConfiguration
            .getApplicationCorrelationId(this);

    Log.i("FuturePaymentExample", "Application Correlation ID: "
            + correlationId);

    // TODO: Send correlationId and transaction details to your server for
    // processing with
    // PayPal...
    Toast.makeText(getApplicationContext(),
            "App Correlation ID received from SDK", Toast.LENGTH_LONG)
            .show();
}

@Override
public void onDestroy() {
    // Stop service when done
    stopService(new Intent(this, PayPalService.class));
    super.onDestroy();
}
}

0 个答案:

没有答案