2

アプリケーションの支払いプロセスに Braintree を使用しています
[BTPaymentViewController paymentViewControllerWithVenmoTouchEnabled:NO]; この方法を暗号化に使用します `

(void)paymentViewController:(BTPaymentViewController *)paymentViewController
        didSubmitCardWithInfo:(NSDictionary *)cardInfo
         andCardInfoEncrypted:(NSDictionary *)cardInfoEncrypted {
      NSDictionary *dict=[self encryptFormData:cardInfo];
      [self savePaymentInfoToServer:dict];
}

-(NSDictionary *) encryptFormData:(NSDictionary *) formData {
    BTEncryption *braintree = [[BTEncryption alloc] initWithPublicKey: PUBLIC_KEY];
    NSMutableDictionary *encryptedParams = [[NSMutableDictionary alloc] init];

    [formData enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
        [encryptedParams setObject: [braintree encryptString: object] forKey: key];
    }];

    return encryptedParams;
}

call to this method to post the data to localhost server for testing
- (void) savePaymentInfoToServer:(NSDictionary *)paymentInfo {
    NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@/card", SAMPLE_CHECKOUT_BASE_URL]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    // You need a customer id in order to save a card to the Braintree vault.
    // Here, for the sake of example, we set customer_id to device id.
    // In practice, this is probably whatever user_id your app has assigned to this user.
    //    NSString *customerId = [[UIDevice currentDevice] identifierForVendor].UUIDString;
    AppDelegate *appdelegate=(AppDelegate *) [[UIApplication sharedApplication]delegate];

    [paymentInfo setValue:appdelegate.referenceId forKey:@"bookingRefId"];
    [paymentInfo setValue:appdelegate.passengerId forKey:@"passengerId"];


    request.HTTPBody = [self postDataFromDictionary:paymentInfo];
    request.HTTPMethod = @"POST";
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *body, NSError *requestError)
     {
         NSError *err = nil;
         if (!response && requestError) {
             NSLog(@"requestError: %@", requestError);
             [self.paymentViewController showErrorWithTitle:@"Error" message:@"Unable to reach the network."];
             return;
         }

         NSDictionary *<b>responseDictionary</b> = [NSJSONSerialization JSONObjectWithData:body options:kNilOptions error:&err];
         NSLog(@"saveCardToServer: paymentInfo: %@ response: %@, error: %@", paymentInfo, responseDictionary, requestError);

         if ([[responseDictionary valueForKey:@"success"] isEqualToNumber:@1]) { // Success!
             // Don't forget to call the cleanup method,
             // `prepareForDismissal`, on your `BTPaymentViewController`
             [self.paymentViewController prepareForDismissal];
             // Now you can dismiss and tell the user everything worked.
             [self dismissViewControllerAnimated:YES completion:^(void) {
                 [[[UIAlertView alloc] initWithTitle:@"Success" message:@"Saved your card!" delegate:nil
                                   cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

             }];

         } else { // The card did not save correctly, so show the error from server with convenenience method `showErrorWithTitle`
             [self.paymentViewController showErrorWithTitle:@"Error saving your card" message:[self messageStringFromResponse:responseDictionary]];
         }
     }];
}`

responseDictionary が null でエラーが null である問題を修正する方法を教えてください。

4

1 に答える 1