Skip to content

Commit

Permalink
underp
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunk Fordyce authored and Dunk Fordyce committed May 14, 2015
1 parent b8b056d commit c2cbbae
Show file tree
Hide file tree
Showing 4 changed files with 624 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/ios/Base64.h
@@ -0,0 +1,24 @@
//
// Base64.h
//
// Created by SARATH DR on 07/03/2013.
//
//

#import <Foundation/Foundation.h>

@interface Base64 : NSObject {

}

+ (void) initialize;

+ (NSString*) encode:(const uint8_t*) input length:(NSInteger) length;

+ (NSString*) encode:(NSData*) rawBytes;

+ (NSData*) decode:(const char*) string length:(NSInteger) inputLength;

+ (NSData*) decode:(NSString*) string;

@end
95 changes: 95 additions & 0 deletions src/ios/Base64.m
@@ -0,0 +1,95 @@
//
// Base64.m
//
// Created by SARATH DR on 07/03/2013.
//
//

#import "Base64.h"


@implementation Base64
#define ArrayLength(x) (sizeof(x)/sizeof(*(x)))

static char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char decodingTable[128];

+ (void) initialize {
if (self == [Base64 class]) {
memset(decodingTable, 0, ArrayLength(decodingTable));
for (NSInteger i = 0; i < ArrayLength(encodingTable); i++) {
decodingTable[encodingTable[i]] = i;
}
}
}


+ (NSString*) encode:(const uint8_t*) input length:(NSInteger) length {
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;

for (NSInteger i = 0; i < length; i += 3) {
NSInteger value = 0;
for (NSInteger j = i; j < (i + 3); j++) {
value <<= 8;

if (j < length) {
value |= (0xFF & input[j]);
}
}

NSInteger index = (i / 3) * 4;
output[index + 0] = encodingTable[(value >> 18) & 0x3F];
output[index + 1] = encodingTable[(value >> 12) & 0x3F];
output[index + 2] = (i + 1) < length ? encodingTable[(value >> 6) & 0x3F] : '=';
output[index + 3] = (i + 2) < length ? encodingTable[(value >> 0) & 0x3F] : '=';
}

return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}


+ (NSString*) encode:(NSData*) rawBytes {
return [self encode:(const uint8_t*) rawBytes.bytes length:rawBytes.length];
}


+ (NSData*) decode:(const char*) string length:(NSInteger) inputLength {
if ((string == NULL) || (inputLength % 4 != 0)) {
return nil;
}

while (inputLength > 0 && string[inputLength - 1] == '=') {
inputLength--;
}

NSInteger outputLength = inputLength * 3 / 4;
NSMutableData* data = [NSMutableData dataWithLength:outputLength];
uint8_t* output = data.mutableBytes;

NSInteger inputPoint = 0;
NSInteger outputPoint = 0;
while (inputPoint < inputLength) {
char i0 = string[inputPoint++];
char i1 = string[inputPoint++];
char i2 = inputPoint < inputLength ? string[inputPoint++] : 'A'; /* 'A' will decode to \0 */
char i3 = inputPoint < inputLength ? string[inputPoint++] : 'A';

output[outputPoint++] = (decodingTable[i0] << 2) | (decodingTable[i1] >> 4);
if (outputPoint < outputLength) {
output[outputPoint++] = ((decodingTable[i1] & 0xf) << 4) | (decodingTable[i2] >> 2);
}
if (outputPoint < outputLength) {
output[outputPoint++] = ((decodingTable[i2] & 0x3) << 6) | decodingTable[i3];
}
}

return data;
}


+ (NSData*) decode:(NSString*) string {
return [self decode:[string cStringUsingEncoding:NSASCIIStringEncoding] length:string.length];
}

@end
70 changes: 70 additions & 0 deletions src/ios/IOSStoreKit.h
@@ -0,0 +1,70 @@
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVPluginResult.h>
#import <StoreKit/StoreKit.h>
#import <Foundation/Foundation.h>
#import "Base64.h"


@interface SubscriptionManager : CDVPlugin <SKPaymentTransactionObserver, SKRequestDelegate>
{
NSSet* productIdentifier;
SKProduct* subscription;
NSString* productId;
NSString* callBackId;
NSString* eventCallbackid;
NSMutableDictionary* allProducts;
NSMutableSet* delegates;
SKReceiptRefreshRequest* refreshRequest;
}

@property (retain) NSSet *productIdentifier;
@property (retain) SKProductsRequest *request;
@property (retain) SKProduct *subscription;
@property (retain) NSString *productId;
@property (retain) NSMutableDictionary *allProducts;
@property (nonatomic,retain) NSString *callbackId;
@property (nonatomic,retain) NSString *eventCallbackId;
@property (retain) NSMutableSet* delegates;
@property (strong, retain) SKReceiptRefreshRequest* refreshRequest;


-(void) emitEvent:(NSString*)evname object:(NSObject*) result;
-(void) commandReply:(CDVInvokedUrlCommand*) command withDictionary:(NSDictionary*) obj;
-(void) commandReply:(CDVInvokedUrlCommand*) command withError:(NSString*) msg;

-(NSData *)readAppStoreReceipt;
-(void) receiptDone: (CDVInvokedUrlCommand*)command data:(NSData*)receiptData;

-(NSMutableDictionary*) serializeTransaction: (SKPaymentTransaction*)transaction;

-(void) init:(CDVInvokedUrlCommand*) command;
-(void) receipt: (CDVInvokedUrlCommand*)command;
-(void) purchase :(CDVInvokedUrlCommand*)command;
-(void) product: (CDVInvokedUrlCommand*)command;
-(void) finish:(CDVInvokedUrlCommand*) command;
-(void) transactions:(CDVInvokedUrlCommand*) command;

-(void) dealloc;
-(void) pluginInitialize;
@end


@interface ProductsRequestDelegate : NSObject <SKProductsRequestDelegate> {
SubscriptionManager* plugin;
CDVInvokedUrlCommand* command;
}
@property (retain) SubscriptionManager* plugin;
@property (retain) CDVInvokedUrlCommand* command;
@end



@interface ProductsRefreshDelegate : NSObject <SKRequestDelegate> {
SubscriptionManager* plugin;
CDVInvokedUrlCommand* command;
}
@property (retain) SubscriptionManager* plugin;
@property (retain) CDVInvokedUrlCommand* command;
@end


0 comments on commit c2cbbae

Please sign in to comment.