You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Luke Walsh edited this page Dec 18, 2022
·
1 revision
While this package stores the result of charging a shop for a plan, it does not actively check the charge's status; example: If the recurring charge was later cancelled, if the recurring charge could not complete for one month, etc.
It is not checked by the package because that would require custom jobs, custom checks, and custom logic which varies from app to app.
If you would like to check all your shops' charge statuses for plans, you can schedule a job to run every night or every week. Here's an example:
useOsiset\ShopifyApp\Services\ChargeHelper;
useOsiset\ShopifyApp\Objects\Values\ChargeReference;
useApp\User;
// ...// Setup the "Charge Helper"$chs = resolve(ChargeHelper::class);
$shops = User::all();
// Loop all shopsforeach ($shopsas$shop) {
$plan = $shop->plan;
if ($plan === null) {
// No plan, skipcontinue;
}
// Get the charge entry from database, set it to the charge helper to use for API calls$charge = $chs->chargeForPlan($plan->getId(), $shop);
$chs->useCharge($charge->getReference());
// Get the charge data from Shopify API$chargeData = $chs->retrieve($shop);
// Now you can access `$chargeData['status']` to check its status and control your flow
}
Welcome to the wiki!
Please see the homepage for a list of relevant pages.