2015-04-30 15 views
8

của Apple documentation to test a subscription mua trong chế độ Sandbox nói rằng:Tôi làm cách nào để kiểm tra việc hủy đăng ký trong mua hàng trong ứng dụng trên Store Kit?

"Để kiểm tra xem mua hàng đã bị hủy, tìm kiếm các lĩnh vực Cancellation Date trong việc tiếp nhận Nếu trường có một ngày trong nó, không phụ thuộc vào thuê bao của. ngày hết hạn, giao dịch mua đã bị hủy — xử lý biên lai đã hủy giống như không có giao dịch mua nào được thực hiện ".

Nhưng nhận không hiển thị một Cancellation Date lĩnh vực:

"expires_date" = "2015-04-29 16:46:26 Etc/GMT"; 
"expires_date_ms" = 1430325986000; 
"expires_date_pst" = "2015-04-29 09:46:26 America/Los_Angeles"; 
"is_trial_period" = false; 
"original_purchase_date" = "2015-04-29 16:27:40 Etc/GMT"; 
"original_purchase_date_ms" = 1430324860000; 
"original_purchase_date_pst" = "2015-04-29 09:27:40 America/Los_Angeles"; 
"original_transaction_id" = 1000000153387111; 
"product_id" = ...; 
"purchase_date" = "2015-04-29 16:31:26 Etc/GMT"; 
"purchase_date_ms" = 1430325086000; 
"purchase_date_pst" = "2015-04-29 09:31:26 America/Los_Angeles"; 
quantity = 1; 
"transaction_id" = ...; 
"web_order_line_item_id" = ...; 

Apple nói không để quản lý thuê bao của người dùng, và tham khảo iTunes thay vì:

"Thay vì cần đến mã UI quản lý đăng ký của riêng bạn, ứng dụng của bạn có thể mở URL sau: https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions Mở URL này khởi chạy iTunes hoặc iTunes Store, sau đó hiển thị trang Quản lý đăng ký ".

Nhưng điều này không thể được kiểm tra bằng tài khoản Sandbox (yêu cầu thẻ tín dụng). Và tôi thực sự cần kiểm tra các đăng ký bị hủy.

Đây là mã tôi sử dụng để có được những nhận:

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:receiptURL]; 
NSURLResponse *response = nil; 
NSError *error = nil; 
NSData *receipt = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

if (receipt) { 
    // Create the JSON object that describes the request 
    NSError *error; 
    NSDictionary *requestContents = @{ 
             @"receipt-data": [receipt base64EncodedStringWithOptions:0], 
             @"password": @"...", 
             }; 
    NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents 
                  options:0 
                  error:&error]; 

    if (!requestData) { 
     NSLog(@"Unable to serialise json data. Possible user/password mistake. Error: %@", error); 
    } 

    // Create a POST request with the receipt data. 
    NSURL *storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"]; 
    NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL]; 
    [storeRequest setHTTPMethod:@"POST"]; 
    [storeRequest setHTTPBody:requestData]; 

    // Make a connection to the iTunes Store on a background queue. 
    NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
    [NSURLConnection sendAsynchronousRequest:storeRequest queue:queue 
          completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 
           if (connectionError) { 
            NSLog(@"Connection error: %@", connectionError); 
           } else { 
            NSError *error; 
            NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; 
            NSArray *receiptInfo = jsonResponse[@"latest_receipt_info"]; 
            NSInteger total = receiptInfo.count; 
            NSDictionary *receiptDict = receiptInfo[total-1]; 
            NSLog(@"Json: %@", receiptInfo); 

Trả lời

0

Sử dụng tài khoản táo thực sự. Đó là cách duy nhất tôi biết về công việc đó. Nếu bạn chắc chắn rằng mã của bạn đang làm việc với ví dụ trong tài liệu, bạn nên ổn.

Các vấn đề liên quan