public function testRecurringFromCharge() { $m = ChargeIO_Merchant::findCurrent(); $accounts = $m->merchantAccounts(); $account = reset($accounts); // Create a recurring charge from a new charge with a schedule $card = $this->newCard(); $charge = ChargeIO_Charge::create($card, 10000, array('account_id' => $account->id, 'recur' => array('interval_unit' => 'WEEK', 'interval_delay' => 1))); $this->assertNotNull($charge); $this->assertEquals('AUTHORIZED', $charge->status); $this->assertNotNull($charge->recurring_charge_id); $this->assertNotNull($charge->recurring_charge_occurrence_id); // Retrieve occurrences -- should contain the initial paid occurrence associated with the charge and the next pending occurrence $rc = ChargeIO_RecurringCharge::findById($charge->recurring_charge_id); $this->assertNotNull($rc); $occs = $rc->occurrences(); $this->assertEquals(2, $occs->getTotalEntries()); $this->assertEquals('PENDING', $occs[0]->status); $this->assertEquals('PAID', $occs[1]->status); $this->assertEquals(1, count($occs[1]->transactions)); $this->assertEquals($charge->id, $occs[1]->transactions[0]['id']); $transaction_id = $occs[1]->transactions[sizeof($occs[1]->transactions) - 1]['id']; $this->assertNotNull($transaction_id); $c = new ChargeIO_Charge($occs[1]->transactions[0], new ChargeIO_Connection(ChargeIO::getCredentials())); $this->assertNotNull($c); $this->assertEquals($charge->id, $c->id); $r = $c->refund(10); $this->assertNotNull($r); $this->assertNotNull($r->id); }
public function testHolds() { // New authorization for $20 from one-time card token $token = ChargeIO_OneTimeToken::createOneTimeCard($this->newCard()->attributes); $charge = ChargeIO_Charge::authorize(new ChargeIO_PaymentMethodReference(array('id' => $token->id)), 2000); $this->assertNotNull($charge); $this->assertEquals('AUTHORIZED', $charge->status); $this->assertEquals(false, $charge->auto_capture); // Retrieve first page (most recent) pending holds $holds = ChargeIO_Charge::allHolds(); $this->assertGreaterThanOrEqual(1, $holds->getTotalEntries()); $this->assertEquals($charge->id, $holds[0]->id); // Convert manual-capture authorization to auto-capture $charge->capture(2000, array('capture_time' => 'NEXT_AUTO_CAPTURE')); $this->assertEquals('AUTHORIZED', $charge->status); $this->assertEquals(true, $charge->auto_capture); // Charge no longer appears in pending holds $holds = ChargeIO_Charge::allHolds(); $this->assertGreaterThanOrEqual(0, $holds->getTotalEntries()); if ($holds->getTotalEntries() > 0) { $this->assertNotEquals($charge->id, $holds[0]->id); } }