Hey Brad,
Here is my setup - using PHP as well:
$charge = array(
'recurring_application_charge' => array(
'price' => '3.99',
'name' => 'AtCost Membership Plan',
'return_url' => Router::url('/charges/confirm',
true),
'test' => true
)
);
try {
$recurringApplicationCharge = $sc->call('POST',
'/admin/recurring_application_charges.json', $charge);
// Save the charge
$data = array(
'Charge' => array(
'shop_id' =>
$this->Session->read('
shopify.shopData.id'),
'amount' => '3.99',
'plan_id' => 1,
'test' => true
)
);
$this->loadModel('Charge');
$charge = $this->Charge->save($data);
$this->Session->write('shopify.charge_id',
$charge['Charge']['id']);
$this->redirect($recurringApplicationCharge['confirmation_url']);
} catch (Exception $e){
pr($e);
}
This API call will generate the charge and ask the customer to
confirm the charge. When they accept it, they get redirected to
the return url that you provided in the first api call. At that
point, you still need to activate the charge with the charge id
you are given. Like this:
$chargeId = $this->request->query['charge_id'];
if (is_null($chargeId) || empty($chargeId)){
// Throw error here
}
// Activate the charge
$sc = parent::get_shopify_client();
$activated = $sc->call('POST',
'/admin/recurring_application_charges/' . $chargeId .
'/activate.json');
// Save the activation timestamp
$this->Charge->read(null,
$this->Session->read('shopify.charge_id'));
$this->Charge->set('activated_on', date('Y-m-d H:i:s'));
$this->Charge->save();
Hope this helps!
Luckner Jr.