Square recently removed the requirement for OAuth merchant authorization as outlined here in the "Initiating a Square Register transaction from your app" section.
When my app pops over to the Square Register app, an alert popup appears in the Square app saying:
"API Error: No client ID specified"
despite the fact that I clearly list my "client_id" in my app when I call to open square. My code is below. Any ideas how to fix it?
-(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];
}
The NSLog of jsonString is:
{
"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";
}
The NSLog of encodedString is:
And, as a note, the 'CALLBACK_URL' and 'CLIENT_ID' I input are placeholders since I didn't want to put the real values in.
Thanks!
Here's the code I used that worked: