Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Switching from stripe payment gateway to flutter_ravepay on Android #16

Open
horizonltd opened this issue May 30, 2020 · 0 comments
Open

Comments

@horizonltd
Copy link

horizonltd commented May 30, 2020

I want to change from stripe payment gateway to flutter_ravepay, though I have try a lot of way but all to no vail.

Thanks.

public class PaymentActivity extends AppCompatActivity {

private String restaurantId, address, orderDetails;
private Button buttonPlaceOrder;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_payment);
    getSupportActionBar().setTitle("");

    // Get Order Data
    Intent intent = getIntent();
    restaurantId = intent.getStringExtra("restaurantId");
    address = intent.getStringExtra("address");
    orderDetails = intent.getStringExtra("orderDetails");

    final CardInputWidget mCardInputWidget = (CardInputWidget) findViewById(R.id.card_input_widget);

    buttonPlaceOrder = (Button) findViewById(R.id.button_place_order);
    buttonPlaceOrder.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("StaticFieldLeak")
        @Override
        public void onClick(View view) {
            final Card card = mCardInputWidget.getCard();
            if (card == null) {
                // Do not continue token creation.
                Toast.makeText(getApplicationContext(), "Card cannot be blank", Toast.LENGTH_LONG).show();
            } else {

                // Disable the Place Order Button
                setButtonPlaceOrder("LOADING...", false);

                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... voids) {
                       
                        Stripe stripe = new Stripe(getApplicationContext(), "STRIPE API KEY HERE");
                        stripe.createToken(
                                card,
                                new TokenCallback() {
                                    public void onSuccess(Token token) {
                                        // Make an order

                                        //Toast.makeText(getApplicationContext(), token.getId(), Toast.LENGTH_LONG).show();

                                       addOrder(token.getId());
                                    }
                                    public void onError(Exception error) {
                                        // Show localized error message
                                        Toast.makeText(getApplicationContext(),
                                                error.getLocalizedMessage(),
                                                Toast.LENGTH_LONG
                                        ).show();

                                        // Enable the Place Order Button
                                        setButtonPlaceOrder("PLACE ORDER", true);
                                    }
                                }
                        );

                        return null;
                    }
                }.execute();
            }
        }
    });
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant