Пример #1
0
        <div class="container">
            <div class="panel">
                <div class="panel-header">
                    <h3 class="panel-title">LinePay 伺服器回應</h3>
                </div>
                <div class="panel-box">
                    <?php 
// LinePay Server -> Store Server (calling confirmUrl)
if (isset($_GET['transactionId']) && isset($_SESSION['cache'])) {
    $apiEndpoint = $_SESSION['cache']['apiEndpoint'];
    $channelId = $_SESSION['cache']['channelId'];
    $channelSecret = $_SESSION['cache']['channelSecret'];
    $params = ["amount" => $_SESSION['cache']['amount'], "currency" => $_SESSION['cache']['currency']];
    try {
        $LinePay = new Chinwei6\LinePay($apiEndpoint, $channelId, $channelSecret);
        $result = $LinePay->confirm($_GET['transactionId'], $params);
        echo '<pre class="code">';
        echo json_encode($result, JSON_PRETTY_PRINT);
        echo '</pre>';
    } catch (Exception $e) {
        echo '<pre class="code">';
        echo $e->getMessage();
        echo '</pre>';
    }
    unset($_SESSION['cache']);
} else {
    echo '<pre class="code">';
    echo "No Params";
    echo '</pre>';
}
    $apiEndpoint = $_POST['apiEndpoint'];
    $channelId = $_POST['channelId'];
    $channelSecret = $_POST['channelSecret'];
    $params = ["orderId" => isset($_POST['orderId']) ? $_POST['orderId'] : null, "transactionId" => isset($_POST['transactionId']) ? $_POST['transactionId'] : null];
    try {
        $LinePay = new Chinwei6\LinePay($apiEndpoint, $channelId, $channelSecret);
        $result = $LinePay->checkPayment($params);
        echo json_encode($result, JSON_PRETTY_PRINT);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
} else {
    if (isset($_POST['refundSubmit'])) {
        if (empty($_POST['transactionId'])) {
            echo "transactionId is required.";
            return;
        }
        $apiEndpoint = $_POST['apiEndpoint'];
        $channelId = $_POST['channelId'];
        $channelSecret = $_POST['channelSecret'];
        $transactionId = isset($_POST['transactionId']) ? $_POST['transactionId'] : null;
        $params = ["refundAmount" => isset($_POST['refundAmount']) ? $_POST['refundAmount'] : null];
        try {
            $LinePay = new Chinwei6\LinePay($apiEndpoint, $channelId, $channelSecret);
            $result = $LinePay->refund($transactionId, $params);
            echo json_encode($result, JSON_PRETTY_PRINT);
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
}
Пример #3
0
        <div class="container">
            <div class="panel">
                <div class="panel-header">
                    <h3 class="panel-title">LinePay 伺服器回應</h3>
                </div>
                <div class="panel-box">
                    <?php 
// Store Webpage -> Store Server
if (isset($_POST['productName'])) {
    $apiEndpoint = $_POST['apiEndpoint'];
    $channelId = $_POST['channelId'];
    $channelSecret = $_POST['channelSecret'];
    $params = ["productName" => $_POST['productName'], "productImageUrl" => $_POST['productImageUrl'], "amount" => $_POST['amount'], "currency" => $_POST['currency'], "confirmUrl" => $_POST['confirmUrl'], "orderId" => $_POST['orderId'], "confirmUrlType" => $_POST['confirmUrlType']];
    try {
        $LinePay = new Chinwei6\LinePay($apiEndpoint, $channelId, $channelSecret);
        // Save params in the _SESSION
        $_SESSION['cache'] = ["apiEndpoint" => $_POST['apiEndpoint'], "channelId" => $_POST['channelId'], "channelSecret" => $_POST['channelSecret'], "amount" => $_POST['amount'], "currency" => $_POST['currency']];
        $result = $LinePay->reserve($params);
        echo '<pre class="code">';
        echo json_encode($result, JSON_PRETTY_PRINT);
        echo '</pre>';
        if (isset($result['info']['paymentUrl']['web'])) {
            echo '<a target="_blank" href="' . $result['info']['paymentUrl']['web'] . '">點此連至 Line 頁面登入帳戶</a>';
        }
    } catch (Exception $e) {
        echo '<pre class="code">';
        echo $e->getMessage();
        echo '</pre>';
    }
} else {