Getting checkout session from a connected account paymentlink - php

I am using php and have stripe main account, with some connected accounts.
On those accounts I created payment links and I could add a redirect link (after completing payment), in which I added the placeholder for the session_id (automatically added).
The success page I created should get the checkout session, but somehow I am unable to get it from the connected accounts.
I can’t find in the stripe docs how to do that, only from the main account (session_id)
Does anybody know howto and have some good docs?
I got an error:
The resource ID cannot be null or whitespace
This is code I use:
$stripe = new \Stripe\StripeClient('sk_live_......');
$acc = $stripe->accounts->retrieve('acct_.....', []); // This shows some data of that connected account.
$session = $stripe->checkout->sessions->retrieve($_GET['session_id'], [], ['stripe_account' => 'acct_....']);
the session_id in the url is correct (as I see it on the dashboard of stripe), but as I do not get any data from the connected account regarding any payments, its hard to find it.
I am pretty new with this, so any guidence would help.
Extra update
I changed the following line and got also info of the session (id, amount, email who paid, etc):
$session = $stripe->checkout->sessions->retrieve($_GET['session_id'],['expand' => ['payment_intent']], ['stripe_account' => 'acct_.....']);
The only error I am getting is:
Fatal error: Uncaught Stripe\Exception\InvalidArgumentException: The resource ID cannot be null or whitespace
No idea why I still get that error or what I miss.

I seem to have fix it, using the following line:
$session = $stripe->checkout->sessions->retrieve($_GET['session_id'],['expand' => ['payment_intent']], ['stripe_account' => $account_id]);
The $account_id changes depending on the account.
But adding the expand part made it show the session_id from the connected stripe_account.

It's hard to say for sure without more details, but it sounds like you're trying to access objects on the connected account from your platform account. If I'm right, you're likely seeing errors about those objects not existing. If that's what's happening you need to make a Connect request to fetch the objects from your connected account.
If that's not what's happening please edit your question and add more detail, including the specific code and error messages you're seeing.

Related

Facebook Marketing API: Tried accessing nonexisting field (X) on node type (Page)

Ultimately, I am trying to create a Web (laravel) app that allows me to edit / monitor / manage various Facebook Ad accounts. I have tried a few different things to get the token but haven't had any luck. From what I can tell it seems that I have a token that only has permission to "Pages". (A Pages token?)
I tried following these instructions here, although a little outdated. I have a development account and I understand that I can't submit it until it meets a certain criteria.
I am not sure if the development account is why I can't create a system user account. I have tried creating a System User but the page just endlessly loads. As you can see below.
I was thinking that maybe it could be something with the way I set up my Advertising Accounts but they look correct.
So basically I have no ideas on why I keep getting these errors. Additionally here is an example of a token I generated with all the allowed permissions:
And finally my code:
use FacebookAds\Api;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;
public function createFBAd( Request $request )
{
// Initialize a new Session and instanciate an Api object
$api = Api::init(env('FB_APP_ID'), env('FB_APP_SECRET'), env('FB_ACCESS_TOKEN'));
$account = (new AdAccount($act_id))->read(array(
AdAccountFields::ID,
AdAccountFields::NAME,
AdAccountFields::ADLABELS, //Throws error
AdAccountFields::AMOUNT_SPENT, //Throws error
AdAccountFields::SPEND_CAP, //Throws error
AdAccountFields::MIN_DAILY_BUDGET, //Throws error
));
}
If I remove the fields:
AdAccountFields::ADLABELS, //Throws error
AdAccountFields::AMOUNT_SPENT, //Throws error
AdAccountFields::SPEND_CAP, //Throws error
AdAccountFields::MIN_DAILY_BUDGET, //Throws error
I get a return of Id and Name.
I am developing using laravel, on a local machine, installed the Facebook Marketing API SDK through composer, and the facebook app is set to development mode in the facebook developers account.
Any help with this would be appreciated!
The issue turned out to be as I suspected, the Systems Users tab not loading. I tried contacting Facebook and reaching out through their community help but I was unable to get a response. Ultimately, I ended up submitting the app, requesting for ads_management permissions, and then checking the System Users tab. To my surprise, the System Users tab then loaded. I don't know if the app will be approved (since I haven't built it). I am just beginning the development phase, but a "fake" submit seems to be what did the trick. This could be a total coincidence but that was my solution.

Podio authentication fails after multiple calls

