2017-08-02 35 views
2

我似乎無法找到將我的令牌發送到我的firebase後端的代碼。發送令牌到後端條帶目標c

- (void)addCardViewController:(STPAddCardViewController *)addCardViewController didCreateToken:(STPToken *)token completion:(STPErrorBlock)completion { 
    [self submitTokenToBackend:token completion:^(NSError *error) { 
     if (error) { 
      completion(error); 
     } else { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       [self showReceiptPage]; 
      }]; 
     } 
    }]; 
} 

回答

1

試試這個代碼,

STPAddress *address = [[STPAddress alloc] init]; 
address.name ="Test"; 
address.line1 = @"Test Address-1"; 
address.line2 = @"Test Address-2"; 
address.city = @"City"; 
address.postalCode = @"1234"; 
address.state = @"State"; 
address.country = @"Country"; 



STPCard *stripCard; 
stripCard = [[STPCard alloc] init]; 
stripCard.number = strCard_Number; 
stripCard.cvc = strCard_Cvv; 
stripCard.expMonth = month; 
stripCard.expYear = year; 
stripCard.address = address; 
stripCard.currency = @"INR"; 


[[STPAPIClient sharedClient] createTokenWithCard:stripCard completion:^(STPToken * _Nullable token, NSError * _Nullable error) 
{ 
     NSString *strMess= @""; 
     if(error) { 
      strMess = [error localizedDescription];  
     } 
     else { 
      strMess = stringValue(token.tokenId); 
      strMess = [NSString stringWithFormat:@"Token:\n-------\n%@\n\n\nCard Details:\n-------\n%@",strMess,token.allResponseFields]; 
      //[Function showAlertMessage:strMess autoHide:NO]; 

      NSString *strToken = @""; 
      strToken = token.tokenId; 

      NSLog(@"strToken: %@",strToken); 
     } 
     NSLog(@"strMess: %@",strMess); 
}]; 
+0

令牌在我的方法已創建。在Stripe文檔中指出:(注意:本指南中的示例假定您已經編寫了一個名爲submitTokenToBackend的函數:completion:它將您的STPToken發送到您的服務器)。我似乎無法做出這個功能。 – saud

+0

每次我嘗試選擇器不被識別或用作參數 – saud

+0

閱讀條紋的官方文檔,使用這個令牌,你稱爲web服務在條紋指導中提及 –