Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created July 18, 2011 21:21
Show Gist options
  • Save dawsontoth/1090694 to your computer and use it in GitHub Desktop.
Save dawsontoth/1090694 to your computer and use it in GitHub Desktop.
??
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
*/
package ti.modules.titanium.paypal;
import java.math.BigDecimal;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.Log;
import org.appcelerator.titanium.util.TiActivityResultHandler;
import org.appcelerator.titanium.util.TiConfig;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiUIView;
import org.appcelerator.titanium.TiC;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalPayment;
public class PaypalButton extends TiUIView implements OnClickListener
{
// Debug helpers
private static final String LCAT = "PaypalButton";
private static final boolean DBG = TiConfig.DEBUG;
Activity activity;
// Module vars
CheckoutButton button;
public PaypalButton(TiViewProxy proxy) {
super(proxy);
activity = proxy.getTiContext().getActivity();
PayPal pp = PayPal.getInstance();
if (pp == null) {
pp = PayPal.initWithAppID(activity, "APP-80W284485P519543T", PayPal.ENV_SANDBOX);
pp.setLanguage("en_US");
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
}
if (pp.isLibraryInitialized()) {
button = pp.getCheckoutButton(activity,
PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY);
setNativeView(button);
}
}
@Override
public boolean fireEvent(String eventName, KrollDict data) {
if (eventName.equals(TiC.EVENT_CLICK)) {
Log.d(LCAT, "onClick fired!");
}
return super.fireEvent(eventName, data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment