forked from MKSG-MugunthKumar/MKStoreKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MKStoreObserver.m
107 lines (83 loc) · 3.41 KB
/
MKStoreObserver.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// MKStoreObserver.m
// MKStoreKit (Version 4.0)
//
// Created by Mugunth Kumar on 17-Nov-2010.
// Version 4.1
// Copyright 2010 Steinlogic. All rights reserved.
// File created using Singleton XCode Template by Mugunth Kumar (http://mugunthkumar.com
// Permission granted to do anything, commercial/non-commercial with this file apart from removing the line/URL above
// As a side note on using this code, you might consider giving some credit to me by
// 1) linking my website from your app's website
// 2) or crediting me inside the app's credits page
// 3) or a tweet mentioning @mugunthkumar
// 4) A paypal donation to [email protected]
//
// A note on redistribution
// While I'm ok with modifications to this source code,
// if you are re-publishing after editing, please retain the above copyright notices
#import "MKStoreObserver.h"
#import "MKStoreManager.h"
@interface MKStoreManager (InternalMethods)
// these three functions are called from MKStoreObserver
- (void) transactionCanceled: (SKPaymentTransaction *)transaction;
- (void) failedTransaction: (SKPaymentTransaction *)transaction;
- (void) provideContent: (NSString*) productIdentifier
forReceipt: (NSData*) recieptData;
@end
@implementation MKStoreObserver
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
[[MKStoreManager sharedManager] restoreFailedWithError:error];
}
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
[[MKStoreManager sharedManager] restoreCompleted];
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
[[MKStoreManager sharedManager] transactionCanceled:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
#if TARGET_OS_IPHONE
[[MKStoreManager sharedManager] provideContent:transaction.payment.productIdentifier
forReceipt:transaction.transactionReceipt];
#elif TARGET_OS_MAC
[[MKStoreManager sharedManager] provideContent:transaction.payment.productIdentifier
forReceipt:nil];
#endif
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
#if TARGET_OS_IPHONE
[[MKStoreManager sharedManager] provideContent: transaction.originalTransaction.payment.productIdentifier
forReceipt:transaction.transactionReceipt];
#elif TARGET_OS_MAC
[[MKStoreManager sharedManager] provideContent: transaction.originalTransaction.payment.productIdentifier
forReceipt:nil];
#endif
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
@end