public void sendToPayleven(View v) { int amount = (int) (Math.round(this.getAmount() * 100)); // in cents TransactionRequestBuilder builder = new TransactionRequestBuilder(amount, Currency.getInstance("EUR")); TransactionRequest request = builder.createTransactionRequest(); String orderId = "42"; PaylevenApi.initiatePayment(this, orderId, request); }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { PaylevenApi.handleIntent(requestCode, data, new PaylevenResultHandler()); switch (requestCode) { case TicketSelect.CODE_TICKET: switch (resultCode) { case Activity.RESULT_CANCELED: // Back to start Intent i = new Intent(this, Start.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); this.startActivity(i); break; case Activity.RESULT_OK: TicketInput.requestTicketSwitch(SessionData.currentSession(this).getCurrentTicket()); this.finish(); break; } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle state) { super.onCreate(state); boolean open = false; if (state != null) { this.ticket = (Ticket) state.getSerializable("ticket"); this.payments = new ArrayList<Payment>(); int count = state.getInt("payCount"); for (int i = 0; i < count; i++) { Payment p = (Payment) state.getSerializable("payment" + i); this.payments.add(p); } open = state.getBoolean("drawerOpen"); this.printEnabled = state.getBoolean("printEnabled"); } else { this.ticket = ticketInit; ticketInit = null; this.payments = new ArrayList<Payment>(); this.printEnabled = true; } setContentView(R.layout.payments); this.scroll = (ScrollView) this.findViewById(R.id.scroll); this.scrollHandler = new Handler(this); this.keyboard = (NumKeyboard) this.findViewById(R.id.numkeyboard); keyboard.setKeyHandler(new Handler(this)); this.input = (EditText) this.findViewById(R.id.input); this.giveBack = (TextView) this.findViewById(R.id.give_back); this.ticketTotal = (TextView) this.findViewById(R.id.ticket_total); this.ticketRemaining = (TextView) this.findViewById(R.id.ticket_remaining); this.paymentModes = (Gallery) this.findViewById(R.id.payment_modes); PaymentModesAdapter adapt = new PaymentModesAdapter(PaymentMode.defaultModes(this)); this.paymentModes.setAdapter(adapt); this.paymentModes.setOnItemSelectedListener(this); this.paymentModes.setSelection(0, false); this.currentMode = PaymentMode.defaultModes(this).get(0); String total = this.getString(R.string.ticket_total, this.ticket.getTotalPrice()); this.slidingHandle = (ImageView) this.findViewById(R.id.handle); this.slidingDrawer = (SlidingDrawer) this.findViewById(R.id.drawer); this.slidingDrawer.setOnDrawerOpenListener( new OnDrawerOpenListener() { @Override public void onDrawerOpened() { slidingHandle.setImageResource(R.drawable.slider_close); } }); slidingDrawer.setOnDrawerCloseListener( new OnDrawerCloseListener() { @Override public void onDrawerClosed() { slidingHandle.setImageResource(R.drawable.slider_open); } }); if (open) { this.slidingDrawer.open(); } this.paymentsList = (ListView) this.findViewById(R.id.payments_list); PaymentsAdapter padapt = new PaymentsAdapter(this.payments, this); this.paymentsList.setAdapter(padapt); this.ticketTotal.setText(total); this.updateDisplayToMode(); this.refreshRemaining(); this.refreshGiveBack(); this.refreshInput(); // Init printer connection this.printer = new PrinterConnection(new Handler(this)); try { if (!this.printer.connect(this)) { this.printer = null; } } catch (IOException e) { Log.w(LOG_TAG, "Unable to connect to printer", e); Error.showError(R.string.print_no_connexion, this); // Set null to cancel printing this.printer = null; } // Init Payleven API PaylevenApi.configure("edaffb929bd34aa78122b2d15a36a5c7"); // Update UI based upon settings View paylevenBtn = this.findViewById(R.id.btnPayleven); if (Configure.getPayleven(this)) { paylevenBtn.setVisibility(View.VISIBLE); } else { paylevenBtn.setVisibility(View.INVISIBLE); } }