CFSDK payment gateway 'Invalid token sent in request' - ios

I am working on an app in which I need to integrate payment gateway and I am using Cashfree payment gateway WebView Checkout option as per the need. It is easy to implement from their docs. This is how I initiate SDK:
func initiateCFSDK() {
let cashfreeVC = CFViewController(params: getPaymentParams(), appId: self.appId, env: self.environmentCF, callBack: self)
let navVC = UINavigationController(rootViewController: cashfreeVC)
self.present(navVC, animated: true, completion: nil)
}
Payment parameters:
func getPaymentParams() -> Dictionary<String, String> {
return [
"orderId": self.orderId,
"tokenData" : self.paymentToken,
"orderAmount": self.paymentValue,
"customerName": "name",
"orderNote": "health prodcuts",
"orderCurrency": "INR",
"customerPhone": "9876543210",
"customerEmail": "abc#gmail.com",
"notifyUrl": "https://test.gocashfree.com/notify"
]
}
From their docs, we need to drag and drop framework to Xcode project and add it to Embedded Binaries. The token in generated from the backend using the orderId and need to pass it in payment parameters.
Problem 1:
Everytime I Initiate SDK it gives me error: "Invalid token sent in request" and prints following result in delegate method:
Finished navigating to url https://test.cashfree.com/billpay/checkout/post/submit
JSON value : {"orderId":"","referenceId":"","orderAmount":"","txMsg":"Invalid token sent in request","txTime":"","txStatus":"FAILED","paymentMode":"","signature":""}
Following is the screenshot for the reference.
Problem 2:
Since I present the SDK by embedding inside a UINavigationController, when I press back button it can't dismiss itself.
I am banging my head from many weeks for the error (Invalid token) I can't resolve. So anyone here tried it and please take a look what is wrong? Looking forward for the solutions from SO.
P.S: I tried contacting their tech support and everytime they just sent link to their docs.

I have prepared demo project with Cash Free SDK, Using Xcode 11.0
Step 1
To Generate the token , I have used in postman
https://test.cashfree.com/api/v2/cftoken/order
with parameters
{
"orderId":"ORD123456",
"orderAmount":"30",
"orderCurrency":"INR"
}
with following headers
Content-Type:application/json
X-Client-Id:XXXXXXX
X-Client-Secret:XXXXXX
Step 2
Now In code
func initiateCFSDK() {
let cashfreeVC = CFViewController(params: getPaymentParams(), appId: "xxxxxxxxxxx", env: "TEST", callBack: self)
self.navigationController?.pushViewController(cashfreeVC, animated: true)
}
func getPaymentParams() -> Dictionary<String, String> {
return [
"orderId": "ORD123456",
"tokenData" : "<<TOKEN FROM POSTMAN REQUEST>>",
"orderAmount": "30",
"customerName": "name",
"orderNote": "health prodcuts",
"orderCurrency": "INR",
"customerPhone": "9876543210",
"customerEmail": "abc#gmail.com",
"notifyUrl": "https://test.gocashfree.com/notify"
]
}
Here Nothing changed just used TEST environment and passed the appid and token
Notes:
make sure you are using TEST environment URL to generate token with TEST environment client id and client secret
also check notifyUrl
Order ID should be same
make sure you are not using old or expired tokens
Problem 2 : Don't bother to present , just push this controller :)
Cheers !! :)

Related

How do i get EC_v1 version of Apple Pay PaymentToken

I'm trying to Integrate Apple Pay in my application. Following the online docs and some SO help, I've managed to show the Apple Pay payment dialog and all the call backs are configured.
the response returned from the Apple Pay is something like this
{
"version": "RSA_v1",
"signature": "somestring",
"data": "DP...A=",
"header": {
"wrappedKey": "MF...5g==",
"publicKeyHash": "kd...l4=",
"transactionId": "a5...3e"
}
}
But my requirement is to get ephemeralPublicKey under header object. According to Apple Pay Payment Token Format Reference
the returned object is correct as its RSA_v1 version which will not have ephemeralPublicKey but wrappedKey. Now my question is how do i get EC_v1 version of the returned token object.
May be I'm missing something here in the docs but please someone point me to the right direction. Any help is appreciated.
Here is the way to get this returned response from the Apple Pay Gateway server. You can't see this response in the console directly. You can see this response only if you will log it on the server by using an ajax request. See mine below sample URL and my source code.
Full Documentation for beginners
https://gist.github.com/jagdeepsingh/c538e21f3839f65732a5932e35809d60
session.onpaymentauthorized = (event) => {
$("#paymentMethodVal").val("apple-pay");
$form = $("#reservation-form");
console.log($form.serialize());
callRequest({
url: '/reserve/init-apple-pay',
method: 'POST',
data: {
token: event.payment.token,
reservationData: $form.serialize()
},
beforeRequest: function(e) {},
afterRequest: function(response) {
response = JSON.parse(response);
if(response.status){
toastr.success(response.message);
session.completePayment(ApplePaySession.STATUS_SUCCESS);
}else{
toastr.error(response.message.split(/\r\n|\r|\n/g).join('<br/>'));
session.completePayment(ApplePaySession.STATUS_FAILURE);
}
}
});
};
token: event.payment.token, line is your answer this will send data directly to server and you can log data over there.
{
"version": "RSA_v1",
"signature": "somestring",
"data": "DP...A=",
"header": {
"wrappedKey": "MF...5g==",
"publicKeyHash": "kd...l4=",
"transactionId": "a5...3e"
}
}

Share articles on linkedin not working with new v2 Api's

