12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

購入レシート情報をアプリからサーバに渡す

Posted at

はじめに

iPhoneアプリから、レシート情報をBase64に変換しサーバにPOSTする部分です。

POST部分はAFNetworkingを使用しています。
こちらを参考にしてください。
AFNetworkingのPOSTでJSONが空になってしまう場合

サーバ側では受け取った後にレシート検証をしています。
C#でのInAppPurchaseレシート検証処理(App Storeを使用)

レシート情報の取得とエンコード

    // レシート情報の取得、エンコード、パラメータ作成
    NSURL *receiptFileURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:receiptFileURL];

    NSString *receiptStr = [receipt base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    NSDictionary *param = @{@"receipt_data":receiptStr};

POST

    AFHTTPRequestOperation *operation = [WCFUtil makeRequestOperation:@"purchase" param:param timeoutInterval:30];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *op, id responseObject) {
        
        NSError *parseError = nil;
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&parseError];
        
        if ([json[@"result"] isEqualToString:@"OK"]) {
            // 正常完了時処理
        }
        else {
            // 失敗時処理
        }
        
    } failure:^(AFHTTPRequestOperation *op, NSError *error) {
        NSLog(@"Error: %@", [error localizedDescription]);
    }];
    
    // 実行
    [operation start];

おわりに

何かの参考になりましたら幸いです。

いくつか課金処理のパーツを小出しにしたので
出しきった後、流れをまとめようかと思います。

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?