Error with Square Checkout API - "The order has expired" - square

Getting this error (category: INVALID_REQUEST_ERROR code: ORDER_EXPIRED) from the checkout endpoint when a user clicks through, then comes back days later to pay. This is the endpoint that takes the order information and provides a unique checkout URL for the user.
How long do orders have before they expire? I'm not even clear on what exactly is expiring?
Not much sent over in the post. Trying to determine if I just need to alter the idempotency key "if an order has expired", which seems counterproductive.
$this->_order = ['redirect_url' => $redirectUrl,
'idempotency_key' => $this->_idempotencyKey,
'ask_for_shipping_address' => false
];
$this->_order['order']['reference_id'] = (string) "{$this->getInvoice()->getId()}";

Checkout urls expire in 24 hours. Square is working on updating the documentation to reflect this info.

Related

GoogleCalendarAPI to insert events giving Rails--[API Error]: --{:error=>["Excon::Error::Forbidden", "Expected([200]) <=> Actual(403 Forbidden)\n"]}

I have been using Google calendar API to insert events in user's calendar. I have written a code which takes csv(with approx 1000 rows) as an input with minimum required parameters to create events such as event_title, event_description, event_date (since its a full day event) and recipient email id..The code runs in background using sidekiq.
Out of 1000 rows , only some events are inserted in user's calendar. Most of them are giving Rails -- [API Error]: -- {:error=>["Excon::Error::Forbidden", "Expected([200]) <=> Actual(403 Forbidden)\n"]} error.
I have been using excon client (gem) to hit the urls to refresh token and inserting an event.
Token is refreshed
Loop (
Hitting API to insert events
)
rescue error
end
I couldnt figure out what's going wrong ?..Any help is appreciated. While registering my app in Google developer console , I have given the full scope of calendar api auth/calendar.
I tried setting Excon.defaults[:ssl_verify_peer] = false.
Implementing such api first time.
The 403 would indicate that the permissions are not valid in some way. My guesses would be that either the token is expiring, you are hitting some kind of rate limit, or something is different about the parameters for the failing request such that the particular event is not allowed.
Do you think any of those is more likely than the others? If it is the token expiring, you could try to catch the 403 error, refresh the token, and retry. If it's one of the others it might take a bit more digging to see why the ones that are failing are different from the ones that succeed.

Any POST or GET requests from the Revue API return 401