I've been working with the Podio API for nearly a year now and have rarely had issues, but I recently ran into one that I can't figure out. I'm not even sure how to test what is going on. When an item is created, I have a webhook to a script which will send an http GET request to an item and perform a number of functions. The script runs just fine and has never run into any issues, unless I create a number of items in quick succession (15 or so). If I do this, a certain number will finish successfully, and then I will suddenly get the following error with each new call:
2016-11-14 16:41:14 401 GET /item/514610204
2016-11-14 16:41:14 Reponse: {"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http:\/\/api.podio.com\/item\/514610204","query_string":"","method":"GET "},"error_description":"invalid_request","error":"unauthorized"}
If I wait a minute or so, it begins working again.
I'm authenticating with username and password. Does anyone know what is going on or how to check what is going on? The podio.log has not been helpful in this situation.
(UPDATE)
The issue is that I am hitting an authentication request rate limit because I haven't been using a session manager. I'm now attempting to do this, but having issues. My code using the Redis setup is as follows:
require_once 'models/PodioRedisSession.php';
Podio::set_debug(true, 'file');
Podio::setup($client_id, $client_secret,array(
"session_manager" => "PodioRedisSession"
));
Podio::$auth_type = array(
"type" => "password",
"identifier" => "MY_EMAIL"
);
Podio::$oauth = self::$session_manager->get(Podio::$auth_type); //ERROR IS ON THIS LINE
if (!Podio::is_authenticated()) {
Podio::authenticate_with_password('MY_EMAIL', 'MY_PASSWORD');
}
which gives me the following error: Cannot access self:: when no class scope is active.
Am I on the right track to get the session manager working with password authentication? The error occurs on the commented line.
(UPDATE)
I was finally able to get the system running properly. The code above is correct. The server just needed to be reset (Windows server) for Redis to take affect.
If your script is authenticating to Podio each time an item is created, it is possible that you are running into the Podio API’s rate limit on authentication requests.
Are you generating a new auth token each time the script is triggered by your webhook? The Podio client libraries include some general documentation on session management that may be useful!
To avoid hitting this limit you should authenticate with the API once and then store the oauth and refresh tokens that at are returned from the API. Redis will do the trick. Then you use the oauth token for all subsequent requests.
An example can be found here [1]
Your oauth token will be valid for at most 28 days. When it's no longer valid you will need to obtain a new oauth token using the refresh token you received when you first authenticated. [2]
[1] https://developers.podio.com/authentication/username_password
[2] https://developers.podio.com/authentication

Cannot update user information using Google PHP API Client library

I am trying to update user phone numbers on Google Apps Directory. Currently I have the API able to retrieve information on user's but when I try to set their phone numbers it just silently fails. The values do not update in the directory. It is possible I may be just missing a method that actually sends the data but I have been unable to find such a method.
My current scopes are:
$scopes = array('https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.orgunit');
My attempts at saving phone numbers have been varied. I have tried:
$work_phone = new \Google_Service_Directory_UserPhone();
$work_phone->setType('work');
$work_phone->setValue($work_number);
$google_user->setPhones(array($work_phone));
And
$google_user->setPhones(array(array(
"type"=>"work",
"value"=>$work_number
)));
As well as a variety of values for the type array structures. Any help would be greatly appreciated.
In order to update the phone number in the directory, you need to send the information back to Google. With your code:
$google_user->setPhones(array($work_phone));
You are setting the object's phones array correctly. You still need to update that user however. You were correct when you said:
I may be just missing a method that actually sends the data
You would need to do something like this:
$work_phone = new \Google_Service_Directory_UserPhone();
$work_phone->setType('work');
$work_phone->setValue($work_number);
$google_user->setPhones(array($work_phone));
$serviceDirectory = new Google_Service_Directory($client);
$serviceDirectory->users->update($google_user);
Relevent API documentation can be found here: https://developers.google.com/admin-sdk/directory/v1/reference/users/update

need help implementing facebook credits

