public function testTransactionLifecycle() { // New charge for $10 $card = $this->newCard(); $charge = ChargeIO_Charge::create($card, 1000); $this->assertNotNull($charge); $this->assertEquals('AUTHORIZED', $charge->status); // Attach signature and add gratuity of $2.50 $sigdata = '[{"x":[179,179,179,179,180,188,195,206,218,228,245,252,261,267,270,270,269,262,254,246,237,230,225,221,219,219,222,229,239,251,263,274,282,286,288,289,286],"y":[77,84,89,97,104,113,120,127,132,133,133,133,128,121,114,106,99,93,87,85,85,85,87,93,99,109,120,129,138,144,146,147,145,141,134,130,127]}]'; $charge->sign($sigdata, 250); $this->assertNotNull($charge->signature_id); $this->assertEquals(250, $charge->gratuity); $sig = ChargeIO_Signature::findById($charge->signature_id); $this->assertNotNull($sig); $this->assertEquals($sigdata, $sig->data); $this->assertEquals('chargeio/jsignature', $sig->mime_type); // Refund $1.75 $refund = $charge->refund(175); $this->assertNotNull($refund); $this->assertEquals('AUTHORIZED', $refund->status); $this->assertEquals(175, $refund->amount); // Void the refund $refund->void(); $this->assertEquals('VOIDED', $refund->status); // Capture the original charge, but for only $9.10 $charge->capture(910); $this->assertEquals('COMPLETED', $charge->status); $this->assertEquals(910, $charge->amount); }
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); }