I am trying to add subscribers to my newsletter using the Revue api. According to the documentation, I need to add a header called 'Authorization' and value 'Token MY-TOKEN' in my requests.
In order to test out the API I am using Postman as seen in the screenshot below:
Any request I do to any url, ends up with a 401.
What am I missing here? The token value is copy pasted from the bottom of https://www.getrevue.co/app/integrations ('Your API key is xyz') as the documentation mentions. Double checked that there are no extra spaces added.
You cannot use the API (or at least certain entry points) without first verifying your account
If you fail to do this, your requests end with a 401 status.
Verify your account
There is no explicit option to verify your account. Instead, you need to import an existing mailing list. If you don't have a list to import, you can enforce this step by creating an artificial list, containing just your email. To do so, visit your Revue dashboard, Subscribers section, and click "Import from file":
.
Then, enter your email and two commas to skip your first and last name:
Submit and fill the next form.
When completed, a top ribbon indicates that the review is on its way:
You need to wait for the review to be completed.
Perform a request
To get your API key, visit your Revue dashboard, Account settings, Integrations, and scroll down to the bottom of the page:
Run something like:
const revueApiKey = "[your API key]";
const result = await fetch('https://www.getrevue.co/api/v2/subscribers', {
method: 'POST',
headers: {
Authorization: `Token ${revueApiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: "john#example.com", double_opt_in: false })
});
If you have the following when you log in to Revue
"We are reviewing your account."
You will not be able to make API calls and will get a 401.
I've talked to support on the issue and unfortunately, it's undocumented at the moment.
Took nearly a week for me to get reviewed but it's working fine now. It is at the end of the Christmas period so I am hoping they are only temporarily that slow at reviewing accounts.

How do I make user authentication api for laravel

I tried this using jwt-auth, but the thing is token gets expired. I want to remember the user with token that never gets expired. Is their any possible way to do it in Laravel 5.2.
Should I send email and password for each request to api instead of saving session and token.
I will implement this way:
If the user selects Remember me, set the ttl to a longer time ,say 1 year OR month. To do this we need to publish
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"
Then we can override the default ttl value which is 60 mins to our desired value.
$jwt = \Illuminate\Support\Facades\Config::get('jwt');
$jwt['ttl'] = 60*24*30; // 30 days
\Illuminate\Support\Facades\Config::set('jwt',$jwt);
Hope this helps!

Paypal Autoreturn no post or get data

I have the following working in Sandbox
*Return without Autoreturn, no PDT;
*Return with Autoreturn, with PDT;
*IPN works properly
What I want to use is Autoreturn without PDT but when that is set Autoreturn sends no Get or Post variables. I've also checked the various other posts on this subject and rm=2 is set. Any help appreciated
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$PAYPAL_URL = "https://www.sandbox.paypal.com/cgi-bin/webscr?";
$newpost['business']='xxxxxxxxxx';
$newpost['cancel_return']='http://localhost/cz/subscribe.php';
$newpost['return']='https://www.xxxxxxxx/paypal/success_test.php';
$newpost['cmd']='_donations'; //donation checkout
$newpost['lc']='US';
$newpost['rm']='2';
$newpost['cbt']='Click to Set Subscriber Status';
$newpost['currency_code']='USD';
$newpost['button_subtype']='services';
$newpost['no_note']='1';
$newpost['no_shipping']='2'; //shipping address required
$newpost['tax_rate']='0.000';
$newpost['bn']='xxxxxxxx_BuyNow_WPS_US';
$newpost['amount']=$prod[1];
$newpost['item_name']=' Subscription'; //product name
After a lot of testing what I found was Paypal Sandbox as of Sep 23 2013 on non-PAYPAL account transactions autoreturns using IPN format when using CMD=_xclick, however on CMD=_donation it sits there waiting until the user clicks the return to mysite button.
*When processing a Paypal account transaction with CMD=_donation, autoreturn using IPN format returns nothing.* Using CMD=_xclick and allowing it to return in ten seconds works, as does clicking "If you are not redirected within 10 seconds, click here."
I don't know if this behavior occurs in production, however it rivals the readability of the Paypal documentation for clarity and understanding.

Send an email via MailChimp

I think problem is around $api->listSubscribers()
include('../libs/mailchimp/MCAPI.class.php');
$options = array('list_id' => '$list_id', 'subject' => 'Prova', 'from_name' => 'name', 'from_email' => 'info#example.com');
$content = array('html' => '<p>Testo di prova</p>');
$api = new MCAPI($apikey);
$campaignId = $api->campaignCreate('trans', $options, $content);
$api->listSubscribe($options['list_id']);
$api->campaignSendNow($campaignId);
if ($api->errorCode){
echo "Unable to Create New Campaign!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
echo "New Campaign ID:".$campaignId ."\n";
}
Why does'nt it send an email?
You have a several issues here:
The first one is that you are not doing error checking after each API call. If you take the error checking code from the bottom and stick it after the listSubscribe() call, you'll immediately get an error because you aren't passing any sort of subscriber data (at the very least you need the email address). The docs for listSubscribe are here
Once you do that - unless you've thoroughly read and considered the options in the listSubscribe docs - your second issue is going to be that you are running listSubscribe with the double_optin parameter set to true (the default), which means they won't be subscribed until clicking a link in the confirmation email.
Next, that code is just going to get you in trouble, and probably quickly. If you are going to use psuedo-transcational campaigns it is imperrative that you only create ONE psuedo-trans campaign per type of email and then send that campaign over and over. That's how they are intended to work. Not doing that is going to cause you to fill up your account with a whole bunch of trash campaigns at which point there's no point in using a psuedo-trans campaign since that's the same as creating/sending a regular campaign to a single user over and over.
Do you get any errors?
It seems you are not including the api key, it should look like:
$api = new MCAPI($apikey);
Instead of:
$api = new MCAPI('apikey');
You get the API Key from your api dashboard: http://admin.mailchimp.com/account/api