Wiki
Clone wikiXam.Paypal.Droid / Home
Xamarin Android PayPal binding library
This is a Xamarin.Android binding library for Paypal SDK.
Last version is available on NuGet: Xam.PayPal.Droid
Please see PayPalSdk for Android onGitHub for SDK documentation.
A simple tutorial can be found on markjackmilian.net
Quick startup
- Add Nuget Package (package will add necessary references)
- Set Java Heap Size to 1G
- In application node if your Manifest add:
<service android:name="com.paypal.android.sdk.payments.PayPalService" android:exported="false" /> <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
You are ready to go!
Example of activity
[Activity(Label = "xam.paypal.test", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
private PayPalConfiguration config = new PayPalConfiguration()
.Environment(PayPalConfiguration.EnvironmentSandbox)
.ClientId("YOUR CLIENT ID HERE");
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.myButton);
button.Click += this.ButtonOnClick;
// start paypal service
var intent = new Intent(this, typeof(PayPalService));
intent.PutExtra(PayPalService.ExtraPaypalConfiguration, config);
this.StartService(intent);
}
private void ButtonOnClick(object sender, EventArgs eventArgs)
{
var payment = new PayPalPayment(new BigDecimal("2.45"), "USD", "the item",
PayPalPayment.PaymentIntentSale);
var intent = new Intent(this, typeof(PaymentActivity));
intent.PutExtra(PayPalService.ExtraPaypalConfiguration, config);
intent.PutExtra(PaymentActivity.ExtraPayment, payment);
this.StartActivityForResult(intent, 0);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Ok)
{
var confirm = data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation);
if (confirm != null)
{
try
{
Log.Info("xam.paypal.test", confirm.ToString());
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
}
catch (JSONException e)
{
Log.Error("xam.paypal.test", "something wen really wrong here: ", e);
}
}
}
else if (resultCode == Result.Canceled)
{
Log.Info("xam.paypal.test", "Canceled.");
}
else if ((int)resultCode == PaymentActivity.ResultExtrasInvalid)
{
Log.Info("xam.paypal.test", "Invalid Payment or PayPalConfiguration.");
}
}
protected override void OnDestroy()
{
this.StopService(new Intent(this, typeof(PayPalService)));
base.OnDestroy();
}
}
##Note about versioning## Master branch contains the last published version on Nuget and has every previous version tagged. The version is based on PayPal sdk version:
- First three number are PayPalSdk version.
- Fourth number is for binding library revision.
Have fun!
##Follow Me
- Twitter: @markjackmilian
- MyBlog: markjackmilian.net
- Linkedin: linkedin
Updated