/** * @param PayService $service * @param array $post * @param int $amount */ function createPayJp(PayService $service, $post, $amount) { if (!($card_id = $service->getCardIdInPost($post))) { return; } $factory = $service->getFactory(); if (isset($post['authorize']) && $post['authorize'] === 'auth') { $factory->create($card_id)->authorize($amount); } else { $factory->create($card_id)->charge($amount); } }
<?php use AsaoKamei\PayJp\Interfaces\UpdatePayInterface; require_once __DIR__ . '/demo.inc.php'; $service = new PayService(); $factory = $service->getFactory(); $list = $factory->getList(); ?> <h1><a href="index.php" >top</a> > Payment List</h1> <?php foreach ($list as $charge) { echo '<ul>'; echo chargeInfo($charge); echo '</ul>'; } function chargeInfo(UpdatePayInterface $charge) { $html = "\n <li>{$charge->getId()}</li>\n <li>created at: {$charge->getCreatedAt()->format('Y/m/d H:i')}</li>\n <li>amount: {$charge->getAmount()}</li>\n "; if ($charge->isRefund()) { $html .= "<li>refund amount: {$charge->getAmountRefund()}</li>"; } if (!$charge->isCaptured()) { $html .= "<li>capture: <form method='post' action='capture.php' style='display: inline;'>\n <input type='hidden' name='id' value='{$charge->getId()}'/>\n <input type='submit' value='capture this charge'/>\n </form></li>\n "; } elseif ($charge->getAmount() > $charge->getAmountRefund()) { $html .= "<li>refund: <form method='post' action='refund.php' style='display: inline;'>\n <input type='hidden' name='id' value='{$charge->getId()}'/>\n <input type='text' name='refund' value='{$charge->getAmount()}'/>\n <input type='submit' value='refund'/>\n </form> OR \n <form method='post' action='refund.php' style='display: inline;'>\n <input type='hidden' name='id' value='{$charge->getId()}'/>\n <input type='submit' value='cancel'/>\n </form></li>"; } return $html; }