GithubHelp home page GithubHelp logo

pxbachs / paypal.forms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alejandroruiz/paypal.forms

0.0 1.0 0.0 193.88 MB

PayPal Plugin for Xamarin.Forms

License: MIT License

C# 99.75% Smalltalk 0.25%

paypal.forms's Introduction

PayPal.Forms

PayPal Plugin for Xamarin.Forms

Setup

##iOS & Android

In MainActivity(Android)/AppDelegate(iOS) after "Forms.Init()" call the Init method with your PayPal config value

...
global::Xamarin.Forms.Forms.Init ();
 CrossPayPalManager.Init(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"
				  }
			);
...

##iOS

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

##Android

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();
}

Usage

##Single Item

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);
}

##List of Items

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);
}

##Shipping Address (Optional)

//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);
}

##Future Payments

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);
}

##Profile sharing

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);
}

##Obtain a Client Metadata ID

//Print Client Metadata Id
Debug.WriteLine(CrossPaypalManager.Current.ClientMetadataId);

##Standalone Card Scanner

//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

Known Issues

  • On Xamarin Studio 5.10.X you will receive an alert that xamarin cant resolve "xamarin.paypal" and/or "paypal.forms" lib name this will be fixed by upgrading to Xamarin Studio 6 in beta/alpha channel(recommended) or downgrading to Xamarin Studio 5.9(not recommended)

TODO

No new tasks to do. All issues or features requests are welcome

paypal.forms's People

Contributors

alejandroruiz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.