Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:35:50+00:00 2026-06-06T17:35:50+00:00

I am implementing in app purchase (non consumable type – songs ).when a user

  • 0

I am implementing in app purchase (non consumable type – songs ).when a user taps buy for every song purchase i call startPurchase funtion.my song content is delivered via my server.

In that when i purchased something and again try to re purchase the same, it is not treated as restore of purchase.it makes a new purchase.the delegate methods are called multiple times

Actually what is my problem is, i tap buy and proceed with the payment, and purchased that item.

Again when i try to buy the same item the apple alert says as “You have already purchased this item, tap ok to download” when i tap “OK“.this is not coming under SKPaymentTransactionStateRestored instead it goes to SKPaymentTransactionStatePurchased.why this is happening? pls help

Please help me out

- (void)startPurchase:(NSString*)inProductId{

  if ([SKPaymentQueue canMakePayments])
  {
     myProductId = inProductId

    SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:myProductId]];
    productsRequest.delegate = self;
    [productsRequest start];
  }
  else {
    NSLog(@"Parental-controls are enabled");
      }

}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:
  (SKProductsResponse *)response {

  NSLog(@"response received");
  SKProduct *validProduct = nil;
  int count = [response.products count];

  UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" message:
  [NSString stringWithFormat:@"%d",response.products.count] delegate:
  self cancelButtonTitle:@"OK" otherButtonTitles:nil];

  [alert show];
  [alert release];

  if (count > 0) {
    validProduct = [response.products objectAtIndex:0];
    NSLog(@"products available");
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:myProductId];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
  }
  else if (!validProduct) {
    NSLog(@"No products available");
  }
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        SKPayment *payment = [transaction payment];

      if([payment.productIdentifier isEqualToString:myProductId])
      {
          NSLog(@"%@payement queue payment.productIdentifier",payment.productIdentifier);

        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                NSLog(@"completeTransaction");
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                NSLog(@"failedTransaction");
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"restoreTransaction");
                [self restoreTransaction:transaction];
            default:
                break;
        }
      }
    }
}

- (void)provideContent:(NSString *)productIdentifier
{
    NSLog(@"Provide Content %@", productIdentifier);

    }

- (void)recordTransaction:(SKPaymentTransaction *)transaction {
    NSLog(@"inside the recordTransaction");

}

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
    [self recordTransaction: transaction];
    [self provideContent: transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];


}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
    NSLog(@"restoreTransaction transaction inside");

   }

- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        if(transaction.error.code == SKErrorUnknown) {
            NSLog(@"Unknown Error (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
            UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
            message: @"There was an error purchasing this item please try again."
            delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
            [failureAlert show];
            [failureAlert release];
        }

        if(transaction.error.code == SKErrorClientInvalid) {
            NSLog(@"Client invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
            UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
            message: @"There was an error purchasing this item please try again."
            delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
            [failureAlert show];
            [failureAlert release];
        }

        if(transaction.error.code == SKErrorPaymentInvalid) {
            NSLog(@"Payment invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
            UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
            message: @"There was an error purchasing this item please try again."
            delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
            [failureAlert show];
            [failureAlert release];
        }

        if(transaction.error.code == SKErrorPaymentNotAllowed) {
            NSLog(@"Payment not allowed (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
            UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
            message: @"There was an error purchasing this item please try again."
            delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
            [failureAlert show];
            [failureAlert release];
        }
    }
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:35:51+00:00Added an answer on June 6, 2026 at 5:35 pm

    I think your problem add transaction server duplicate reflecting
    Try below code for avoid add transaction server duplicate may be it’s worked:

    - (void)startPurchase:(NSString*)inProductId{
    
      if ([SKPaymentQueue canMakePayments])
      {
         myProductId = inProductId
    
        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:myProductId]];
        productsRequest.delegate = self;
        [productsRequest start];
      }
      else {
        NSLog(@"Parental-controls are enabled");
          }
    
    }
    static bool hasAddObserver=NO;
    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:
      (SKProductsResponse *)response {
    
      NSLog(@"response received");
      SKProduct *validProduct = nil;
      int count = [response.products count];
    
      UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" message:
      [NSString stringWithFormat:@"%d",response.products.count] delegate:
      self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    
      [alert show];
      [alert release];
    
      if (count > 0) {
        validProduct = [response.products objectAtIndex:0];
        NSLog(@"products available");
        SKPayment *payment = [SKPayment paymentWithProductIdentifier:myProductId];
        if (!hasAddObserver) {
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        hasAddObserver=YES;
        }
        [[SKPaymentQueue defaultQueue] addPayment:payment];
      }
      else if (!validProduct) {
        NSLog(@"No products available");
      }
    }
    
    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
    {
        for (SKPaymentTransaction *transaction in transactions)
        {
            SKPayment *payment = [transaction payment];
    
          if([payment.productIdentifier isEqualToString:myProductId])
          {
              NSLog(@"%@payement queue payment.productIdentifier",payment.productIdentifier);
    
            switch (transaction.transactionState)
            {
                case SKPaymentTransactionStatePurchased:
                    NSLog(@"completeTransaction");
                    [self completeTransaction:transaction];
                    break;
                case SKPaymentTransactionStateFailed:
                    NSLog(@"failedTransaction");
                    [self failedTransaction:transaction];
                    break;
                case SKPaymentTransactionStateRestored:
                    NSLog(@"restoreTransaction");
                    [self restoreTransaction:transaction];
                default:
                    break;
            }
          }
        }
    }
    
    - (void)provideContent:(NSString *)productIdentifier
    {
        NSLog(@"Provide Content %@", productIdentifier);
    
        }
    
    - (void)recordTransaction:(SKPaymentTransaction *)transaction {
        NSLog(@"inside the recordTransaction");
    
    }
    
    - (void) completeTransaction: (SKPaymentTransaction *)transaction
    {
        [self recordTransaction: transaction];
        [self provideContent: transaction.payment.productIdentifier];
        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    
    
    }
    
    - (void) restoreTransaction: (SKPaymentTransaction *)transaction
    {
        NSLog(@"restoreTransaction transaction inside");
    
       }
    
    - (void) failedTransaction: (SKPaymentTransaction *)transaction
    {
        if (transaction.error.code != SKErrorPaymentCancelled)
        {
            if(transaction.error.code == SKErrorUnknown) {
                NSLog(@"Unknown Error (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
                UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
                message: @"There was an error purchasing this item please try again."
                delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
                [failureAlert show];
                [failureAlert release];
            }
    
            if(transaction.error.code == SKErrorClientInvalid) {
                NSLog(@"Client invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
                UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
                message: @"There was an error purchasing this item please try again."
                delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
                [failureAlert show];
                [failureAlert release];
            }
    
            if(transaction.error.code == SKErrorPaymentInvalid) {
                NSLog(@"Payment invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
                UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
                message: @"There was an error purchasing this item please try again."
                delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
                [failureAlert show];
                [failureAlert release];
            }
    
            if(transaction.error.code == SKErrorPaymentNotAllowed) {
                NSLog(@"Payment not allowed (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
                UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
                message: @"There was an error purchasing this item please try again."
                delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
                [failureAlert show];
                [failureAlert release];
            }
        }
        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    }
    

    In your i am check the transaction server is added or not below code:

    if (!hasAddObserver) {
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        hasAddObserver=YES;
        }
    

    hasAddObserver Variable static bool datatype is check if already added easy to added check transaction server!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am midway in implementing in app purchase (SONGS-non consumable - content delivery from
I'm currently implementing a non-renewable in-app purchase and am a little concerned over the
I am trying to implement the in-App purchase of non-consumable goods. I have implemented
I am implementing an application using in app purchase with non-consumables items, it was
I am implementing in app purchase in my application. as per the requirement product
I am implementing In App purchase in my application. What I want to do
I'm implementing an in app purchase for an iPhone app. All is good -
I'm implementing an in-app camera and every time I take a picture my image
I'm implementing in app purchase in my app. I created a product at itunes
I'm planning on implementing some in-app purchase items and I want to save purchase

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.