Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed PaymentQueue

  • Loading branch information...
commit e606d8c1f394da1df5be83dc5db710b6a5e344af 1 parent a9aef5c
@masuidrive authored
View
10 Classes/JpMasuidriveTiStorekitModule.m
@@ -117,11 +117,21 @@ - (void)productsRequest:(SKProductsRequest *)request
#pragma Public APIs
+-(id)canMakePayments
+{
+ return NUMBOOL([SKPaymentQueue canMakePayments]);
+}
+
-(id)createPayment:(id)args
{
return [[[Payment alloc] _initWithPageContext:[self executionContext] args:args] autorelease];
}
+-(id)createPaymentQueue:(id)args
+{
+ return [[[PaymentQueue alloc] _initWithPageContext:[self executionContext] args:args] autorelease];
+}
+
-(void)findProducts:(id)args
{
ENSURE_ARG_COUNT(args, 2);
View
1  Classes/PaymentQueue.h
@@ -11,7 +11,6 @@
SKPaymentQueue* queue;
}
-(void)addPayment:(id)arg;
--(id)canMakePayments;
-(id)_initWithPageContext:(id<TiEvaluator>)context queue:(SKPaymentQueue*)queue_;
@end
View
28 Classes/PaymentQueue.m
@@ -16,7 +16,7 @@
@implementation PaymentQueue
-(id)_initWithPageContext:(id<TiEvaluator>)context
- queue:(SKPaymentQueue*)queue_
+ queue:(SKPaymentQueue*)queue_
{
if (self = [super _initWithPageContext:context]) {
queue = [queue_ retain];
@@ -32,6 +32,15 @@ -(void)dealloc
[super dealloc];
}
+- (SKPaymentQueue*)queue
+{
+ if(queue==nil) {
+ queue = [[[SKPaymentQueue alloc] init] autorelease];
+ [queue addTransactionObserver:self];
+ }
+ return [[queue retain] autorelease];
+}
+
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions) {
@@ -45,17 +54,17 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran
case SKPaymentTransactionStatePurchased:
[self fireEvent:@"purchased" withObject:evt];
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ [[self queue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self fireEvent:@"failed" withObject:evt];
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ [[self queue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self fireEvent:@"restored" withObject:evt];
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ [[self queue] finishTransaction:transaction];
break;
}
}
@@ -89,24 +98,19 @@ -(void)addPayment:(id)arg
{
ENSURE_SINGLE_ARG_OR_NIL(arg, Payment);
Payment* payment = (Payment*)arg;
- [[SKPaymentQueue defaultQueue] addPayment:payment.payment];
+ [[self queue] addPayment:payment.payment];
}
-(void)finishTransaction:(id)arg
{
ENSURE_SINGLE_ARG_OR_NIL(arg, PaymentTransaction);
PaymentTransaction* pt = arg;
- [[SKPaymentQueue defaultQueue] finishTransaction:pt.transaction];
+ [[self queue] finishTransaction:pt.transaction];
}
-(void)restoreCompletedTransactions:(id)arg
{
- [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
-}
-
--(id)canMakePayments
-{
- return NUMBOOL([SKPaymentQueue canMakePayments]);
+ [[self queue] restoreCompletedTransactions];
}
@end
View
2  example/app.js
@@ -36,7 +36,7 @@ var PaymentTestSuite = (function() {
return {
suiteName: "Payment Test Suite",
testCanMakePayments: function() {
- jsUnity.assertions.assertEqual(true, StoreKit.defaultPaymentQueue.canMakePayments);
+ jsUnity.assertions.assertEqual(true, StoreKit.canMakePayments);
},
testCreatePayment: function() {
var payment = StoreKit.createPayment();
Please sign in to comment.
Something went wrong with that request. Please try again.