Paypal API get authorisation code from code
I've implemented a Paypal Connect button. This returns a code
parameter in the query string.
I'm unsure as to how to then turn this into an access code. The following code returns a (400) Bad Request
error on the CreateFromAuthorizationCode()
line:
var config = ConfigManager.Instance.GetProperties();
var oAuthCredential = new OAuthTokenCredential(
Code.Settings.AssetStore.AssetStorePaypalAccountClientID,
Code.Settings.AssetStore.AssetStorePaypalAccountSecret,
config);
var accessToken = oAuthCredential.GetAccessToken();
var apiContext = new APIContext(accessToken);
var n = new CreateFromAuthorizationCodeParameters();
n.SetCode(paypalLoginCode);
n.setClientId(Code.Settings.AssetStore.AssetStorePaypalAccountClientID);
n.setClientSecret(Code.Settings.AssetStore.AssetStorePaypalAccountSecret);
n.SetGrantType("authorization_code");
n.SetRedirectUri("https://www.constructdev.net/en/game-assets/seller-account/cashout/create");
var info = Tokeninfo.CreateFromAuthorizationCode(apiContext, n);
Response.Write(info.access_token);
Response.End();
The Paypal API's seem a bit of a mess, any help on how to get the code at this point would be much appreciated.
See also questions close to this topic
-
Huge amount of logon attempts when loading a page (without cache)
I notice in the Performance Monitor of Windows Server 2012 that there are spikes in logon attempts per second under Web Service -> Logon Attempts/sec. These spikes go from about 0 to 50.
I've traced this down to a page refresh. Loading a page with no cache that is. An average page load does about 50 requests (images, scripts, etc). Now apparently these 50 requests are shown as logon attempts.
Is this normal?
Note that this page does not require the visitor to be logged in.
-
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3\
When warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {e43b756a-2818-4898-8730-5e8e0f230be7} may be persisted to storage in unencrypted form.
info: IdentityServer4.Startup[0]
Starting IdentityServer4 version 4.1.1+cebd52f5bc61bdefc262fd20739d4d087c6f961f
info: IdentityServer4.Startup[0]
You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.
info: IdentityServer4.Startup[0]
Using the default authentication scheme Identity.Application for IdentityServer
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://[::]:8081
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
info: IdentityServer4.Hosting.IdentityServerMiddleware[0]
Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token
info: IdentityServer4.AspNetIdentity.ResourceOwnerPasswordValidator[0]
Credentials validated for username: muthu
info: IdentityServer4.Validation.TokenRequestValidator[0]
Token request validation success, {
"ClientId": "sdgfsdsgsdg",
"ClientName": "Swagger UI",
"GrantType": "password",
"Scopes": "api",
"AuthorizationCode": "********",
"RefreshToken": "********",
"UserName": "sample",
"Raw": {
"grant_type": "password",
"username": "sample",
"password": "REDACTED"
}
}
fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
Exception occurred while processing message.
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'http://*:8080/.well-known/openid-configuration'.
---> System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
fail: IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler[0]
IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'http://*:8080/.well-known/openid-configuration'.
---> System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync()
info: IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler[7]
Bearer was not authenticated. Failure message: IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
info: IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler[12]
AuthenticationScheme: Bearer was challenged.
-
ASP.NET using return RedirectToAction(" ", " ") how to use this to redirect to a cshtml
I can not find a useable tutorial that explains how to redirect using REdirectToAction. can someone share a link that that explains ALL the steps needed to use this? I think I am having a hard time understanding how the parameters are given can find an HTML file with a model in the parameter? or is it a controller? I am very lost on how they communicate. please someone if you can help.
-
Paypal CANCEL URL set to wrong URL
We use a Paypal payment gateway software from a document solution company running on our Windows 2016 server At the Paypal checkout stage, the cancel URL displayed is set to https://ServerInternalIPAddress. This URL is useless because external customers can't reach that address. In my Paypal account's web payment settings, the cancel URL is set to the correct external URL but Paypal says the source code of the checkout code is picking the internal IP. This is apparently overriding the Paypal web payment settings. I spoke to the developer and they said the internal IP is hardcoded. Which I don't agree with because the IP is specific to our server. So surely the the gateway software is picking it up from somewhere. I've look in the registry, config files, uninstalled, reinstalled. No success
Does anyone know of anyway I can force the software/server/gateway/firewall to recognize a different cancel URL instead of https://ServerInternalIPAddress
-
Does Python Kivy have some sort of deeplinking feature?
I'm working on an app currently with Kivy on Python and was wondering if it was possible to create deeplinks with it? For example I have the PayPal API on my app that lets users pay through PayPal but need to find a way to create a deeplink back into my app after customer approval on the PayPal webpage. I've been trying to look up for possible documentaion or examples but came out empty so far. Any help would be appreciated!
.py
def PayPal(self): client_id = "ID" client_secret = "SECRET" environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret) client = PayPalHttpClient(environment) request = OrdersCreateRequest() request.prefer("return=representation") request.request_body({ "application_context": { "return_url": ""}, "intent": "CAPTURE", "purchase_units": [ { "amount": { "currency_code": "CAD", "value": str(App.get_running_app().cart) } } ] }) try: response = client.execute(request) print("Order With Complete Payload:") print("Status Code:", response.status_code) print("Status:", response.result.status) print("Order ID:", response.result.id) print("Intent:", response.result.intent) print("Links:") for link in response.result.links: print('\t{}: {}\tCall Type: {}'.format(link.rel, link.href, link.method)) print("Total Amount: {} {}".format(response.result.purchase_units[0].amount.currency_code, response.result.purchase_units[0].amount.value)) order = response.result print(order) except IOError as ioe: print(ioe) if isinstance(ioe, HttpError): print(ioe.status_code) webbrowser.open_new_tab("https://www.sandbox.paypal.com/checkoutnow?token=" + response.result.id)
-
Paypal Payment : IPN Url is not being called if user is logged in while doing a payment
Hello i have project in WordPress and core php
where paypal payment has been integrated the code is quite old
So when i do the payment from the paypal using guest payment process by using just card information it works well it calls the IPN correctly
But when i do the payment using Logging in to the paypal account It never calls a IPN and transaction is not being tracked
I am not getting it the behavior i have checked everything on code side but unable to resolve this Can please guide where i am doing a mistake
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="PayPalForm"> <input type="hidden" name="business" value="xxx@xxx.com"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="item_name" value="$<?php echo $topupValue ?>"> <input type="hidden" name="amount" value="<?php echo $transactionValue ?>"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_number" value="<?php echo $productCode ?>"> <input type="hidden" name="custom" value="<?php echo $transactionID ?>"> <input type="hidden" name="quantity" value="<?php echo $topupQuantity ?>"> <input type="hidden" name="notify_url" value="https://IPN_TO_CAPTURE_PAYMENT"> <input type='hidden' name='rm' value='2'> <input type='hidden' name='return' value='https://RETURN_SUCCESS_URL'> <input type='hidden' name='return_cancel' value='https://RETURN_CANCEL_URL'> </form>
Guest Payment : It works well with after successfully payment it shows the transaction details page and it ask for return to merchant site.
Paypal Account Login Payment : It doesn't show the transaction details page it just redirect on success page mentioned in request after successful transaction and IPN Url is not being called so capturing of payment is not working.
-
I have a problem with a paypal sandbox test buy
I am doing e-commerce on shopify.And I finished mine website.And trying add payment methods.Finally I intergrated Paypal express check-out on shopify.
And I wanna test paypal its working correctly. And I create sandbox account.I can login smoothly www.sandbox.paypal.com but when I am trying test buy on my website paypal login says "Check your email adress and password and try again" but I am sure with mail adress and password are corrects.
-
Connect With PayPal : Get status 400 (Bad Request)
I am facing 400 bad request response from PayPal during getting access token based on access code. I go through below reference link https://developer.paypal.com/docs/connect-with-paypal/integrate/#1-create-the-app
I follow 5 steps perfectly but getting the issue with step no. 6. See my code below:
Request Part:
$curl = curl_init(); $base_token = "{client_id:secret}"; $data = array( CURLOPT_URL => "https://api.sandbox.paypal.com/v1/oauth2/token", CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array( 'grant_type' => 'authorization_code', 'code' => '{authorization_code}' ), CURLOPT_HTTPHEADER => array( "Authorization: Basic ".$base_token, ), ); curl_setopt_array($curl,$data ); $response = curl_exec($curl); curl_close($curl);
Response Part:
stdClass Object ( [name] => Bad Request [debug_id] => 5837077aa8787 [message] => java.lang.IllegalArgumentException [details] => Array ( ) )