I've read a few of the other posts on getting started with implementing Facebook credits and I've downloaded the sample code from github: https://github.com/facebook/credits-api-sample.
The only changes I had made to the sample code are:
In index.php, I set the app ID.
In callback.php, I set the app secret.
I've uploaded all these files to my server:
index.php
callback.php
facebook.php
facebookapi_php5_restlib.php
xd_receiver.html
assets folder
On the Facebook app edit page:
The canvas url points to index.php.
The credits callback field points to the callback.php file on my
server.
Added myself as a credits tester.
I have not registered my company. Is that required for testing?
I do not have a secure canvas url. Is that required? The app is in sandbox mode.
When I run the test app, I see the index page. When I click on the "Pay with Facebook" button, this error pops up:
There was a problem processing your payment. Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
When I close the dialog, there is a message:
Transaction failed!
Error message returned from Facebook:
The entity (class EntApplication) backed by id cannot be seen by the
current viewer 0 (EntID: )
Can someone please tell me what I am doing wrong?
I found out what the problems were:
In order to get this to work, you need to have the company registration filled out.
After that is done (and this was not obvious), you need to actually select the company from the drop down list. This is all done in the credits section.
You must have a secure canvas url set in the basic settings section (i.e. https://example.com/app/index.html)
I'm not sure if you have to have the callback as a secure url in order for the test to work, but it does make sense that this would be required.
The test will not work in sandbox mode.
Hopefully this will help others that may run into similar problems.
Now I have to figure out how to get this to work using the facebook-actionscript sdk.

Redirecting to authentication dialog - "An error occurred. Please try again later"

Why does it always happen to me?
This happens after my application verify for user user login and redirect user to the authentication page:
https://www.facebook.com/dialog/oauth?client_id=XXX&redirect_uri=http%3A%2F%2Fexample.com%2Fmyappname%2F&state=YYYYYY&scope=offline_access%2Cpublish_actions
But instead of showing the authorization page, Facebook shows an error page with
An error occurred. Please try again later.
Is there any configuration I have to do before try to authenticate my users?
All is done with PHP using the PHP-SDK classes.
I have had the same problem as you.
From the Facebook Developers Apps page, make sure that the Sandbox Mode is disabled.
I had the same problem after changing the domain of my site. Altough I properly changed the request_uri parameter and updated my app settings with the new domain, the error kept showing up.
Then I realized that the ID and the SECRET ID of my Facebook APP had automatically changed with no warning!! The whole thing started working again using the new ID.
This was happening to me also but all the api keys, secrets and stuff were correct. What I found is that my app was running in sandbox mode. Go to your app settings in https://developers.facebook.com/ click the advanced settings tab and check to see if your app is in sandbox mode. If it is disable it and try again. Let us know if it works.
I was getting this error because I was starting from http://mysite.com, but had specified http://WWW.mysite.com in my Facebook settings - the www mattered... I ended up solving by using .httpaccess to always kill the "www", and pointing FB to http://mysite.com
worst. subdomain. ever. :u)
When working with Dialogues, Facebook provide a 'show_error' attribute that defaults to no but can be set to true in a Development environment and is really helpful for debugging purposes.
show_error - If this is set to true, the error code and error description will be displayed in the event of an error.
Instructions of it's use can be found in the Facebook Docs.
I'd been debugging "An Error occurred. Please try later." dialogue before i found this attribute in the docs. Once i started using it, i could see the following message too:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
I had the same problem; it turned out FB requires a string appID and not an int...
//DOESNT WORK:
$facebook = new Facebook(array(
'appId' => 147XXXXXXXXXXX,
'secret' => 'XXXXXXXXXXXXXX',
));
// WORKS:
$facebook = new Facebook(array(
'appId' => '147XXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXX',
));
For me this happened because the "test user" I created was part of a separate app. I created a test user for THIS app, and it started working fine.
Stupid on my part I know, but this could save someone else some trouble.
Make sure your app is configured to use the appropriate URL & domain of your site. That may be it.
According to OAUTH Dialog documentation:
*redirect_uri: The URL to redirect to after the user clicks a button in the dialog. The URL you specify must be a URL of with the same Base Domain as specified in your app's settings, a Canvas URL of the form https://apps.facebook.com/YOUR_APP_NAMESPACE ...*
I am constructing oauth links dynamically to ask a user for additional permissions if needed and I realized, that even if you are redirecting to https://apps.facebook.com/YOUR_APP_NAMESPACE you have to have the App Domain and Website settings set in your application administration. I set domain to facebook.com and Website to facebooks root url.
Now my oauth dialog link works fine - even in sandbox mode.
I had this exact problem on a Page Tab app and for the life of me couldn't work out what the problem was. It worked on my test page but as soon as I made it live it wouldn't work. I found in the end that I fixed the problem by putting the actual URL to the Page Tab (i.e. http://www.facebook.com/<"page_name">/app_<"app_id">) into "Site URL" under "Website". This doesn't make any sense. But it worked :-)
Solution for me is to set option 'Authenticated Referrals' to enabled. Its realy fixed after that.
The issue resolved after I updated the 'appID' and 'secret' and then pushed the change back to heroku (i.e. - 'git push heroku master')
The key is not to forget to push the changes back to heroku master. Very easy to overlook if you're use to testing on localhost.
Hope this helps.
For me the problem was that the Facebook users I was using to test the app did not have its email address confirmed by Facebook.
My client had set up 2 fake accounts on Facebook and told me that they were not working. But he forgot to confirm the email addresses of those accounts (the emails Facebook sent went to his spam folder and he didn't notice).
Took me hours to find this, so I hope it helps somebody.
Cheers!
Also had a problem with wrong redirect link: I had a link starting with "https://apps.facebook.com?myapplication".... but after authorization the redirection would bring me to "apps.facebook.com/Myapplication" and consequently I would get a message described above:"Error occured. Try back later." since "apps.facebook.com"... means "http://apps.facebook.com/Myapp" and not "HTTPS://apps.facebook.com/,..."
The solution: went to my application settings in facebook developers section. Clicked 'Edit'. In the left-side Menu selected "Permissions" (by default the Menu is set to Basic) and in the newly opened set of setting changed my "Auth Token Parameter" from "Query string" to "URL Fragment".
It worked! After authorization is finished the users are taken to "https://apps.facebook.com/myapp..."
Another possible mistake, if you directly copied the code from Facebook SDK example then you may get the same error despite of having everything correct. http://developers.facebook.com/docs/reference/php/
This is because in their example they have used backquotes instead of single quotes for the key of the array. The correct code is as follows.
require_once("facebook.php");
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
If your all code is working properly then to remove such type of error go to Facebook Developers Apps and disable sandbox mode.
I just encountered this problem myself. I'm developing an app internally, so my host is 'localhost'. It wasn't obvious how to set 'localhost' up in the app configuration. If you want to develop locally, set up your app by following these steps:
Go to the place where you manage your Facebook app. Specifically, you want to be in "Basic" under the "Settings" menu.
Add 'localhost' to "App Domain".
Under "Select how your app integrates with Facebook", select "Website", and enter "http://localhost/".
Save and wait a couple of minutes for the information to propagate, although it worked right away for me.
I had put the restriction on the app that only United States residence could use the app. I was working from Canada at the time this error message appeared. After removing the restriction everything worked.
Came here with a similar problem and, yes, my Sandbox was enabled. I disabled it and, voila, the login problem went away. I must warn that this problem does not affect developers and website administrators as Facebook allows those users to see the app. For this reason, I couldn't even believe that users complained about not being able to login, as I was able to login with no problems at all.
I had the same problem, and fix it by adding param &display=touch to url
try, it may helps
Answer for 2015
Sandbox mode is gone.
Proceed to My Apps -> Your App -> Status & Review and change the slider to yes for:
Do you want to make this app and all its live features available to the general public?
If you're the app developer, you may see a more specific error message, but generally that message means one of two things:
Your server returned a HTTP error code (usually 5xx)
You tried to send the user, after login, to a URL not allowed by your app configuration (though as an Admin of the app, you should see a more specific error message and Facebook error code in this case)
I had this error because I was using redirect_url as a parameter instead of redirect_uri.
The Server-Side Authentication doc page says to use redirect_url:
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID
&redirect_url=YOUR_REDIRECT_URI
&scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
&state=SOME_ARBITRARY_BUT_UNIQUE_STRING
But this is incorrect. The OAuth Dialog doc says to use redirect_uri instead, which works, so I'm assuming that you can only use one and not the other:
https://www.facebook.com/dialog/oauth/?
client_id=YOUR_APP_ID
&redirect_uri=YOUR_REDIRECT_URL
&state=YOUR_STATE_VALUE
&scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
I had tried all the answers mentioned here. But it didn't work. I had to delete and create again. I am guessing it was due to new the "Authenticated Referral". If you have added Open Graph objects which are not approved, it might give you an error.
I had the same problem and the root cause was different:
I was logged in as a Test User of a different application. Therefore I wasn't able to authorize an app that's not the one where the Test User was created for.
When I logged out and logged in as a regular user or a Test User for the app I tried to authorize, everything was OK.
In my case, there was an age issue with the account being used with the app.
If the FB app has alcoholic content then FB users who are younger than about 21 will throw an error when trying to authorize with it.
You need to specify http:// in your REDIRECT URI.
For me the issue was that the url of the app didn't completely match the url I was running it on (i.e different directories, same domain)
There is no possibility to solve this type of error. So Its better to use your custom dialog same like shown in facebook and post message again & again without login. Even though you remove your app from facebook, you can ask for login and post message successfully.
The reason in my case was completely different. I was trying to open a Feed dialog automatically after page load. And 9 times of 10 it displayed this error. First, I added show_error: true parameter as suggested by #Peter Roome, but it didn't help, displaying 104: Invalid signature, not descriptive at all.
Then I figured out the reason. The code was in $(document).ready jQuery function. And it seems that some facebook stuff had not yet been loaded at the point the code was to be executed. I moved the code to $(window).load block (which is executed after all page content is loaded), and the problem has been solved.

Categories