public WebPayPalAuthorization getAuthorization(User me, string guid) { if (me.type == "admin") { PayPalAuthorization authorization = db.PayPalAuthorizations.SingleOrDefault(a => a.guid == guid); if (authorization != null) { WebPayPalAuthorization webAuth = new WebPayPalAuthorization(); webAuth.id = authorization.id; webAuth.guid = authorization.guid; webAuth.type = authorization.type; webAuth.bfksRegistrationId = authorization.bfksRegistrationId; webAuth.frostyRegistrationId = authorization.frostyRegistrationId; webAuth.userId = authorization.userId; webAuth.user = authorization.user != null?authorization.user.convert() : null; webAuth.email = authorization.email; webAuth.name = authorization.name; webAuth.date = authorization.date; return(webAuth); } else { return(null); } } else { throw new PermissionDeniedException(); } }
private void sendAuthorizationToServer(PayPalAuthorization authorization) { /** * TODO: Send the authorization response to your server, where it can * exchange the authorization code for OAuth access and refresh tokens. * * Your server must then store these tokens, so that your server code * can execute payments for this user in the future. * * A more complete example that includes the required app-server to * PayPal-server integration is available from * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend */ }
public string createAuthorization(WebPayPalAuthorization authorization, int currentUserId) { if ((authorization.type == "Logged-in" && currentUserId > 0) || (authorization.type == "Email" && currentUserId == -1) || (authorization.type == "Anonymous" && currentUserId == -1)) { if (authorization.type == "Logged-in" && (authorization.email != null || authorization.name != null)) { throw new Exception("Incompatible email or name provided while logged-in."); } if (authorization.type == "Email" && (String.IsNullOrWhiteSpace(authorization.email) || String.IsNullOrWhiteSpace(authorization.name))) { throw new Exception("Email or name not provided with Email type."); } if (authorization.type == "Anonymous" && (authorization.email != null || authorization.name != null)) { throw new Exception("Incompatible email or name provided with Anonymous type."); } PayPalAuthorization a = new PayPalAuthorization(); a.guid = Guid.NewGuid().ToString(); a.type = authorization.type; a.bfksRegistrationId = authorization.bfksRegistrationId; a.frostyRegistrationId = authorization.frostyRegistrationId; if (currentUserId > 0) { a.userId = currentUserId; } else { a.userId = null; } a.email = authorization.email; a.name = authorization.name; a.date = DateTime.UtcNow; db.PayPalAuthorizations.Add(a); db.SaveChanges(); return(a.guid); } else { throw new Exception("Invalid authorization type or currentUserId: type=" + authorization.type + ", currentUserId=" + currentUserId); } }
private void updateRegistrationPayment(PayPalNotification notification) { PayPalAuthorization authorization = db.PayPalAuthorizations .Include(a => a.bfksRegistration) .Include(a => a.frostyRegistration) .SingleOrDefault(a => a.guid == notification.custom); if (authorization != null) { if (authorization.bfksRegistration != null) { authorization.bfksRegistration.isPaid = true; } if (authorization.frostyRegistration != null) { authorization.frostyRegistration.isPaid = true; } db.SaveChanges(); } }
private void SendAuthorizationToServer(PayPalAuthorization auth) { // TODO: Send Authorization to server Dbg.WriteLine("Here is your Authorization:\n\n{0}\n\nSend this to your server for further processing.", auth.ToJSONObject().ToString(4)); }
public void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data) { if (requestCode == PayPalManager.REQUEST_CODE_PAYMENT) { if (resultCode == Result.Ok) { PaymentConfirmation confirm = (PaymentConfirmation)data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation); if (confirm != null) { try { System.Diagnostics.Debug.WriteLine(confirm.ToJSONObject().ToString(4)); System.Diagnostics.Debug.WriteLine(confirm.Payment.ToJSONObject().ToString(4)); /** * TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification * or consent completion. * See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ * for more details. * * For sample mobile backend interactions, see * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend */ Toast.MakeText( Context.ApplicationContext, "PaymentConfirmation info received from PayPal", ToastLength.Short) .Show(); } catch (JSONException e) { System.Diagnostics.Debug.WriteLine("an extremely unlikely failure occurred: " + e.Message); } } } else if (resultCode == Result.Canceled) { System.Diagnostics.Debug.WriteLine("The user canceled."); } else if ((int)resultCode == PaymentActivity.ResultExtrasInvalid) { System.Diagnostics.Debug.WriteLine( "An invalid Payment or PayPalConfiguration was submitted. Please see the docs."); } } else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) { if (resultCode == Result.Ok) { PayPalAuthorization auth = (Xamarin.PayPal.Android.PayPalAuthorization)data.GetParcelableExtra(PayPalFuturePaymentActivity.ExtraResultAuthorization); if (auth != null) { try { System.Diagnostics.Debug.WriteLine(auth.ToJSONObject().ToString(4)); String authorization_code = auth.AuthorizationCode; System.Diagnostics.Debug.WriteLine(authorization_code); sendAuthorizationToServer(auth); Toast.MakeText( Context.ApplicationContext, "Future Payment code received from PayPal", ToastLength.Long) .Show(); } catch (JSONException e) { System.Diagnostics.Debug.WriteLine("an extremely unlikely failure occurred: " + e.Message); } } } else if (resultCode == Result.Ok) { System.Diagnostics.Debug.WriteLine("The user canceled."); } else if ((int)resultCode == PayPalFuturePaymentActivity.ResultExtrasInvalid) { System.Diagnostics.Debug.WriteLine( "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs."); } } else if (requestCode == REQUEST_CODE_PROFILE_SHARING) { if (resultCode == Result.Ok) { PayPalAuthorization auth = (Xamarin.PayPal.Android.PayPalAuthorization)data.GetParcelableExtra(PayPalProfileSharingActivity.ExtraResultAuthorization); if (auth != null) { try { System.Diagnostics.Debug.WriteLine(auth.ToJSONObject().ToString(4)); String authorization_code = auth.AuthorizationCode; System.Diagnostics.Debug.WriteLine(authorization_code); sendAuthorizationToServer(auth); Toast.MakeText( Context.ApplicationContext, "Profile Sharing code received from PayPal", ToastLength.Short) .Show(); } catch (JSONException e) { System.Diagnostics.Debug.WriteLine("an extremely unlikely failure occurred: " + e.Message); } } } else if (resultCode == Result.Canceled) { System.Diagnostics.Debug.WriteLine("The user canceled."); } else if ((int)resultCode == PayPalFuturePaymentActivity.ResultExtrasInvalid) { System.Diagnostics.Debug.WriteLine( "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs."); } } }
private void sendAuthorizationToServer(PayPalAuthorization authorization) { /** * TODO: Send the authorization response to your server, where it can * exchange the authorization code for OAuth access and refresh tokens. * * Your server must then store these tokens, so that your server code * can execute payments for this user in the future. * * A more complete example that includes the required app-server to * PayPal-server integration is available from * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend */ }
public void OnActivityResult(int requestCode, Result resultCode, global::Android.Content.Intent data) { if (requestCode == PayPalManager.REQUEST_CODE_PAYMENT) { if (resultCode == Result.Ok) { PaymentConfirmation confirm = (PaymentConfirmation)data.GetParcelableExtra(PaymentActivity.ExtraResultConfirmation); if (confirm != null) { try { OnSuccess?.Invoke(confirm.ToJSONObject().ToString()); OnSuccess = null; } catch (JSONException e) { OnError?.Invoke("an extremely unlikely failure occurred: " + e.Message); OnError = null; System.Diagnostics.Debug.WriteLine("an extremely unlikely failure occurred: " + e.Message); } } OnError?.Invoke("Unknown Error"); OnError = null; } else if (resultCode == Result.Canceled) { OnCancelled?.Invoke(); OnCancelled = null; System.Diagnostics.Debug.WriteLine("The user canceled."); } else if ((int)resultCode == PaymentActivity.ResultExtrasInvalid) { OnError?.Invoke("An invalid Payment or PayPalConfiguration was submitted. Please see the docs."); OnError = null; System.Diagnostics.Debug.WriteLine( "An invalid Payment or PayPalConfiguration was submitted. Please see the docs."); } } else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) { if (resultCode == Result.Ok) { PayPalAuthorization auth = (PayPalAuthorization)data.GetParcelableExtra(PayPalFuturePaymentActivity.ExtraResultAuthorization); if (auth != null) { try { OnSuccess?.Invoke(auth.ToJSONObject().ToString()); OnSuccess = null; } catch (JSONException e) { System.Diagnostics.Debug.WriteLine("an extremely unlikely failure occurred: " + e.Message); } } OnError?.Invoke("Unknown Error"); OnError = null; } else if (resultCode == Result.Canceled) { OnCancelled?.Invoke(); OnCancelled = null; System.Diagnostics.Debug.WriteLine("The user canceled."); } else if ((int)resultCode == PayPalFuturePaymentActivity.ResultExtrasInvalid) { OnError?.Invoke("Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs."); OnError = null; System.Diagnostics.Debug.WriteLine( "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs."); } } else if (requestCode == REQUEST_CODE_PROFILE_SHARING) { if (resultCode == Result.Ok) { PayPalAuthorization auth = (PayPalAuthorization)data.GetParcelableExtra(PayPalProfileSharingActivity.ExtraResultAuthorization); if (auth != null) { try { OnSuccess?.Invoke(auth.ToJSONObject().ToString()); OnSuccess = null; } catch (JSONException e) { System.Diagnostics.Debug.WriteLine("an extremely unlikely failure occurred: " + e.Message); } } OnError?.Invoke("Unknown Error"); OnError = null; } else if (resultCode == Result.Canceled) { OnCancelled?.Invoke(); OnCancelled = null; System.Diagnostics.Debug.WriteLine("The user canceled."); } else if ((int)resultCode == PayPalFuturePaymentActivity.ResultExtrasInvalid) { OnError?.Invoke("Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs."); OnError = null; System.Diagnostics.Debug.WriteLine( "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs."); } } else if (requestCode == REQUEST_CODE_CARD_SCAN) { if (data == null) { RetrieveCardCancelled?.Invoke(); RetrieveCardCancelled = null; System.Diagnostics.Debug.WriteLine("The user canceled."); return; } var card = (CreditCard)data.GetParcelableExtra(CardIOActivity.ExtraScanResult); if (card != null) { RetrieveCardSuccess?.Invoke(card, CardIOActivity.GetCapturedCardImage(data)); RetrieveCardSuccess = null; } else { RetrieveCardCancelled?.Invoke(); RetrieveCardCancelled = null; System.Diagnostics.Debug.WriteLine("The user canceled."); } } }
private void SendAuthorizationToServer(PayPalAuthorization auth) { // TODO: Send Authorization to server Dbg.WriteLine ("Here is your Authorization:\n\n{0}\n\nSend this to your server for further processing.", auth.ToJSONObject().ToString(4)); }