iOS Square Register Popover OpenURL 问题
iOS Square Register Popover OpenURL Issue
Square 最近删除了 "Initiating a Square Register transaction from your app" 部分中概述的 here OAuth 商家授权要求。
当我的应用程序弹出到 Square Register 应用程序时,Square 应用程序中会出现一个警告弹出窗口,内容为:
"API Error: No client ID specified"
尽管我在调用 open square 时在我的应用程序中清楚地列出了我的 "client_id"。我的代码如下。 有什么解决办法吗?
-(void)squarePaymentWithName:(NSString *)name{
//Specify amount of money to charge
float orderPriceFloat = [Order orderTotalPrice];
float orderPriceFloatCents = orderPriceFloat * 100;
NSInteger orderPriceFloatCentsInteger = [[NSNumber numberWithFloat:orderPriceFloatCents] integerValue];
NSString *amountString = [NSString stringWithFormat:@"%ld", (long)orderPriceFloatCentsInteger];
NSDictionary *squareDictionary = @{@"callback_url": @"<CALLBACK_URL>",
@"client_id": @"<CLIENT_ID>",
@"version": @"1.2",
@"amount_money":
@{@"amount": amountString,
@"currency_mode":@"USD"
},
@"options":
@{@"supported_tender_types": @[@"CREDIT_CARD", @"SQUARE_GIFT_CARD"],
@"auto_return": @"true"
}
};
NSString *jsonString = [NSString stringWithFormat:@"%@", squareDictionary];
NSString *encodedString = [jsonString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //encode the string
NSString *scheme = [NSString stringWithFormat:@"square-commerce-v1://payment/create?data=%@", encodedString]; //input the string to the url
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
BOOL canOpen = [application canOpenURL:URL]; //open the url
[application openURL:URL];
}
jsonString的NSLog为:
{
"amount_money" = {
amount = 250;
"currency_mode" = USD;
};
"callback_url" = CALLBACK_URL;
"client_id" = CLIENT_ID;
options = {
"auto_return" = true;
"supported_tender_types" = (
"CREDIT_CARD",
"SQUARE_GIFT_CARD"
);
};
version = "1.2";
}
encodedString的NSLog为:
另外,请注意,我输入的 'CALLBACK_URL' 和 'CLIENT_ID' 是占位符,因为我不想输入实际值。
谢谢!
这是我使用的有效代码:
NSDictionary *squareDictionary = @{@"callback_url": CALLBACK_URL,
@"client_id": CLIENTID,
@"version": @"1.2",
@"notes": notes,
@"state": name,
@"amount_money":
@{@"amount": amountString,
@"currency_code":@"USD"
},
@"options":
@{@"supported_tender_types": @[@"CREDIT_CARD"],
@"auto_return": @"true"
}
};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:squareDictionary
options:NSJSONWritingPrettyPrinted
error:&error]; // Pass 0 if you don't care about the readability of the generated string
NSString *jsonString;
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *encodedString = [jsonString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //encode the string
NSString *scheme = [NSString stringWithFormat:@"square-commerce-v1://payment/create?data=%@", encodedString]; //input the string to the url
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
BOOL canOpen = [application canOpenURL:URL]; //open the url
if (canOpen) {
[application openURL:URL];
} else {
NSLog(@"couldn't open app");
}
}
Square 最近删除了 "Initiating a Square Register transaction from your app" 部分中概述的 here OAuth 商家授权要求。
当我的应用程序弹出到 Square Register 应用程序时,Square 应用程序中会出现一个警告弹出窗口,内容为:
"API Error: No client ID specified"
尽管我在调用 open square 时在我的应用程序中清楚地列出了我的 "client_id"。我的代码如下。 有什么解决办法吗?
-(void)squarePaymentWithName:(NSString *)name{
//Specify amount of money to charge
float orderPriceFloat = [Order orderTotalPrice];
float orderPriceFloatCents = orderPriceFloat * 100;
NSInteger orderPriceFloatCentsInteger = [[NSNumber numberWithFloat:orderPriceFloatCents] integerValue];
NSString *amountString = [NSString stringWithFormat:@"%ld", (long)orderPriceFloatCentsInteger];
NSDictionary *squareDictionary = @{@"callback_url": @"<CALLBACK_URL>",
@"client_id": @"<CLIENT_ID>",
@"version": @"1.2",
@"amount_money":
@{@"amount": amountString,
@"currency_mode":@"USD"
},
@"options":
@{@"supported_tender_types": @[@"CREDIT_CARD", @"SQUARE_GIFT_CARD"],
@"auto_return": @"true"
}
};
NSString *jsonString = [NSString stringWithFormat:@"%@", squareDictionary];
NSString *encodedString = [jsonString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //encode the string
NSString *scheme = [NSString stringWithFormat:@"square-commerce-v1://payment/create?data=%@", encodedString]; //input the string to the url
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
BOOL canOpen = [application canOpenURL:URL]; //open the url
[application openURL:URL];
}
jsonString的NSLog为:
{
"amount_money" = {
amount = 250;
"currency_mode" = USD;
};
"callback_url" = CALLBACK_URL;
"client_id" = CLIENT_ID;
options = {
"auto_return" = true;
"supported_tender_types" = (
"CREDIT_CARD",
"SQUARE_GIFT_CARD"
);
};
version = "1.2";
}
encodedString的NSLog为:
另外,请注意,我输入的 'CALLBACK_URL' 和 'CLIENT_ID' 是占位符,因为我不想输入实际值。
谢谢!
这是我使用的有效代码:
NSDictionary *squareDictionary = @{@"callback_url": CALLBACK_URL,
@"client_id": CLIENTID,
@"version": @"1.2",
@"notes": notes,
@"state": name,
@"amount_money":
@{@"amount": amountString,
@"currency_code":@"USD"
},
@"options":
@{@"supported_tender_types": @[@"CREDIT_CARD"],
@"auto_return": @"true"
}
};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:squareDictionary
options:NSJSONWritingPrettyPrinted
error:&error]; // Pass 0 if you don't care about the readability of the generated string
NSString *jsonString;
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *encodedString = [jsonString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //encode the string
NSString *scheme = [NSString stringWithFormat:@"square-commerce-v1://payment/create?data=%@", encodedString]; //input the string to the url
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
BOOL canOpen = [application canOpenURL:URL]; //open the url
if (canOpen) {
[application openURL:URL];
} else {
NSLog(@"couldn't open app");
}
}