2016-12-06 11 views
2

私の問題は次のとおりです。クレジットカード/デビットカードを受け入れる予定のアプリを作成しました。そしてImはiOSでBraintree 4 SDKを使用して、ココアポッドを使って迅速に使用しています。私はちょうど良いのドロップを提示することができますが、それは何ですか?私はクイックスタートガイドのコードを使用しているので、それを行うことになっています。しかし、ノンス関数を呼び出すか、金額などを表示するかについては何も言いません! SDK 3では、デリゲートを置くことができるView Controllerであり、カードを覚えておく以外はほとんどすべてが機能します。だから私の質問はどこでiOSでnonce関数を呼び出すはずですか?合計はどこに表示されるべきですか?そして、私はどのようにサーバーBTに支払いを行うのですか?iOSでBraintreeで支払いアプリを実装する方法

ページには実際にすべての情報が欠落しています。助けて。

マイコード:

// Mark - Braintree methods 

    func showDropIn(clientTokenOrTokenizationKey: String) { 

      let request = BTDropInRequest() 
      request.amount = "\(total)" 
      request.currencyCode = "MXN" 
//   request. 
      let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request) 
      { (controller, result, error) in 
       if (error != nil) { 
        print("ERROR") 
       } else if (result?.isCancelled == true) { 
        print("CANCELLED") 
       } else if let result = result { 
        // Use the BTDropInResult properties to update your UI 
        // result.paymentOptionType 
        // result.paymentMethod 
        // result.paymentIcon 
        // result.paymentDescription 
        print(result) 

//     controller. 
       } 
       controller.dismiss(animated: true, completion: nil) 
      } 
      self.present(dropIn!, animated: true, completion: nil) 

//  //create paymentrequest 
//  let 
//  paymentRequest: BTPaymentRequest = BTPaymentRequest() 
//  paymentRequest.summaryTitle = "Lavado Automozo" 
//  paymentRequest.summaryDescription = "$\(totalLabel.text!) precio total de los servicios solicitados." 
//  paymentRequest.displayAmount = "$\(total!).00 MXN" 
//  paymentRequest.currencyCode = "MXN" 
//  paymentRequest.callToActionText = "Aceptar compra." 
//  paymentRequest.shouldHideCallToAction = false 
//  //set delegate 
//  let dropInViewController = BTDropInViewController(apiClient: braintreeClient!) 
//  dropInViewController.delegate = self 
//  dropInViewController.paymentRequest = paymentRequest 
//  //add cancel button 
//  dropInViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(ViewController.userDidCancelPayment)) 
//   
//  //present view 
//  let navigationController = UINavigationController(rootViewController: dropInViewController) 
//   
//  present(navigationController, animated: true, completion: nil) 
//   
     //  let request = BTDropInRequest() 
//  let dropIn = BTDropInController() 
//  { (controller, result, error) in 
//   if (error != nil) { 
//    print("ERROR") 
//   } else if (result?.isCancelled == true) { 
//    print("CANCELLED") 
//   } else if let result = result { 
//    // Use the BTDropInResult properties to update your UI 
//    // result.paymentOptionType 
//    // result.paymentMethod 
//    // result.paymentIcon 
//    // result.paymentDescription 
//   } 
//   controller.dismiss(animated: true, completion: nil) 
//  } 
//  self.present(dropIn!, animated: true, completion: nil) 
    } 

そして、私はこの?:ダミーカードの後

