Песочница Braintree Apple Pay показывает ошибку оплаты не выполнено после сканирования отпечатков пальцев iOS - PullRequest
2 голосов
/ 24 апреля 2019

Я реализовал Braintree, который поддерживает Apple Pay.Но я столкнулся с проблемой.Все работает правильно, но всякий раз, когда я пытаюсь сделать платеж, он показывает мне знак «Платеж не завершен».Я проверил, что мой домен подтвержден.Я вызвал кнопку Apple Pay с указанным ниже кодом.

- (PKPaymentRequest *)paymentRequest
{
    PKPaymentRequest *paymentRequest = [[PKPaymentRequest alloc] init];
    paymentRequest.merchantIdentifier = @"merchant.myIdentifier";
    //paymentRequest.merchantIdentifier = @"merchant.mysandboxIdentifier";
    paymentRequest.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard];
    paymentRequest.merchantCapabilities = PKMerchantCapability3DS;
    paymentRequest.countryCode = @"US"; // e.g. US
    paymentRequest.currencyCode = @"USD"; // e.g. USD
//    self.requiredShippingAddressFields = PKAddressFieldPostalAddress;
//    paymentRequest.requiredShippingAddressFields = PKAddressFieldAll;

//    paymentRequest.shippingMethods = [self ShipingMethod];

//    paymentRequest.shippingContact = [self ShipingAddress:@"Delivered" :paymentRequest];
   paymentRequest.paymentSummaryItems = [self PaymentSummaryItems];
    return paymentRequest;
}


- (IBAction)applePayButtonTouchUpInside:(id)sender
{

    self.navigationController.navigationItem.backBarButtonItem.enabled = NO;
    self.iconLoadingIndicator.hidden = NO;
    [self.iconLoadingIndicator startAnimating];

    backBtn.enabled = NO;
    self.applePayBtn.enabled = NO;
    self.creditCardBtn.enabled = NO;
    self.checkoutBtn.enabled = NO;

    if([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa,PKPaymentNetworkDiscover]]) // Returns FALSE
    {
        if ([PKPaymentAuthorizationViewController canMakePayments])
        {
            PKPaymentRequest *paymentRequest = [self paymentRequest];
            PKPaymentAuthorizationViewController *vc = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:paymentRequest];
            if (vc)
            {
                self.payment_mode = kApplePayMode;
                vc.delegate = self;
                [self.navigationController presentViewController:vc animated:YES completion:nil];

            }
            else
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Something went wrong. Please Try Again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
               [self StopLoader];
            }
        }
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Your card does not support Apple Pay." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

       [self StopLoader];
    }
}

Этот делегат не звонит, так как застрял в процессе оплаты не завершен процесс. enter image description here

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                       didAuthorizePayment:(PKPayment *)payment
                                   handler:(void (^)(PKPaymentAuthorizationResult *result))completion API_AVAILABLE(ios(11.0), watchos(4.0));
{
    isApplePayInitiatingPayment = YES;

    // Example: Tokenize the Apple Pay payment
    BTApplePayClient *applePayClient = [[BTApplePayClient alloc]
                                        initWithAPIClient:self.braintreeClient];
    [applePayClient tokenizeApplePayPayment:payment
                                 completion:^(BTApplePayCardNonce *tokenizedApplePayPayment,
                                              NSError *error)
     {
         if (tokenizedApplePayPayment)
         {
             // On success, send nonce to your server for processing.
             // If applicable, address information is accessible in `payment`.
             NSLog(@"nonce = %@", tokenizedApplePayPayment.nonce);
             self.wcitiesBraintreeCreateTransaction = [[WcitiesBraintreeCreateTransaction alloc] init];
             [self.wcitiesBraintreeCreateTransaction CreateTransaction:self.totalPrice OneTimeNonce:tokenizedApplePayPayment.nonce paypal_payer_id:@"" payment_mode:kApplePayMode :^(NSMutableArray *result, NSError *error)
              {
                  if (result.count>0)
                  {
                      self.transaction_id = [result objectAtIndex:0];
                      [self generateClientOrder:NO];
                  }
                  else
                  {
                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Transaction failure. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                      [alert show];
                      [self StopLoader];
                  }
              }];


             // Then indicate success or failure via the completion callback, e.g.
             PKPaymentAuthorizationResult *result = [[PKPaymentAuthorizationResult alloc] initWithStatus:PKPaymentAuthorizationStatusSuccess errors:nil];
             completion(result);
         } else {
             // Tokenization failed. Check `error` for the cause of the failure.

             // Indicate failure via the completion callback:
             PKPaymentAuthorizationResult *result = [[PKPaymentAuthorizationResult alloc] initWithStatus:PKPaymentAuthorizationStatusFailure errors:nil];
             completion(result);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Transaction failure. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
             [alert show];
             [self StopLoader];
         }
     }];
}
...