I have a web app that uses a standard paypal shopping cart. What we want to do is to automatically record payments in QB online using Intuit QB API when paypal notifies our web site that the payment has completed.
The examples I have seen for obtaining the access token and secret are user-initiated. How can I get these inside the context of this paypal callback? I need them to happen automatically, and without a Request context from a user. I have some basic test code here that runs within the paypal callback.
//start a transaction
//start try block
//set our transaction record as paid
Token = ConfigurationManager.AppSettings["appToken"];
string consumerKey = ConfigurationManager.AppSettings["consumerKey"];
string consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
string companyID = ConfigurationManager.AppSettings["companyID"];
string accessToken = "??????";
string accessSecret = "?????";
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(appToken, companyID, IntuitServicesType.QBO, oauthValidator);
DataService service = new DataService(context);
Customer customer = new Customer();
//just a test example. without missing tokens, i don't get here.
customer.GivenName = "Mary";
customer.Title = "Ms.";
customer.MiddleName = "Jayne";
customer.FamilyName = "Cooper";
Customer resultCustomer = service.Add(customer) as Customer;
//complete transaction
//catch {rollback transaction}
There is no automated way to get access tokens and secret from your application.
You need to generate them for the first time using user interaction(C2QB- Connect to Quickbooks) and then save them for future use. These tokens are valid for a period of 6 months after which you will have to call Reconnect api to renew the tokens or do a C2QB interaction again to get new tokens.
https://developer.intuit.com/docs/0025_quickbooksapi/0010_getting_started/0030_integrate_your_app/disconnecting_from_quickbooks/0050_how_to_reconnect
Related
In the current website, social login is implemented using the mapping in struts and it will call the custom controller command "XYZThirdPartyLoginCmdImpl" which will authenticate the details passed and it will call the out of the box "LogonCmd" for login.
For creating a REST service for the above functinality, created a custom REST handler " XYZThirdPartyLoginHandler" and from there called the existing command "XYZThirdPartyLoginCmdImpl" using the method executeControllerCommandWithContext. Once the response is generated, WCToken and WCTrustedToken is generated by the below code.
ActivityToken token = getActivityToken();
String identitySignature = token.getSignature();
String identityId = token.getActivityGUID().getGUID().toString();
Map<String, Object> identityTokenInfo = new HashMap();
identityTokenInfo.put(MemberFacadeConstants.EC_USERID, new String[] { userId.toString() } );
identityTokenInfo.put(MemberFacadeConstants.ACTIVITY_TOKEN_ID, new String[] { identityId } );
identityTokenInfo.put(MemberFacadeConstants.ACTIVITY_TOKEN_SIGNATURE, new String[] { identitySignature } );
Map<String, String> commerceTokens = CommerceTokenHelper.generateCommerceTokens(identityTokenInfo);
String wcToken = commerceTokens.get(CommerceTokenHelper.WC_TOKEN);
String wcTrustedToken = commerceTokens.get(CommerceTokenHelper.WC_TRUSTED_TOKEN);
The tokens generated using this is not valid. If we try to invoke any other rest service using this token it shows invalid user session error. "XYZThirdPartyLoginCmdImpl" authentication is success as the userId returned is correct. After executing this the user context is not getting created in CTXMGMT table.
Please guide on how to generate the valid tokens in REST flow in this use case.
If you are on v9, you might want to investigate the oauth_validate REST call (/wcs/resources/store//loginidentity/oauth_validate). See the KC article for more information: [https://www.ibm.com/support/knowledgecenter/SSZLC2_9.0.0/com.ibm.commerce.integration.doc/tasks/tcv_sociallogin.htm][1]. This calls some different commands (OAuthTokenValidationCmdImpl and OpenUserRegisterCmd) than what you might be using, but it allows you to pass in a 3rd party token, and it generates the right tokens.
I have ASP.NET Web application and I am using IdentityServer3 for user authentication. Our customers login to web application using userid/password.
Now I have one more Web API and some of our customers need to call this web api from their applications. (server to server communication). So based on this, in identityserver i did the following
1> Created a new scope name api
2> Created a new client for Web API and configured with allowed scope api and offline_access
3> Set flow to ClientCredentials
4> Set AccessTokenType to Jwt
5> For each customer i created different secret key
Now our customers can get access token at connect/token endpoint and then make call to API using the access token. The API validates the token with IdentityServer, and then returns the result. All good till here.
However, in API project i also need to identify the customer aka caller. Based on customer i need to do some logic
public class ResourcesController : ApiController
{
public IHttpActionResult Get()
{
var caller = User as ClaimsPrincipal;
// need to identify caller here
return Json(new
{
message = "OK",
});
}
}
(One option i can think of is taking customer id is as part of API url. Something like http://api.domain.com/v1/customerid/resources)
Is there anyway to make a use of IdentityServer to identify customer?
I've actually had a similar need some time ago. For the simplest solution, you should be able to assign a custom claim to each of the Identity Server client that you have created for your customers.
AlwaysSendClientClaims = true,
Claims = new List<Claim>()
{
new Claim("CustomerId", "0121021")
}
These client claims will then be included in the access token and therefore available to you in your backend.
public class ResourcesController : ApiController
{
public IHttpActionResult Get()
{
var caller = User as ClaimsPrincipal;
// need to identify caller here
var customerId = caller?.Claims.Where(p => p.Type.Equals("CustomerId")).First().Value;
// need to identify caller here
return Json(new
{
message = "OK",
});
}
}
I'm trying to get access token for Power BI API. Our account is a federated account.
I've been trying this but it keeps giving me an error saying Incorrect username or password. To use the resource owner password credentials grant flow to get the access token for Azure AD, I make a call to http request diectly using the HttpClient
HttpClient clie = new HttpClient();
string tokenEndpoint = "https://login.microsoftonline.com/{tenant}/oauth2/token";
var body = "resource=https://analysis.windows.net/powerbi/api&client_id={client_id}&grant_type=password&username={username}&password={password}";
var stringContent = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded");
string result = clie.PostAsync(tokenEndpoint, stringContent).ContinueWith((response) =>
{
return response.Result.Content.ReadAsStringAsync().Result;
}).Result;
This will work for non federated accounts. How can I implement the same for federated accounts?
The easier would be to leverage MSAL.NET (or ADAL.NET) which does a lot to achieve that. See https://aka.ms/msal-net-up
scopes = new string[]{ "https://analysis.windows.net/powerbi/api/Dashboard.Read.All"}
result = await app.AcquireTokenByUsernamePasswordAsync(scopes, "joe#contoso.com",
securePassword);
Even better if you know that your machine is domain joined or AAD joined, you can use Integrated Windows Authentication: https://aka.ms/msal-net-iwa
result = await app.AcquireTokenByIntegratedWindowsAuthAsync(scopes);
Note that, I recommend using MSAL.NET (instead of ADAM.NET), because with MSAL/NET/the Azure AD v2.0 endpoint, PowerBI offers a better control of the permission scopes:
See the API permissions tab in an app registration in https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview
So this is what i did so far and it doesn't work, i will appreciate any help on the matter:
my goal is to post back any webhook event that occur in my paypal sandbox account.
So i have 2 accounts,
one that belongs to the receiver of the money, call it "facilitator",
one that belong to the "buyer",
Now in my account,there is a Sandbox webhooks configuration, so i entered the following:
https://csdieuqkzo.localtunnel.me
goes without saying that this comes from localtunnel.me.
So in my project, i do a simple sale using the api... this is the full create sale process:
$payer = new Payer();
$payer->setPayment_method('paypal');
//dd($payer);
$item = new Item();
$item->setQuantity('1');
$item->setName('benny');
$item->setPrice('7.41');
$item->setCurrency('USD');
$item->setSku('blah');
// //var_dump($item);
$items = new ItemList();
$items->addItem($item);
//var_dump($items);
$amountDetails = new Details();
$amountDetails->setSubtotal('7.41');
$amountDetails->setTax('0.03');
$amountDetails->setShipping('0.03');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$amount->setDetails($amountDetails);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$transaction->setItemList($items);
// echo '<pre>';
// print_r($transaction);
$RedirectUrls = new RedirectUrls();
$RedirectUrls ->setReturnUrl('https://csdieuqkzo.localtunnel.me/#/pricing');
$RedirectUrls ->setCancelUrl('https://csdieuqkzo.localtunnel.me/#/');
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->setRedirectUrls($RedirectUrls);
// echo '<pre>';
// print_r($payment);
// dd();
$response = $payment->create($this->apiContext)->toarray();
Session::put('pay_id',$response['id']);
return Response::json($response);
After this there is a redirect to paypal, approval and when it comes back to my site, it excute with the following:
$payerId = Input::get('payerId');
$payment = Payment::get(Session::get('pay_id'), $this->apiContext);
//return $payerId;
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayer_id($payerId);
$approval = $payment->execute($paymentExecution, $this->apiContext)->toarray();
return Response::json($approval);
Then an object is coming in saying the state of this transaction is approved, super, but i don't see any post to the webhook url i defined earlier...Now how did i test it?
I wrote a simple script to the post method of my root (in laravel):
Route::post('/',function(){
$myfile = fopen("bennyfile.txt", "a") or die("Unable to open file!");
$txt = "\nouterequested";
fwrite($myfile, $txt);
fclose($myfile);
});
Means whenever a post request is coming to the following url (in my case, a post to the root of:https://csdieuqkzo.localtunnel.me
I just want to add a line, that's it...but it doesn't update anything!...
for example if i do a post request from postman to the same place, all is good, but when a sale is approved, or any other action, nothing is happening.
Why?
This is a paypal document which helps you understand how webhooks works.
https://developer.paypal.com/docs/integration/direct/rest-webhooks-overview/
webhooks is http call back mechanism, ideally, you will need a valid url as your webhooks endpoint to test the webhooks notification message posted by PayPal. If you did sale using paypal wallet, you should get PayPal's webhooks notification message in JSON format at your endpoint. webhooks doesn't support direct credit card case yet.
If you want to test your listener script on local, you can use postman tool to post the sample message to your local url and test.
Using "localhost" isn't going to work because when PayPal's servers hits that address they're just hitting themselves. You need to setup DNS to point a domain to a virtual server on your local machine instead so that you can use a fully qualified domain name instead of localhost.
I'm using PayPal SOAP SDK for .NET to make a refund transaction.I try to call RefundTransaction method in SDK using transaction ID from SetExpressCheckout/DoExpressCheckout calls ( they work well ). PayPal API is returning 10004 error "Transaction id is not valid".
Here is my code:
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
RefundTransactionRequestType refundTransactionRequest = new RefundTransactionRequestType();
refundTransactionRequest.TransactionID = transactionID;
refundTransactionRequest.PayerID = payerID;
refundTransactionRequest.InvoiceID = invoiceNumber;
refundTransactionRequest.RefundType = RefundType.FULL;
refundTransactionRequest.Amount = new BasicAmountType(GetPayPalCurrency(currencyID), amount.ToString("F"));
var request = new RefundTransactionReq() { RefundTransactionRequest = refundTransactionRequest };
RefundTransactionResponseType refundTransactionResponse = service.RefundTransaction(request);
Please help.
Double check to make sure that you processed the DoExpressCheckout transaction as a sale and not an authorization. If it was an authorization, you will not be able to refund it. Also make sure you are using the transaction id that you received as the merchant, and not the transaction id you received as a buyer. The two transaction id's will be different. If you have checked both of these things and it still does not work, if you can provide the API response you are getting back that includes the TIMESTAMP and the CORRELATIONID I can take a look at it on my end.