Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Checking Charge Status

Steve Spasov edited this page Oct 13, 2020 · 2 revisions

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:

use Osiset\ShopifyApp\Services\ChargeHelper;
use Osiset\ShopifyApp\Objects\Values\ChargeReference;
use App\User;

// ...

// Setup the "Charge Helper"
$chs = resolve(ChargeHelper::class);
$shops = User::all();

// Loop all shops
foreach ($shops as $shop) {
  $plan = $shop->plan;
  if ($plan === null) {
     // No plan, skip
     continue;
  }

  // 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.

Clone this wiki locally