func postNonceToServer(paymentMethodNonce: String) -> Bool { 

     PFCloud.callFunction(inBackground: "checkout", withParameters: ["payment_method_nonce" : paymentMethodNonce, "amount" : "\(total!).00"]) { 

      (response, error) -> Void in 

      //   let ratings = response as? Float 
      // ratings is 4.5 

      if error != nil { 


      } else { 


      } 

      print("the response \(response ?? "nil")") 
      print("The error: \(error?.localizedDescription)") 

      //self.clientToken = response as! String 

//   print(self.clientToken) 

     } 

     let dateFormatter = DateFormatter() 
     dateFormatter.dateFormat = "mmm. dd, YYYY HH:mm" 
     dateFormatter.timeZone = NSTimeZone.local 

     let fechaRegistro = dateFormatter.string(from: Date()) 

//  displayError("Exito", message: "Tu pago ha sido procesado, en unos momentos atenderemos tu orden. Total es de $\(totalLabel.text!) la fecha registrada \(fechaRegistro)") 

     let usuarioPagado: PFObject = PFObject(className: "Ordenes") 
     let location: PFGeoPoint = PFGeoPoint(latitude: ubicacion.latitude, longitude: ubicacion.longitude) 
     usuarioPagado["Ubicacion"] = location 
     usuarioPagado["NumeroExterior"] = numeroExteriorTextField.text! 
     usuarioPagado["NumeroDeTelefono"] = telefonoTextField.text! 
     usuarioPagado["LavadoCarro"] = numeroCarrosTextField.text! 
     usuarioPagado["LavadoMiniVan"] = numeroMinivanTextField.text! 
     usuarioPagado["LavadoPickUp"] = numeroPickUpsTextField.text! 
     usuarioPagado["LavadoDeVan"] = numeroVansTextField.text! 
     usuarioPagado["LavadoAspiradoCarro"] = numeroAspiradoCarrosTextField.text! 
     usuarioPagado["LavadoAspiradoMiniVan"] = numeroAspiradoMinivanTextField.text! 
     usuarioPagado["LavadoAspiradoPickUp"] = numeroPickUpsTextField.text! 
     usuarioPagado["LavadoAspiradoDeVan"] = numeroAspiradoVansTextField.text! 
     usuarioPagado["Monto"] = totalLabel.text! 
     usuarioPagado["NumeroDeTelefono"] = telefonoTextField.text! 
     usuarioPagado["TipoDeCelular"] = "iPhone" 
     usuarioPagado["FechaDeOrden"] = fechaRegistro 
     //usuarioPagado["TipoDeCelular"] 
     //usuarioPagado["PaymentConfirmation"] = completedPayment.confirmation.description 
     // 
     //  usuarioPagado.saveInBackground() { 
     //   (success: Bool, error: Error?) -> Void in 
     // 
     //   if error == nil { 
     // 
     //    //done 
     //    print("saved object") 
     // 
     //   } else { 
     // 
     //    //not done 
     //    print("not saved because \(error?.localizedDescription)") 
     // 
     //   } 
     //  } 

     do { 

      let result = try usuarioPagado.save() 

//   displayError("Exito", message: "Tu pago ha sido procesado, en unos momentos atenderemos tu orden. Total es de $\(totalLabel.text!) la fecha registrada \(fechaRegistro)") 
//    

     } catch let error { 

      print(error.localizedDescription) 
      self.displayError("Error", message: "Hubo un error al guardar tu informacion, ponte ne contacto con nosotros.") 
      return false 
     } 
     numeroCarrosTextField.text = "0" 
     numeroMinivanTextField.text = "0" 
     numeroPickUpsTextField.text = "0" 
     numeroVansTextField.text = "0" 

     numeroAspiradoCarrosTextField.text = "0" 
     numeroAspiradoMinivanTextField.text = "0" 
     numeroAspiradoPickUpsTextField.text = "0" 
     numeroAspiradoVansTextField.text = "0" 
     totalLabel.text = "00.00" 
     self.lavadoSwitch.isOn = false 
     self.lavadoYAspiradSwitch.isOn = false 

     self.numeroExteriorTextField.text = "" 
     self.telefonoTextField.text = "" 
//  displayError("Exito", message: "Tu pago ha sido procesado, en unos momentos atenderemos tu orden. Total es de $\(totalLabel.text!) la fecha registrada \(fechaRegistro)") 

     // Update URL with your server 
//  let paymentURL = URL(string: "https://your-server.example.com/payment-methods")! 
//  let request = NSMutableURLRequest(url: paymentURL) 
//  request.httpBody = "payment_method_nonce=\(paymentMethodNonce)".data(using: String.Encoding.utf8) 
//  request.httpMethod = "POST" 
//   
//  URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) -> Void in 
//   // TODO: Handle success or failure 
//   }.resume() 
     return true 

    } 

EDIT DropIn Payment method selected

Dummy card

を呼び出すことになっていますそれはただ閉じます。

+2

Braintreeをcocoapodでインストールする際にこのエラーが発生します。 "BraintreeDropInの仕様を見つけることができません" – VJVJ

+0

@ Pedro.Alonsonあなたは、製品のユーザーの金額を表示し、購入する方法を見つけましたか? – Ramis

+0

@VJVJ本当に私は今、私はOpenpayを使用しているフレームワークを変更しなければならなかった –

答えて

3

全開示:私はブレーントリーで働いています。ご不明な点がございましたら、supportまでお気軽にお問い合わせください。

オブジェクトのshowDropIn()でお支払い方法nonceにアクセスできます。これはpostNonceToServer()と呼ぶこともできます。あなたが成功しpostNonceToServer()呼び出した後

func showDropIn(clientTokenOrTokenizationKey: String) { 
    let request = BTDropInRequest() 
    request.amount = "\(total)" 
    request.currencyCode = "MXN" 
    let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request) 
    { (controller, result, error) in 
     if (error != nil) { 
      print("ERROR") 
     } else if (result?.isCancelled == true) { 
      print("CANCELLED") 
     } else if let result = result { 
      let selectedPaymentMethod = result.paymentMethod! // retrieve the payment method. 
      self.postNonceToServer(paymentMethodNonce: selectedPaymentMethod.nonce) // call postNonceToServer() with the nonce from the selected payment method. 
     } 
     controller.dismiss(animated: true, completion: nil) 
    } 
    self.present(dropIn!, animated: true, completion: nil) 
} 

あなたは、サーバー上のreceive the payment method noncecreate a transactionことができます。

+0

そして合計を表示するには? –

+1

@シェアBraintreeをcocoapodでインストールする際にこのエラーが発生します。 "BraintreeDropInの仕様を見つけることができません – VJVJ

関連する問題