I'm retrieving a connected account thanks to Stripe PHP library, updating a few information and trying to save it. But, it throws this error message:
This account can only be updated with an account token, because it was
originally created with an account token. (Attempted to update param
'legal_entity' directly.)
Here is my code:
\Stripe\Stripe::setApiKey('sk_MYSTRIPESECRETKEY');
$account = \Stripe\Account::retrieve(ACCOUNT_ID);
$account['legal_entity'] = array('dob' => array('day' => 01,'month' => 01,'year' => 1970));
$account->save();
What am I doing wrong ?
The solution was: creating a token and filling it with the legal entity fields I needed.
Related
I'm trying to implement below doc , where in my website there will be a stripe connect button after click on button if user login then user will connect and I will save user stripe session id.
https://stripe.com/docs/building-extensions
But this doc is deprecated.
In stripe docs not getting any clue how I will do the same thing. I have tried by
$stripeAccountLink = $this->StripeClient->accountLinks->create([
'account' => 'acct_1MQqv1SHt2ASWOGp',
'refresh_url' => url("/profile-edit"),
'return_url' => url("/profile-edit"),
'type' => 'account_onboarding',
]);
So here after redirect user always user need to create a new account. Why it's not just connect and redirect me if user already log in and am I in right way ?
docs : https://stripe.com/docs/connect/standard-accounts
With help from #CarlZhao I am finally getting a good understanding of the difference between OAuth and Graph. I am building the capability in my app for users to post messages to a team channel. So far I can list teams, channels, and delete channels. I am having a hard time trying to send a chatMessage. I understand that because sending a chatMessage is a delegated permission and not an application permission so from my understanding I have to use the accessToken created from OAuth when the user authenticated with my app.
What I am doing is saving that token in my database so I can call it when I am trying to send a chatMessage. Not sure if that is correct. So in my code, I am creating a new Graph instance, but I am using the access token of the user and not the token of the graph.
$useraccesstoken = "************************************";
// create a new OAuth graph from useraccesstoken
$graph_message = new Graph();
$graph_message->setAccessToken($useraccesstoken);
// post message
$data = [
'body' => [
'content' => 'This is a message from the API I made it works'
],
];
$message = $graph_message->createRequest("POST", "/teams/$group_id/channels/$channel_id/messages")
->addHeaders(array("Content-Type" => "application/json"))
->attachBody($data)
->setReturnType(Model\User::class)
->execute();
This is producing no errors, but nothing happens and the chatMessage is not posted. I have double-checked and my $group_id and $channel_id are correct.
Am I using the $useraccesstoken correctly? can I start a new Graph() instance with the $useraccesstoken?
Yes, you could start a new Graph() instance with the $useraccesstoken.
The graph API of sending messages doesn't return User::class. Try your code with
->setReturnType(Model\ChatMessage::class)
The access token is invalid for one hour by default, see here. You could not use it all the time, so it seems you don't need to store in the database. It's better to refresh token before the access token expires, and this step shows you how to refresh token.
The default is 1 hour - after 1 hour, the client must use the refresh
token to (usually silently) acquire a new refresh token and access
token.
I have the Xero API setup and the OAuth flow working. I have linked up the "Demo Company UK" as the tenant (Organisation) and have granted my user with Adviser • Contact bank account admin, Payroll admin • Expenses (Admin) permissions (which appears to be the highest level) located here: https://go.xero.com/Settings/Users but I still get the following error. "You are not permitted to access this resource" I have added all the scopes that should cover the requests and have a valid access token but still no good.
'client_id' => env('XERO_CLIENT_ID'),
'client_secret' => env('XERO_CLIENT_SECRET'),
'redirect_uri' => env('XERO_REDIRECT_URI'),
'scope' => 'openid email profile offline_access accounting.transactions accounting.contacts accounting.contacts.read accounting.reports.read',
Example function making a basic call to get the users within the account. The connection to Xero is fine but as soon as I try to request any data the same error is thrown.
public function testXero() {
$xeroAccessToken = GlobalSetting::where('name', '=', 'xero_access_token')->first();
$xeroTenantOrganisation = GlobalSetting::where('name', '=', 'xero_tenant_organisation_id')->first();
$xero = new XeroApp(
new AccessToken(
array(
'access_token' => json_decode($xeroAccessToken->value)->id_token
)
), $xeroTenantOrganisation->value
);
//dd( $xero ); //we have a succesfull connection here...
# Retrieve all contacts
$contacts = $xero->contacts()->get();
dd($contacts); //error "You are not permitted to access this resource".
}
Has anybody encountered this issue?
The issue is that I was passing id_token when making a new XeroApp class instance. I failed to see all the other objects in the JSON object stored in the Database (very large). There is an actual access_token that is stored along with some other useful bits of information that I make within my call.
$xero = new XeroApp(
new AccessToken(
array(
'access_token' => json_decode($xeroAccessToken->value)->access_token,
'refresh_token' => json_decode($xeroAccessToken->value)->refresh_token,
'expires' => json_decode($xeroAccessToken->value)->expires,
)
), $xeroTenantOrganisation->value
);
$contacts = $xero->contacts;
dd($contacts);//RESULTS!!! YES
I will keep this thread open just in case it helps anyone out.
Nice save Nick - yes the id_token can be used for things like "Sign up with Xero" which can be a huge advantage if your business operations is core to financial data.
https://developer.xero.com/documentation/oauth2/sign-up
It essentially enables you to provision accounts in your system (using the decoded ID token name / email) and sync their Xero data in a single flow. We've see partners significantly reduce drop off for new signups because of it.
All that said, a valid access_token and the tenant_id are the things you need to make authorized API calls.
I had same problem and I recognized that I had wrong tenant id.
You have to be sure about all credentials.
Am having some issues getting AWS SES working per below; I want to send an email to users from my website. Looks like the credentials are not being validated, however I have used the correct credentials generated from an IAM (I also tried the server root keys and it gave me the same error). I have run out of ideas of how to resolved/ debug any further so any steer would be greatly appreciated.
Error Received on Execution:
Error retrieving credentials from the instance profile metadata server. (Client error: 404)
Steps Taken
I have setup SES and validated the email addresses etc
I have created a IAM profile with 'Full access to SES'
I have installed the AWS SDK for php using the phar file
I have written the php code below providing the correct security access code directly of the SES
require 'aws/aws.phar';
use Aws\Ses\SesClient;
//More code here
$client = SesClient::factory(array(
'key' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxx',
'region' => 'us-west-2',
'version' => '2010-12-01'
));
//code to build the $msg here as array
try{
$result = $client->sendEmail($msg);
//save the MessageId which can be used to track the request
$msg_id = $result->get('MessageId');
echo("MessageId: $msg_id");
//view sample output
print_r($result);
} catch (Exception $e) {
echo($e->getMessage());
}
//view the original message passed to the SDK
print_r($msg);
Thank you for your help in advance - this is always a great community!! Please let me know if i can provide anything else
John
You can provide credentials to your SDK using multiple methods. See the documentation: Providing Credentials to SDK
1) Set the environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION with the values from the IAM profile you created.
2) Instead of 1), you can also create ~/.aws/credentials file. Here you can add the lines: [default]
aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
aws_default_region = the region
1) or 2) will definitely work and it is straight forward.
3) You can also create instance profile. You need to create IAM role and instance profile. Your instance needs to have instance profile assigned when it is being created. See page 183 (as indicated on bottom of page. The topic name is "Using an IAM Role to Grant Permissions to Applications
Running on Amazon EC2 Instances") of this guide: AWS IAM User Guide to understand the steps and procedure. Here, the secret key and access key are automatically picked up and you don't have to do anything. You just need to set default region using step 1) (i.e, export AWS_DEFAULT_REGION=someregion).
4) You have already tried the 4th method and may be there is some issue in your settings which I am not aware of.
I want my website to automatically post status updates to a particular twitter account using OAuth in PHP.
I test this using a URL
www.mysite.com/update_status
but it asks me for "user name" and "password", which is fine when I am testing it. But my website will not be able to insert this user name and password before posting the status update.
So the question is how can a website which is in the server, automatically post a status update to an account without user filling out the user name and password.
Is there any way to bypass this? I tried saving oAuth tokens, but it's not working.
Thank you for your answer in advance!
My recommendation:
1) Use a PHP library like http://github.com/abraham/twitteroauth.
2) Select your app on http://dev.twitter.com/apps and click on "My Access Token".
3) Us that access token as described on http://dev.twitter.com/pages/oauth_single_token.
Just tried this and it WORKS! And its SO SIMPLE to use!!
http://ditio.net/2010/06/07/twitter-php-oauth-update-status/
Got it working in under 5mins.
xAuth is able to do that, but Twitter only allows it for desktop and mobile apps.
In case you wanna try it, read this article and the API docs.
Try it with zend framework. As of version 1.10.8 minimal code required to post on Twitter is:
$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
'oauth_token' => 'REPLACE_WITH_TOKEN',
'oauth_token_secret' => 'REPLACE_WITH_TOKEN_SECRET'
));
$twitter = new Zend_Service_Twitter(array(
'consumerSecret' => 'REPLACE_WITH_CONSUMER_SECRET',
'accessToken' => $token
));
$response = $twitter->status->update('REPLACE WITH MESSAGE');
All tokens and secrets can be accessed after registering your application on http://dev.twitter.com