$response = Easypay_request::commit_payment_request($paymentId, $config, $reqId); if ($response->is_success()) { echo "<h2>Success</h2>"; } else { echo "<h2>ERROR</h2>"; /** @var Message $msg */ $messages = $response->get_messages(); if (count($messages) > 0) { foreach ($messages as $msg) { echo "<p><strong>" . $msg->get_code() . "</strong>, " . $msg->get_field() . ", " . $msg->get_message() . "</p>"; } } else { echo "<h2>ERROR</h2>"; echo "<strong>" . $response->get_exception() . "</strong>"; } } } else { echo "<h2>ERROR</h2>"; echo "<strong>Purchase terminated with state: '" . $purchase . "'</strong>"; } if (isset($_GET['paymentId'])) { echo "<form method=\"get\" action=\"easypay_controller.php\"><input type=\"hidden\" name=\"paymentId\" value=\"" . $_GET['paymentId'] . "\" ><input type=\"submit\" name=\"status\" value=\"Get Payment Status\"/></form>"; } } elseif (isset($_GET['status']) && $_GET['paymentId']) { $paymentId = $_GET['paymentId']; $reqId = "req-id-123"; $config->set_basepath("/ce-rest-service"); $response = Easypay_request::get_payment_status($paymentId, $config, $reqId); echo "<h2>STATUS " . $response->get_status() . "</h2>"; echo "<p><strong>MSISDN: " . $response->get_formatted_msisdn() . "</strong>, OrderID: " . $response->get_order_ID() . ", Payment Info: " . $response->get_payment_info() . ", CHF " . $response->get_amount() . "</p>"; }
$assert = $expected == $actual ? "PASSED" : "FAILED"; echo "expected " . $expected . $endOfLine; echo "actual " . $actual . $endOfLine; echo "Test HASH Signature: " . $assert . $endOfLine; echo "--------------------------------------------------------------------" . $endOfLine; echo "<h3>Test PaymentRequest Signature</h3>"; $data = json_encode($paymentRequest->get_json_data()); echo "data: " . $data . $endOfLine; $secret = $config->get_easypay_secret(); $signature = base64_encode(Signature::sign($data, $secret)); $expected = "gnBbvXl2PJqXEdeO09mcjMMV4FM="; $actual = $signature; $assert = $expected == $actual ? "PASSED" : "FAILED"; echo "expected " . $expected . $endOfLine; echo "actual " . $actual . $endOfLine; echo "Test PaymentRequest Signature: " . $assert . $endOfLine; echo "--------------------------------------------------------------------" . $endOfLine; echo "<h3>Test GetCheckoutPageUrl</h3>"; $url = Easypay_request::get_checkout_page_url($config, $paymentRequest); $expected = "http://easypay-test.swisscom.ch/test-service/authorize.jsf?signature=gnBbvXl2PJqXEdeO09mcjMMV4FM%3D&checkoutRequestItem=eyJhZHVsdENvbnRlbnQiOmZhbHNlLCJhbW91bnQiOjUwLCJvcGVyYXRpb24iOm51bGwsIm9yZGVySWQiOm51bGwsInBheW1lbnRJbmZvIjoiVGVzdCIsInJvYW1pbmciOmZhbHNlLCJ1c2VyQWdlbnRPcmlnaW4iOm51bGwsInVzZXJTb3VyY2VJUCI6bnVsbCwiY29udGVudFR5cGUiOm51bGwsInN0b3JlU291cmNlIjpudWxsLCJjYW5jZWxVcmwiOm51bGwsImNwU2VydmljZUlkIjpudWxsLCJjcFN1YnNjcmlwdGlvbklkIjpudWxsLCJkZXNjcmlwdGlvbiI6bnVsbCwiZHVyYXRpb24iOjAsImR1cmF0aW9uVW5pdCI6bnVsbCwiZXJyb3JVcmwiOm51bGwsImltYWdlVXJsIjpudWxsLCJtZXJjaGFudElkIjpudWxsLCJwcm9tb3Rpb25BbW91bnQiOm51bGwsInN1Y2Nlc3NVcmwiOm51bGwsInRpdGxlIjpudWxsfQ%3D%3D"; $actual = $url; $assert = $expected == $actual ? "PASSED" : "FAILED"; echo "expected " . $expected . $endOfLine; echo "actual " . $actual . $endOfLine; echo "Test GetCheckoutPageUrl: " . $assert . $endOfLine; echo "--------------------------------------------------------------------" . $endOfLine; ?> </p> </body> </html>