/** * @param ChargeFactoryInterface $factory */ private function refundAndCancel($factory) { // creating a new charge. $charge = $factory->create($this->cards->getSuccess()); $amount = rand(2000, 9999); $charge_id = $charge->charge($amount); $this->assertTrue(strlen($charge_id) > 0); // now retrieve and refund it. $list = $factory->getList(1); $this->assertEquals(1, count($list)); $retrieved = $list[0]; $this->assertEquals($charge_id, $retrieved->getId()); $this->assertEquals($amount, $retrieved->getAmount()); $this->assertTrue($retrieved->getAmount() > 1000); // now refund 1000 yen. $retrieved->refund(1000); // retrieve again. $retrieved = $factory->getList(1)[0]; $this->assertEquals($amount, $retrieved->getAmount()); $this->assertEquals(1000, $retrieved->getAmountRefund()); $this->assertTrue($retrieved->isRefund()); // now cancel the charge. $retrieved->cancel(); // retrieve again. $retrieved = $factory->getList(1)[0]; $this->assertEquals($amount, $retrieved->getAmount()); $this->assertEquals($amount, $retrieved->getAmountRefund()); $this->assertTrue($retrieved->isRefund()); }
/** * @param string $service * @param ChargeFactoryInterface $factory */ private function limitAndOffset($service, $factory) { $all10 = $factory->getList(10, 0); if (count($all10) < 10) { $this->markTestIncomplete("need at least 10 charges to test {$service}..."); } // retrieve the first 4 charges only. $first4 = $factory->getList(4, 0); $this->assertEquals(4, count($first4)); foreach ($first4 as $idx => $charge) { $this->assertEquals($all10[$idx]->getId(), $charge->getId()); } // retrieve the next 4 charges. $first4 = $factory->getList(4, 4); $this->assertEquals(4, count($first4)); foreach ($first4 as $idx => $charge) { $this->assertEquals($all10[$idx + 4]->getId(), $charge->getId()); } }
/** * @param ChargeFactoryInterface $factory * @return UpdatePayInterface */ private function createAndRetrieve($factory) { // creating a new charge. $charge = $factory->create($this->cards->getSuccess()); $amount = rand(1000, 9999); $charge_id = $charge->charge($amount); $this->assertTrue(strlen($charge_id) > 0); // retrieving the created charge. $list = $factory->getList(1); $this->assertEquals($charge_id, $list[0]->getId()); $this->assertEquals($amount, $list[0]->getAmount()); return $list[0]; }