/** * @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; }
$table->money = $total_fee; $table->currency = 'CNY'; $table->bank = '网银(支付宝)'; $table->service = 'chinabank'; $table->create_time = time(); $table->insert(array('id', 'order_id', 'money', 'currency', 'service', 'create_time', 'bank')); $order = Table::Fetch('order', $order_id); //update team,user,order,flow state// ZTeam::BuyOne($order); //查找地市 $area = Table::Fetch('t_city_category_rel', $team["city_id"], 'category_id'); //查找用户 $user = Table::Fetch('user', $order["user_id"], 'id'); $order_type = '3'; //更新支付状态 PayService::afterPayDoSomething($team, $order, $user, $area, $out_trade_no, $order_type); Phplog::RecordOrderSuccessLog(" 流水号:" . $_POST['trade_no'] . " 通知id:" . $_POST['notify_id'] . " 团购订单号:" . $order_id . " 支付金额:" . $total_fee . " 通知时间时间:" . $_POST['notify_time']); $is_ok = true; } else { Phplog::RecordOrderFailLog(" 流水号:" . $payNo . " 团购订单号:" . $orderId . " 支付金额:" . $amount . " 支付银行:" . $banks . " 送货信息:" . $contractName . " 发票抬头:" . $invoiceTitle . " 支付人:" . $mobile . " 支付时间:" . $payDate . " 保留字段:" . $reserved); } } $team = Table::Fetch('team', $order['team_id'], 'id'); //团购结束或者数量已经卖完关闭没有完成支付的订单 if ($team['end_time'] < time() || $team['max_number'] > 0 && $team['now_number'] >= $team['max_number']) { //关闭没有完成支付的订单 ZTeam::CloseTrade($order['team_id']); //将团购权重置为0 Table::UpdateCache('team', $order['team_id'], array('sort' => 0)); } if ($is_ok) {
require_once './sdk/Hpp.Protocol.php'; require_once './sdk/Hpp.PayService.php'; require_once './repository.php'; //订单号 $orderNumber = md5(uniqid(mt_rand(), true)); //请求参数 $payRequest = new PayRequest(); $payRequest->setAppId('CA_APP-ID-0001'); $payRequest->setPayInterface($_POST['pay_interface']); $payRequest->setOrderNumber($orderNumber); $payRequest->setOrderSubject('php-demo-1分钱支付体验'); //订单标题 $payRequest->setOrderDescribe($_POST['order_describe']); $payRequest->setAmount($_POST['order_amount']); $payRequest->setCustomerIp('127.0.0.1'); $payRequest->setReturnUrl('http://127.0.0.1/callback-return.php?orderNumber' . $orderNumber); $payResponse = new PayResponse(PayService::startPay($payRequest)); //保存部分参数供后续用 //订单状态 $payRequest->setValue('status', Protocol::STATUS_ORDER_CREATED); $payRequest->setValue(Protocol::KEY_TRADE_SN, $payResponse->getTradeSn()); //相应数据 $payRequest->setValue('responseData', ['rawHtml' => $payResponse->getRawHtml(), 'wXQRPayUrl' => $payResponse->getWXQRPayUrl()]); //订单日期 $now = (new DateTime())->format('m-d H:i:s'); $payRequest->setValue('createOn', $now); Repository::save($payRequest->getOrderNumber(), $payRequest->toJsonString()); //ajax api输出 header('Content-Type: application/json; charset=UTF-8"'); echo json_encode(['orderNumber' => $orderNumber]);
<?php require 'PayService.php'; $salary = $_GET['salary']; $inss = 0.0; $irpf = 0.0; $payInss = 0.0; $paySalary = 0.0; if (is_numeric($salary) && is_numeric($inss) && is_numeric($irpf)) { $payInss = PayService::getInss($salary, $inss); $payIrpf = PayService::getIrpf($salary, $irpf); $paySalary = PayService::getSalary($salary); } echo $payInss; echo $payIrpf; echo $paySalary;
// UTF-8인 경우 "utf-8"로 설정 $siteCode = $_GET['site_cd']; $orderID = $_GET['ordr_idxx']; $paymentMethod = $_GET['pay_method']; $escrow = $_GET['escw_used'] == 'Y' ? true : false; $productName = $_GET['good_name']; // 아래 두값은 POST된 값을 사용하지 않고 서버에 SESSION에 저장된 값을 사용하여야 함. $paymentAmount = $_GET['good_mny']; // 결제 금액 $returnUrl = $_GET['Ret_URL']; // Access Credential 설정 $accessLicense = ''; $signature = ''; $timestamp = ''; // Base Request Type 설정 $detailLevel = '0'; $requestApp = 'WEB'; $requestID = $orderID; $userAgent = $_SERVER['HTTP_USER_AGENT']; $version = '0.1'; try { $payService = new PayService($g_wsdl); $payService->setCharSet($charSetType); $payService->setAccessCredentialType($accessLicense, $signature, $timestamp); $payService->setBaseRequestType($detailLevel, $requestApp, $requestID, $userAgent, $version); $payService->setApproveReq($escrow, $orderID, $paymentAmount, $paymentMethod, $productName, $returnUrl, $siteCode); $approveRes = $payService->approve(); printf("%s,%s,%s,%s", $payService->resCD, $approveRes->approvalKey, $approveRes->payUrl, $payService->resMsg); } catch (SoapFault $ex) { printf("%s,%s,%s,%s", "95XX", "", "", "연동 오류 (PHP SOAP 모듈 설치 필요)"); }
<?php require_once './sdk/Hpp.PayService.php'; require_once './sdk/Hpp.Protocol.php'; /** * 处理入账响应 */ //直接读取整个req过来的请求 $rawEventBody = file_get_contents('php://input'); $tradeEvent = new TradeSuccessEvent(PayService::reciveTradeSuccessEvent($rawEventBody)); if ($tradeEvent->isTradeSuccess()) { //TODO: 订单已完成,在这里完成发货逻辑... //存储模拟的订单信息 $order = Repository::find($tradeEvent->getOrderNumber()); $order['status'] = $tradeEvent->getStatus(); Repository::save($tradeEvent->getOrderNumber(), json_encode($order)); }
<?php require_once './sdk/Hpp.PayService.php'; require_once './sdk/Hpp.Protocol.php'; require_once './repository.php'; /** * 订单状态查询 */ $orderNumber = $_REQUEST['orderNumber']; //不区分GET/POST $order = Repository::find($orderNumber); if ($order['status'] == 'NOTIFY_CONFIRM') { header('location: ./order-list.php'); exit; } //订单并未完成,向hpp提交订单状态查询请求 $queryRequest = new OrderQueryRequest($order[Protocol::KEY_TRADE_SN]); $queryResponse = new OrderQueryResponse(PayService::startOrderQuery($queryRequest)); //刷新请求状态 $order['status'] = $queryResponse->getStatus(); Repository::save($orderNumber, json_encode($order)); header('location: ./order-list.php');
<?php require_once __DIR__ . '/demo.inc.php'; $service = new PayService(); if ($service_name = getIdInPost('service')) { $key = getIdInPost('key'); $pub = getIdInPost('pub'); $service->setupService($service_name, $key, $pub); } ?> <h1>Credit Cards</h1> <h3>Current Service</h3> <?php if ($service->isLoaded()) { ?> <?php echo $service->getInfo(); ?> <a href="new-pay.php">new payment</a><br/> <a href="list-pay.php">list payments</a> <?php } else { ?> <p>service not set. </p> <?php