async Task HandlePaymentAuthorization (PKPayment payment, Action<PKPaymentAuthorizationStatus> completion, bool isTest = false, bool shouldTestFail = false) { try { Token token = null; if (isTest) token = await StripeClient.CreateTestToken (payment, shouldTestFail); else token = await StripeClient.CreateToken (payment); var msg = string.Format ("Good news! Stripe turned your credit card into a token: \n{0} \n\nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .", token.Id); var avMsg = new UIAlertView ("Todo: Submit this token to your backend", msg, null, "OK"); avMsg.Show (); completion (PKPaymentAuthorizationStatus.Success); } catch (Exception ex) { var avMsg = new UIAlertView ("Payment Failed", ex.Message, null, "OK"); avMsg.Show (); } }
async Task HandlePaymentAuthorization(PKPayment payment, Action <PKPaymentAuthorizationStatus> completion, bool isTest = false, bool shouldTestFail = false) { try { Token token = null; if (isTest) { token = await StripeClient.CreateTestToken(payment, shouldTestFail); } else { token = await StripeClient.CreateToken(payment); } var msg = string.Format("Good news! Stripe turned your credit card into a token: \n{0} \n\nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .", token.Id); var avMsg = new UIAlertView("Todo: Submit this token to your backend", msg, null, "OK"); avMsg.Show(); completion(PKPaymentAuthorizationStatus.Success); } catch (Exception ex) { var avMsg = new UIAlertView("Payment Failed", ex.Message, null, "OK"); avMsg.Show(); } }
public async Task <IResult <ITransactionResult> > HandlePKPayment(PKPayment payment, string customerRef, NSDecimalNumber amount, ApplePaymentType type, JudoFailureCallback failure) { try { CardPaymentModel paymentmodel = new CardPaymentModel { JudoId = JudoConfiguration.Instance.JudoId, ClientDetails = _clientService.GetClientDetails(), UserAgent = _clientService.GetSDKVersion() }; var test = payment.Token.PaymentData.ToString(NSStringEncoding.UTF8); JObject jo = JObject.Parse(test.ToString()); PKPaymentModel pkModel = new PKPaymentModel() { JudoId = JudoConfiguration.Instance.JudoId, YourPaymentReference = "paymentRef12343", YourConsumerReference = customerRef, Amount = amount.ToDecimal(), ClientDetails = _clientService.GetClientDetails(), UserAgent = _clientService.GetSDKVersion(), PkPayment = new PKPaymentInnerModel() { Token = new PKPaymentTokenModel() { PaymentData = jo, PaymentInstrumentName = payment.Token.PaymentInstrumentName, PaymentNetwork = payment.Token.PaymentNetwork } } }; Task <IResult <ITransactionResult> > task = null; if (type == ApplePaymentType.Payment) { task = _judoAPI.Payments.Create(pkModel); } else if (type == ApplePaymentType.PreAuth) { task = _judoAPI.PreAuths.Create(pkModel); } if (task == null) { var judoError = new JudoError() { Exception = new Exception("Judo server did not return response. Please contact customer support") }; failure(judoError); } return(await task); } catch (Exception e) { Console.WriteLine(e.InnerException.ToString()); var judoError = new JudoError() { Exception = e }; failure(judoError); return(null); } }
async Task ClearPaymentWithJudo(PKPayment payment, string customerRef, Action <PKPaymentAuthorizationStatus> completion) { var result = await _applePayService.HandlePKPayment(payment, customerRef, _runningTotal, _paymentAction, _failureCallback); if (result != null && !result.HasError && result.Response.Result != "Declined") { var paymentreceipt = result.Response as PaymentReceiptModel; if (paymentreceipt != null) { if (_successCallBack != null) { completion(PKPaymentAuthorizationStatus.Success); _successCallBack(paymentreceipt); } } } else { if (_failureCallback != null) { var judoError = new JudoError { ApiError = result != null ? result.Error : null }; var paymentreceipt = result != null ? result.Response as PaymentReceiptModel : null; if (paymentreceipt != null) { // send receipt even we got card declined completion(PKPaymentAuthorizationStatus.Failure); _failureCallback(judoError, paymentreceipt); } else { completion(PKPaymentAuthorizationStatus.Failure); _failureCallback(judoError); } } } }
async Task PerformApplePayAction(PKPayment payment, Action<PKPaymentAuthorizationStatus> completion, PKPaymentAuthorizationViewController controller) { var jObject = ConvertToJObject(payment.Token.PaymentData); var paymentServiceModel = new PKPaymentViewModel { Amount = _applePayModel.ItemsTotalAmount(), ConsumerReference = _applePayModel.ConsumerRef, JudoID = _judo.JudoId, PaymentData = jObject, PaymentInstrumentName = payment.Token.PaymentInstrumentName ?? string.Empty, PaymentNetwork = payment.Token.PaymentNetwork ?? string.Empty }; var response = await _applePayRequest.Perform(paymentServiceModel); if (response.ConsideredSuccessful) { if (response.ReceiptModelPresent() && _successCallBack != null) { completion(PKPaymentAuthorizationStatus.Success); controller.DismissViewController(true, null); _successCallBack(response.ReceiptModel); } } else { completion(PKPaymentAuthorizationStatus.Failure); controller.DismissViewController(true, null); if (response.ReceiptModelPresent()) { _failureCallback(response.ErrorModel, response.ReceiptModel); } else { _failureCallback(response.ErrorModel); } } }
public override void DidAuthorizePayment(PKPaymentAuthorizationController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { _completion = completion; var paymentData = NSString.FromData(payment.Token.PaymentData, NSStringEncoding.UTF8); string paymentType; switch (payment.Token.PaymentMethod.Type) { case PKPaymentMethodType.Debit: paymentType = @"debit"; break; case PKPaymentMethodType.Credit: paymentType = @"credit"; break; case PKPaymentMethodType.Store: paymentType = @"store"; break; case PKPaymentMethodType.Prepaid: paymentType = @"prepaid"; break; default: paymentType = @"unknown"; break; } var paymentMethod = new Dictionary <string, string> { ["network"] = payment.Token.PaymentMethod.Network, ["type"] = paymentType, ["displayName"] = payment.Token.PaymentMethod.DisplayName }; var token = JsonConvert.SerializeObject(new { paymentData = JsonConvert.DeserializeObject(paymentData), transactionIdentifier = payment.Token.TransactionIdentifier, paymentMethod = paymentMethod }); _tcs.TrySetResult(token); }
public async void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { await HandlePaymentAuthorization(payment, completion); }
public async void DidAuthorizeTestPayment(StripeTestPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion, bool shouldTestFail) { await HandlePaymentAuthorization(payment, completion, true, shouldTestFail); }
/// <summary> /// This is where you would send your payment to be processed - here we will /// simply present a confirmation screen. If your payment processor failed the /// payment you would return `completion(PKPaymentAuthorizationStatus.Failure)` instead. Remember to never /// attempt to decrypt the payment token on device. /// </summary> public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { paymentToken = payment.Token; var ccApi = CCCAPI.Instance(); //Verifyng - Apple pay token got from apple Console.WriteLine("CC API paymentToken = " + paymentToken); //Card Connect Verifying - Endpoint Console.WriteLine("CC API End point = " + ccApi.Endpoint); ccApi.GenerateTokenForApplePay(payment, (theToken, error) => { //Card Connect token, which should be used to finalize the payment through one of the server sdks of card connect. Console.WriteLine("CC API theToken = " + theToken); if (!String.IsNullOrWhiteSpace(theToken)) { completion(PKPaymentAuthorizationStatus.Success); } else { completion(PKPaymentAuthorizationStatus.Failure); } }); }
public override void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { this.AuthorizePayment?.Invoke(this, new Action <bool>((auth) => { if (auth) { completion(PKPaymentAuthorizationStatus.Success); } else { completion(PKPaymentAuthorizationStatus.Failure); } })); }
public override void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { completion(PKPaymentAuthorizationStatus.Success); // Checkout(); PremimumUser(); }
/// <summary> /// This is where you would send your payment to be processed - here we will /// simply present a confirmation screen. If your payment processor failed the /// payment you would return `completion(PKPaymentAuthorizationStatus.Failure)` instead. Remember to never /// attempt to decrypt the payment token on device. /// </summary> public void DidAuthorizePayment (PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion) { paymentToken = payment.Token; completion (PKPaymentAuthorizationStatus.Success); PerformSegue (confirmationSegue, this); }
public override void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { var applePayClient = new BTApplePayClient(braintreeClient); applePayClient.TokenizeApplePayPayment(payment, (tokenizedApplePayPayment, error) => { if (error == null) { if (string.IsNullOrEmpty(tokenizedApplePayPayment.Nonce)) { payTcs?.SetCanceled(); } else { if (!isDropUI) { OnTokenizationSuccessful?.Invoke(this, tokenizedApplePayPayment.Nonce); } payTcs?.TrySetResult(tokenizedApplePayPayment.Nonce); } completion(PKPaymentAuthorizationStatus.Success); } else { if (!isDropUI) { OnTokenizationError?.Invoke(this, "Error - Payment tokenization failed"); } payTcs?.TrySetException(new Exception("Error - Payment tokenization failed")); completion(PKPaymentAuthorizationStatus.Failure); } }); }
public async void DidAuthorizePayment (PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion) { await HandlePaymentAuthorization (payment, completion); }
public async void DidAuthorizeTestPayment (StripeTestPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion, bool shouldTestFail) { await HandlePaymentAuthorization (payment, completion, true, shouldTestFail); }
public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion) { PerformApplePayAction(payment, completion, controller); }
/// <summary> /// This is where you would send your payment to be processed - here we will /// simply present a confirmation screen. If your payment processor failed the /// payment you would return `completion(PKPaymentAuthorizationStatus.Failure)` instead. Remember to never /// attempt to decrypt the payment token on device. /// </summary> public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { paymentToken = payment.Token; completion(PKPaymentAuthorizationStatus.Success); PerformSegue(confirmationSegue, this); }
public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { ClearPaymentWithJudo(payment, _customerRef, completion); }