package com.geored.gui; import android.app.Activity; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.LinearLayout; import com.geored.rest.R; import com.paypal.android.MEP.CheckoutButton; import com.paypal.android.MEP.PayPal; import com.paypal.android.MEP.PayPalActivity; import com.paypal.android.MEP.PayPalPayment; import com.paypal.android.MEP.PayPalAdvancedPayment; import com.paypal.android.MEP.PayPalInvoiceData; import com.paypal.android.MEP.PayPalInvoiceItem; import com.paypal.android.MEP.PayPalReceiverDetails; public class PagarPayPalActivity extends Activity implements OnClickListener { // The PayPal server to be used - can also be ENV_NONE and ENV_LIVE private static final int server = PayPal.ENV_SANDBOX; // The ID of your application that you received from PayPal private static final String appID = "APP-80W284485P519543T"; protected static final int INITIALIZE_SUCCESS = 0; protected static final int INITIALIZE_FAILURE = 1; CheckoutButton launchSimplePayment; LinearLayout layoutSimplePayment; @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } Handler hRefresh = new Handler(){ @Override public void handleMessage(Message msg) { switch(msg.what){ case INITIALIZE_SUCCESS: setupButtons(); break; case INITIALIZE_FAILURE: showFailure(); break; } } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pagarpaypal); layoutSimplePayment = ((LinearLayout)findViewById(R.id.layoutSimplePayment)); Thread libraryInitializationThread = new Thread() { public void run() { initLibrary(); // The library is initialized so let's create our CheckoutButton and update the UI. if (PayPal.getInstance().isLibraryInitialized()) { hRefresh.sendEmptyMessage(INITIALIZE_SUCCESS); } else { hRefresh.sendEmptyMessage(INITIALIZE_FAILURE); } } }; libraryInitializationThread.start(); } private void initLibrary() { PayPal pp = PayPal.getInstance(); // If the library is already initialized, then we don't need to initialize it again. if(pp == null) { // This is the main initialization call that takes in your Context, the Application ID, and the server you would like to connect to. pp = PayPal.initWithAppID(this, appID, server); // -- These are required settings. pp.setLanguage("en_US"); // Sets the language for the library. // -- // -- These are a few of the optional settings. // Sets the fees payer. If there are fees for the transaction, this person will pay for them. Possible values are FEEPAYER_SENDER, // FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and FEEPAYER_SECONDARYONLY. pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER); // Set to true if the transaction will require shipping. pp.setShippingEnabled(true); // Dynamic Amount Calculation allows you to set tax and shipping amounts based on the user's shipping address. Shipping must be // enabled for Dynamic Amount Calculation. This also requires you to create a class that implements PaymentAdjuster and Serializable. pp.setDynamicAmountCalculationEnabled(false); // -- } } public void setupButtons() { PayPal pp = PayPal.getInstance(); // Get the CheckoutButton. There are five different sizes. The text on the button can either be of type TEXT_PAY or TEXT_DONATE. launchSimplePayment = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY); // You'll need to have an OnClickListener for the CheckoutButton. For this application, MPL_Example implements OnClickListener and we // have the onClick() method below. launchSimplePayment.setOnClickListener((android.view.View.OnClickListener) this); // The CheckoutButton is an android LinearLayout so we can add it to our display like any other View. layoutSimplePayment.addView(launchSimplePayment); // Get the CheckoutButton. There are five different sizes. The text on the button can either be of type TEXT_PAY or TEXT_DONATE. //launchParallelPayment = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY); // You'll need to have an OnClickListener for the CheckoutButton. For this application, MPL_Example implements OnClickListener and we // have the onClick() method below. //launchParallelPayment.setOnClickListener(this); // The CheckoutButton is an android LinearLayout so we can add it to our display like any other View. //layoutSplitPayment.addView(launchParallelPayment); // Get the CheckoutButton. There are five different sizes. The text on the button can either be of type TEXT_PAY or TEXT_DONATE. //launchChainedPayment = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY); // You'll need to have an OnClickListener for the CheckoutButton. For this application, MPL_Example implements OnClickListener and we // have the onClick() method below. //launchChainedPayment.setOnClickListener(this); // The CheckoutButton is an android LinearLayout so we can add it to our display like any other View. //layoutChainedPayment.addView(launchChainedPayment); // Get the CheckoutButton. There are five different sizes. The text on the button can either be of type TEXT_PAY or TEXT_DONATE. //launchPreapproval = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY); // You'll need to have an OnClickListener for the CheckoutButton. For this application, MPL_Example implements OnClickListener and we // have the onClick() method below. //launchPreapproval.setOnClickListener(this); // The CheckoutButton is an android LinearLayout so we can add it to our display like any other View. //layoutPreapproval.addView(launchPreapproval); // Show our labels and the preapproval EditText. //labelSimplePayment.setVisibility(View.VISIBLE); //labelParallelPayment.setVisibility(View.VISIBLE); //labelChainedPayment.setVisibility(View.VISIBLE); //labelPreapproval.setVisibility(View.VISIBLE); //enterPreapprovalKey.setVisibility(View.VISIBLE); //labelKey.setVisibility(View.VISIBLE); //appVersion.setVisibility(View.VISIBLE); //info.setText(""); //info.setVisibility(View.GONE); } /** * Show a failure message because initialization failed. */ public void showFailure() { //title.setText("FAILURE"); //info.setText("Could not initialize the PayPal library."); //title.setVisibility(View.VISIBLE); //info.setVisibility(View.VISIBLE); } }