$messageType = "error"; } } // update credit card info OR/AND password in our database if (!isset($message) && (isset($newPassword) || isset($creditCardId))) { updateUser($_POST['user']['email'], $newPassword, $creditCardId); $message = "Your profile has been updated."; $messageType = "success"; } } else { $message = "The current password that you provided is invalid."; $messageType = "error"; } } } catch (\PayPal\Exception\PPConnectionException $ex) { $message = parseApiError($ex->getData()); $messageType = "error"; } catch (Exception $ex) { $message = $ex->getMessage(); $messageType = "error"; } ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <meta content='IE=Edge,chrome=1' http-equiv='X-UA-Compatible'> <meta content='width=device-width, initial-scale=1.0' name='viewport'> <title>PizzaShop</title> <!-- Le HTML5 shim, for IE6-8 support of HTML elements --> <!--[if lt IE 9]>
function placeOrder() { //sementara semua credit card //$order = $_REQUEST['order']; //$order['payment_method'] == 'credit_card'; $json['paystate'] = 0; //langkah pertama daftarkan cc $creditCardId = $this->daftarkanCC(); $currency = 'USD'; $amount = addslashes($_POST['appprice']); $descr = addslashes($_POST['appdescr']); $app_id = addslashes($_POST['appid']); if ($creditCardId != NULL) { try { $paypal = new PaypalWrap(); $payment = $paypal->makePaymentUsingCC($creditCardId, $amount, $currency, $descr); // pr($payment); $order = new PaypalOrder(); $order->amount = $amount; $order->created_time = leap_mysqldate(); $order->currency = $currency; $order->description = $descr; $order->user_id = Account::getMyID(); $order->payment_id = $payment->getId(); $order->state = $payment->getState(); $orderId = $order->save(); $state = $order->state; if ($state == "approved") { $json['paystate'] = 1; //update paket active $app = new AppAccount(); $app->getByID($app_id); $app->app_active = 1; $app->app_contract_start = leap_mysqldate(); $app->app_pulsa = 1000; $app->app_contract_end = date('Y-m-d', strtotime('+1 year')); $app->load = 1; $app->save(); } $message = "Your order has been placed successfully. Your Order id is <b>{$orderId}</b>"; $messageType = 1; } catch (\PayPal\Exception\PPConnectionException $ex) { $message = parseApiError($ex->getData()); $messageType = 0; } catch (Exception $ex) { $message = $ex->getMessage(); $messageType = 0; } } else { $messageType = 0; $message = "credit card ID registration error"; } $json['bool'] = $messageType; $json['err'] = $message; echo json_encode($json); die; // if($_SERVER['REQUEST_METHOD'] == 'POST') { // // try { // if($order['payment_method'] == 'credit_card') { // // // Make a payment using credit card. // $user = getUser(getSignedInUser()); // $payment = makePaymentUsingCC($user['creditcard_id'], $order['amount'], 'USD', $order['description']); // $orderId = addOrder(getSignedInUser(), $payment->getId(), $payment->getState(), // $order['amount'], $order['description']); // $message = "Your order has been placed successfully. Your Order id is <b>$orderId</b>"; // $messageType = "success"; // // } else if($order['payment_method'] == 'paypal') { // // $orderId = addOrder(getSignedInUser(), NULL, NULL, $order['amount'], $order['description']); // // Create the payment and redirect buyer to paypal for payment approval. // $baseUrl = getBaseUrl() . "/order_completion.php?orderId=$orderId"; // $payment = makePaymentUsingPayPal($order['amount'], 'USD', $order['description'], // "$baseUrl&success=true", "$baseUrl&success=false"); // updateOrder($orderId, $payment->getState(), $payment->getId()); // header("Location: " . getLink($payment->getLinks(), "approval_url") ); // exit; // } // } catch (\PayPal\Exception\PPConnectionException $ex) { // $message = parseApiError($ex->getData()); // $messageType = "error"; // } catch (Exception $ex) { // $message = $ex->getMessage(); // $messageType = "error"; // } // } }
if (trim($_POST['user']['email']) == '' || $_POST['user']['password'] == '') { $errorMessage = "You must enter a email address and password to register."; } else { if ($_POST['user']['password'] != $_POST['user']['password_confirmation']) { $errorMessage = "Passwords do not match. Please check."; } else { try { $creditCardId = NULL; // User can configure credit card info later from the // profile page or can use paypal as his funding source. if (trim($_POST['user']['credit_card']['number']) != "") { $creditCardId = saveCard($_POST['user']['credit_card']); } $userId = addUser($_POST['user']['email'], $_POST['user']['password'], $creditCardId); } catch (PPConnectionException $ex) { $errorMessage = $ex->getData() != '' ? parseApiError($ex->getData()) : $ex->getMessage(); } catch (Exception $ex) { $errorMessage = $ex->getMessage(); } } } if (isset($userId) && $userId != false) { signIn($_POST['user']['email']); header("Location: ../index.php"); exit; } } ?> <!DOCTYPE html> <html lang='en'> <head>
//calculate total amount of all quantity. $total_amount = $item_qty * $item_price; try { // try a payment request //if payment method is paypal $result = create_paypal_payment($total_amount, PP_CURRENCY, '', $items, RETURN_URL, CANCEL_URL); //if payment method was PayPal, we need to redirect user to PayPal approval URL if ($result->state == "created" && $result->payer->payment_method == "paypal") { $_SESSION["payment_id"] = $result->id; //set payment id for later use, we need this to execute payment header("location: " . $result->links[1]->href); //after success redirect user to approval URL exit; } } catch (PPConnectionException $ex) { echo parseApiError($ex->getData()); } catch (Exception $ex) { echo $ex->getMessage(); } } ### After PayPal payment method confirmation, user is redirected back to this page with token and Payer ID ### if (isset($_GET["token"]) && isset($_GET["PayerID"]) && isset($_SESSION["payment_id"])) { try { $result = execute_payment($_SESSION["payment_id"], $_GET["PayerID"]); //call execute payment function. if ($result->state == "approved") { //if state = approved continue.. //SUCESS unset($_SESSION["payment_id"]); //unset payment_id, it is no longer needed //get transaction details