We have an app where we are using social media share with Linkedin, earlier the app was using v1 Api and post share was working fine, but now all of the sudden it has stopped working. I checked on google seems like v1 Apis are now deprecated, so I tried using v2 api's. But now I am getting below error-:
Domain=com.alamofire.error.serialization.response Code=-1011 "Request
failed: forbidden (403)" UserInfo={NSLocalizedDescription=Request
failed: forbidden (403)
Below is the code where I am passing access permissions and all other parameters for getting access token.
- (LIALinkedInHttpClient *)client {
UIViewController *top = [UIApplication sharedApplication].keyWindow.rootViewController;
// [top presentViewController:secondView animated:YES completion: nil];
LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:#"https://com.xxxxxx.linkedin.oauth/oauth"
clientId:#"xxxxxxxxx"
clientSecret:#"xxxxxxxx"
state:#"xxxxxxxxx"
grantedAccess:#[#"w_member_social"]];
return [LIALinkedInHttpClient clientForApplication:application presentingViewController:top.presentedViewController]; //[LIALinkedInHttpClient clientForApplication:application];
}
v2 URL - : https://www.linkedin.com/oauth/v2/shared?/accessToken, here accessToken is the valid token value which is appended to the URL, when I check the value in console.
I am not getting how to make a valid request with v2 Api's, or if there are more parameters that we need to pass for new Api's, can anyone help me on this? Thanks in advance.
Kindly let me know if any other information is required.
According to LinkedIn Share API v2.0, your HTTP call should be looked like this:
POST https://api.linkedin.com/v2/shares
json:
{
"content": {
"contentEntities": [
{
"entityLocation": "https://www.example.com/content.html",
"thumbnails": [
{
"resolvedUrl": "https://www.example.com/image.jpg"
}
]
}
],
"title": "Test Share with Content"
},
"distribution": {
"linkedInDistributionTarget": {}
},
"owner": "urn:li:person:324_kGGaLE",
"subject": "Test Share Subject",
"text": {
"text": "Test Share!"
}
}

Square Point of Sales API sending reference_id or userInfoString

I'm using point of sales API to integrate a webapp with Square point of sales for IOS.
according to the API, if I send a reference in my transaction request I'll get that reference back in the response URL and that's what I want to use that reference for further processing in my app.However I'm not getting the reference in the response so I guess something is wrong in my request
this is my request object
var dataParameter = {
amount_money: {
amount:amount * 100,
currency_code: "USD"
},
callback_url: myURL,
reference_id: referenceId,
client_id: applicationId,
version: "1.3",
notes: "this is a test",
options: {
supported_tender_types: ["CREDIT_CARD", "CASH"],
auto_return: true
}
}
I also tried "userInfoString" instead of "reference_id" and it didn't work.

Unsupported grant type error in RingCentral

I am calling the API to refresh my access token on RingCentral but it throws the following error
{
"error":"invalid_request",
"error_description":"Unsupported grant type",
"errors":[
{
"errorCode":"OAU-250",
"message":"Unsupported grant type"
}
]
}
Can anyone help me out?
Check and see if you are posting the grant_type form field and that it's set to refresh_token
I am using the RingCentral API available from RingCentral GitHub
Here is an example of an authentication request:
var request = new Request("/restapi/oauth/token",
new Dictionary<string, string> {
{ "grant_type", "authorization_code" },
{ "redirect_uri", redirectUri },
{ "code", authCode },
{ "refresh_token_ttl", "604800" } });
grant_type=refresh_token is supported by all the platform_type except server/bot platform type. Make sure you haven't created your apps with that platform type.
The parameter for refresh_token is almost same as grant_type password with minor change.
url will be same: https://platform.devtest.ringcentral.com/restapi/oauth/token
Headers:
"Accept":"application/json“
"Content-Type":"application/x-www-form-urlencoded“
"Authorization",:"Basic <ClientID:ClientSecret in base 64>
Body:
In body, we need to pass the parameters in following way :
username=<account phone number>&password=<account password>&extension=<your extension>&grant_type=refresh_token&refresh_token=<the refresh token generated>

example codes needed when using OAuthSwift and identityserver3

I have set up an identity server using identityServer3. Now I am writing an iOS app to authenticate against the identity server. I could not find any example or codes for this setup. The examples I found are all using google, or github etc. My problem is that the call OAuthSwift.authorizeWithCallbackURL just switch the screen to safari and then nothing shows up. I suspect that my setup of callbackurl or url scheme is not correct.
Here is my code snippet
ON server side:
new Client {
ClientId = "implicitclient1",
ClientName = "Example Implicit Client1",
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
Enabled = true,
Flow = Flows.Implicit,
RequireConsent = true,
AllowRememberConsent = true,
RedirectUris =
new List<string> {"oauth-swift://oauth-callback/TestOAuth2"},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email
},
AccessTokenType = AccessTokenType.Jwt
},
on iOS app side:
let oauthswift = OAuth2Swift(
consumerKey: "implicitclient1",
consumerSecret: "secret",
authorizeUrl: "https://example.com/idserver/core/connect/authorize",
accessTokenUrl: "https://example.com/idserver/core/connect/token",
responseType: "token"
)
oauthswift.authorizeWithCallbackURL(NSURL(string: "oauth-swift://oauth-callback/TestOAuth2")!,
scope: "openid",state: "",
success: {
credential, response, parameters in
print(credential.oauth_token)},
failure: {
error in
print(error.localizedDescription)
})
When adding URL types to the ios app, I put in "TestOAuth2".
What did I do wrong?
Thanks a lot.
I got it working.
Turning on the identityserver3 logging was a tremendous help. I changed the flow from implicit to Authorization Code. ( I am not sure why this was needed but that was how I made it work.) I changed the call back string to "myiosappname://oauth-callback". On the ios app, I put "myiosappname" to plist's URL Types scheme.
I double checked that ssl certificate.
Then it started to work. I hope it helps someone down the road.
HZ

Resources