This plugin is now deprecated as Paypal Mobile SDK its no longer supported in case that you want to implement paypal payments you can create your own native braintree implementation by checking this page for more details https://www.braintreepayments.com
PayPal Plugin for Xamarin.Forms
In MainActivity(Android)/AppDelegate(iOS) after "Forms.Init()" call the Init method with your PayPal config value
...
global::Xamarin.Forms.Forms.Init ();
var config = new PayPalConfiguration(PayPalEnvironment.NoNetwork,"Your PayPal ID from https://developer.paypal.com/developer/applications/")
{
//If you want to accept credit cards
AcceptCreditCards = true,
//Your business name
MerchantName = "Test Store",
//Your privacy policy Url
MerchantPrivacyPolicyUri = "https://www.example.com/privacy",
//Your user agreement Url
MerchantUserAgreementUri = "https://www.example.com/legal",
// OPTIONAL - ShippingAddressOption (Both, None, PayPal, Provided)
ShippingAddressOption = ShippingAddressOption.Both,
// OPTIONAL - Language: Default languege for PayPal Plug-In
Language = "es",
// OPTIONAL - PhoneCountryCode: Default phone country code for PayPal Plug-In
PhoneCountryCode = "52",
};
//iOS
CrossPayPalManager.Init(config);
//Android
CrossPayPalManager.Init(config, this);
...
From official PayPal SDK page (https://github.com/paypal/PayPal-iOS-SDK#with-or-without-cocoapods) follow the two steps:
- Add the open source license acknowledgments
- Add squemas into Info.plist
Add "NSCameraUsageDescription" into you Info.plist file.
<key>NSCameraUsageDescription</key>
<string>We will use your camera to scan the credit card</string>
Is very important to add the following code inside your OnActivityResult and OnDestroy on your main activity class
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
PayPalManagerImplementation.Manager.OnActivityResult(requestCode, resultCode, data);
}
protected override void OnDestroy()
{
base.OnDestroy();
PayPalManagerImplementation.Manager.Destroy();
}
var result = await CrossPayPalManager.Current.Buy (new PayPalItem ("Test Product", new Decimal (12.50), "USD"), new Decimal (0));
if (result.Status == PayPalStatus.Cancelled)
{
Debug.WriteLine ("Cancelled");
}
else if(result.Status == PayPalStatus.Error)
{
Debug.WriteLine (result.ErrorMessage);
}
else if(result.Status == PayPalStatus.Successful)
{
Debug.WriteLine (result.ServerResponse.Response.Id);
}
var result = await CrossPayPalManager.Current.Buy (new PayPalItem[] {
new PayPalItem ("sample item #1", 2, new Decimal (87.50), "USD",
"sku-12345678"),
new PayPalItem ("free sample item #2", 1, new Decimal (0.00),
"USD", "sku-zero-price"),
new PayPalItem ("sample item #3 with a longer name", 6, new Decimal (37.99),
"USD", "sku-33333")
}, new Decimal (20.5), new Decimal (13.20));
if (result.Status == PayPalStatus.Cancelled)
{
Debug.WriteLine ("Cancelled");
}
else if(result.Status == PayPalStatus.Error)
{
Debug.WriteLine (result.ErrorMessage);
}
else if(result.Status == PayPalStatus.Successful)
{
Debug.WriteLine (result.ServerResponse.Response.Id);
}
//Optional shipping address parameter into Buy methods.
var result = await CrossPayPalManager.Current.Buy(
new PayPalItem(
"Test Product",
new Decimal(12.50), "USD"),
new Decimal(0),
new ShippingAddress("My Custom Recipient Name", "Custom Line 1", "", "My City", "My State", "12345", "MX")
);
if (result.Status == PayPalStatus.Cancelled)
{
Debug.WriteLine("Cancelled");
}
else if (result.Status == PayPalStatus.Error)
{
Debug.WriteLine(result.ErrorMessage);
}
else if (result.Status == PayPalStatus.Successful)
{
Debug.WriteLine(result.ServerResponse.Response.Id);
}
var result = await CrossPayPalManager.Current.RequestFuturePayments();
if (result.Status == PayPalStatus.Cancelled)
{
Debug.WriteLine ("Cancelled");
}
else if(result.Status == PayPalStatus.Error)
{
Debug.WriteLine (result.ErrorMessage);
}
else if(result.Status == PayPalStatus.Successful)
{
//Print Authorization Code
Debug.WriteLine(result.ServerResponse.Response.Code);
}
var result = await CrossPayPalManager.Current.AuthorizeProfileSharing();
if (result.Status == PayPalStatus.Cancelled)
{
Debug.WriteLine ("Cancelled");
}
else if(result.Status == PayPalStatus.Error)
{
Debug.WriteLine (result.ErrorMessage);
}
else if(result.Status == PayPalStatus.Successful)
{
Debug.WriteLine (result.ServerResponse.Response.Code);
}
//Print Client Metadata Id
Debug.WriteLine(CrossPayPalManager.Current.ClientMetadataId);
//Optional parameter CardIOLogo("PayPal", "CardIO" or "None") for ScanCard method by default "PayPal" is used
var result = await CrossPayPalManager.Current.ScanCard();
if (result.Status == PayPalStatus.Cancelled)
{
Debug.WriteLine("Cancelled");
}
else if (result.Status == PayPalStatus.Successful)
{
if (result.Card.CardImage != null)
{
CardImage.Source = result.Card.CardImage;
}
Debug.WriteLine($"CardNumber: {result.Card.CardNumber}, CardType: {result.Card.CardType.ToString()}, Cvv: {result.Card.Cvv}, ExpiryMonth: {result.Card.ExpiryMonth}");
Debug.WriteLine($"ExpiryYear: {result.Card.ExpiryYear}, PostalCode: {result.Card.PostalCode}, RedactedCardNumber: {result.Card.RedactedCardNumber}, Scaned: {result.Card.Scaned}");
}
- Nuget Package (https://www.nuget.org/packages/PayPal.Forms)
No new tasks to do. All issues or features requests are welcome