public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { // Make sure the URL comes from Square Register, fail if it doesn't. if (!sourceApplication.StartsWith("com.squareup.square")) { return(false); } // The response data is encoded in the URL and can be decoded as an SCCAPIResponse. NSError decodeError; var response = SCCAPIResponse.ResponseWithResponseURL(url, out decodeError); string message; string title; // Process the response as desired. if (response.SuccessResponse) { title = "Success!"; // Square says the PaymentId and OfflinePaymentId are deprecated and to use TransactionId // and ClientTransactionId (which is missing from SCCAPIResponse) so I added it by parsing the url like they do // http://stackoverflow.com/questions/37756795/why-do-ios-and-android-versions-of-the-square-register-sdk-return-different-valu var clientTransactionId = url.GetClientTransactionId(out decodeError); message = string.Format("Payment creation succeeded with payment ids {0} {1}, transaction id {2}, client transaction id {3}", response.PaymentID, response.OfflinePaymentID, response.TransactionID, clientTransactionId); } else { title = "Error!"; // An invalid response message error is distinct from a successfully decoded error. var errorToPresent = response != null ? response.Error : decodeError; message = string.Format("Payment creation failed with error {0}", errorToPresent.LocalizedDescription); } var alertView = new UIAlertView(title, message, null, "OK"); alertView.Show(); return(true); }
public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { // Make sure the URL comes from Square Register, fail if it doesn't. if(!sourceApplication.StartsWith("com.squareup.square")) { return false; } // The response data is encoded in the URL and can be decoded as an SCCAPIResponse. NSError decodeError; var response = SCCAPIResponse.ResponseWithResponseURL(url, out decodeError); string message; string title; // Process the response as desired. if(response.SuccessResponse) { title = "Success!"; // Square says the PaymentId and OfflinePaymentId are deprecated and to use TransactionId // and ClientTransactionId (which is missing from SCCAPIResponse) so I added it by parsing the url like they do // http://stackoverflow.com/questions/37756795/why-do-ios-and-android-versions-of-the-square-register-sdk-return-different-valu var clientTransactionId = url.GetClientTransactionId(out decodeError); message = string.Format("Payment creation succeeded with payment ids {0} {1}, transaction id {2}, client transaction id {3}", response.PaymentID, response.OfflinePaymentID, response.TransactionID, clientTransactionId); } else { title = "Error!"; // An invalid response message error is distinct from a successfully decoded error. var errorToPresent = response != null ? response.Error : decodeError; message = string.Format("Payment creation failed with error {0}", errorToPresent.LocalizedDescription); } var alertView = new UIAlertView(title, message, null, "OK"); alertView.Show(); return true; }