     
     func collectCheckoutPreference() {
         self.presentLoading()
-        MPServicesBuilder.getPreference(self.viewModel.checkoutPreference._id, baseURL: MercadoPagoCheckoutViewModel.servicePreference.getDefaultBaseURL(), success: {(checkoutPreference : CheckoutPreference) -> Void in
-            self.viewModel.checkoutPreference = checkoutPreference
-            self.viewModel.paymentData.payer = checkoutPreference.getPayer()
-            self.dismissLoading()
-            self.executeNextStep()
-            
-        }, failure: {(error : NSError) -> Void in
-            self.dismissLoading()
-            self.viewModel.errorInputs(error: MPSDKError.convertFrom(error), errorCallback: { (Void) -> Void in
-               self.collectCheckoutPreference()
-            })
-            self.executeNextStep()
+        MPServicesBuilder.getPreference(self.viewModel.checkoutPreference._id, baseURL: MercadoPagoCheckoutViewModel.servicePreference.getDefaultBaseURL(), success: { [weak self] (checkoutPreference : CheckoutPreference) -> Void in
+            
+            guard let strongSelf = self else {
+                return
+            }
+            
+            strongSelf.viewModel.checkoutPreference = checkoutPreference
+            strongSelf.viewModel.paymentData.payer = checkoutPreference.getPayer()
+            strongSelf.dismissLoading()
+            strongSelf.executeNextStep()
+            
+            }, failure: { [weak self] (error : NSError) -> Void in
+                guard let strongSelf = self else {
+                    return
+                }
+                
+                strongSelf.dismissLoading()
+                strongSelf.viewModel.errorInputs(error: MPSDKError.convertFrom(error), errorCallback: { [weak self] (Void) -> Void in
+                    self?.collectCheckoutPreference()
+                })
+                strongSelf.executeNextStep()
         })
     }
     

        let cardInformation = self.viewModel.paymentOptionSelected as! CardInformation
        let saveCardToken = SavedCardToken(card: cardInformation, securityCode: securityCode, securityCodeRequired: true)
        
        MPServicesBuilder.createToken(saveCardToken, baseURL: MercadoPagoCheckoutViewModel.servicePreference.getGatewayURL(), success: { (token) in
            if token.lastFourDigits.isEmpty {
                token.lastFourDigits = cardInformation.getCardLastForDigits()
            }
            self.viewModel.updateCheckoutModel(token: token)
            self.dismissLoading()
            self.executeNextStep()
            
        }, failure: { (error) in
            self.dismissLoading()
            self.viewModel.errorInputs(error: MPSDKError.convertFrom(error), errorCallback: { (Void) in
                self.createSavedCardToken(cardInformation: cardInformation, securityCode: securityCode)
            })
            self.executeNextStep()
        })
    }
    
    func cloneCardToken(token: Token, securityCode: String) {
        self.presentLoading()
        MPServicesBuilder.cloneToken(token,securityCode:securityCode, success: { (token) in
            self.viewModel.updateCheckoutModel(token: token)
            self.dismissLoading()
            self.executeNextStep()
            
        }, failure: { (error) in
            self.dismissLoading()
            self.viewModel.errorInputs(error: MPSDKError.convertFrom(error), errorCallback: { (Void) in
                self.cloneCardToken(token: token, securityCode: securityCode)
            })
            self.executeNextStep()
        })
    }

    func collectPayerCosts(updateCallback:((Void)->Void)? = nil) {
        self.presentLoading()
        let bin = self.viewModel.cardToken?.getBin()
        MPServicesBuilder.getInstallments(bin, amount: self.viewModel.getFinalAmount(), issuer: self.viewModel.paymentData.issuer, paymentMethodId: self.viewModel.paymentData.paymentMethod._id, baseURL: MercadoPagoCheckoutViewModel.servicePreference.getDefaultBaseURL(),success: { (installments) -> Void in
            self.viewModel.payerCosts = installments[0].payerCosts
            
            let defaultPayerCost = self.viewModel.checkoutPreference.paymentPreference?.autoSelectPayerCost(installments[0].payerCosts)
            if let defaultPC = defaultPayerCost {
                self.viewModel.updateCheckoutModel(payerCost: defaultPC)
            }
            
            if let updateCallback = updateCallback {
                updateCallback()
                self.dismissLoading()
            } else {
                
                self.dismissLoading()
                self.executeNextStep()
            }
            
        }) { (error) -> Void in
            self.dismissLoading()
            self.viewModel.errorInputs(error: MPSDKError.convertFrom(error), errorCallback: { (Void) in
                self.collectPayerCosts()
            })
            self.executeNextStep()
        }
        
    }

    func createNewCardToken() {
        self.presentLoading()
        
        MPServicesBuilder.createNewCardToken(self.viewModel.cardToken!, baseURL: MercadoPagoCheckoutViewModel.servicePreference.getGatewayURL(), success: { [weak self] (token : Token?) -> Void in
            guard let strongSelf = self else {
                return
            }
            
            strongSelf.viewModel.updateCheckoutModel(token: token!)
            strongSelf.dismissLoading()
            strongSelf.executeNextStep()
            
            }, failure : { [weak self] (error) -> Void in
                guard let strongSelf = self else {
                    return
                }
                
                strongSelf.viewModel.errorInputs(error: MPSDKError.convertFrom(error), errorCallback: { [weak self] (Void) in
                    self?.createNewCardToken()
                })
                strongSelf.dismissLoading()
                strongSelf.executeNextStep()
        })
    }
    
