148 lines
3.5 KiB
PHP
148 lines
3.5 KiB
PHP
<?php
|
|
$page = "payment";
|
|
include 'header.php';
|
|
|
|
header("Expires: -1");
|
|
header("Cache-Control: no-cache");
|
|
header("Pragma: nocache");
|
|
|
|
$task = semods::getpost('task','main');
|
|
$paymentgw_id = semods::getpost('paymentgw_id', 'paypal'); // default -> paypal
|
|
|
|
|
|
|
|
|
|
if($task == 'cancel') {
|
|
semods::redirect("home.php");
|
|
}
|
|
|
|
|
|
|
|
|
|
if($task == 'checkout') {
|
|
|
|
$cart = new semods_cart();
|
|
if($cart->cart_exists == false) {
|
|
semods::redirect("Location: home.php");
|
|
}
|
|
|
|
$paymentgw = semods_paymengtw_factory( $paymentgw_id );
|
|
|
|
if(!$paymentgw->checkout( $cart )) {
|
|
$is_error = 1;
|
|
$error_message = 100015072;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($task == 'pay') {
|
|
|
|
// PROCESS CART
|
|
|
|
// also must link to current userid .. ?
|
|
// in paypal case cart is got from "custom"
|
|
|
|
|
|
$cart = new semods_cart();
|
|
if($cart->cart_exists == false) {
|
|
header("Location: home.php");
|
|
exit();
|
|
}
|
|
|
|
$paymentgw = semods_paymengtw_factory( $paymentgw_id );
|
|
|
|
if(!$paymentgw->pay( $cart ) ) {
|
|
$is_error = 1;
|
|
// application user displayable errors are >= 100
|
|
if($paymentgw->errID >= 100) {
|
|
$error_message = $paymentgw->errMsg;
|
|
} else {
|
|
$error_message = 100015073;
|
|
}
|
|
//$hide_cart = true;
|
|
} else {
|
|
$result = 1;
|
|
$success_message = 100015075;
|
|
$hide_cart = true;
|
|
unset( $_SESSION['cart_id'] );
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($task == 'success') {
|
|
|
|
// prevent warnings on already started sessions
|
|
$error_level = error_reporting( 0 );
|
|
session_start();
|
|
error_reporting( $error_level );
|
|
unset( $_SESSION['cart_id'] );
|
|
|
|
$result = 1;
|
|
$success_message = 100015075; // tbd: add "thanks and after we recive notification, blah nlah
|
|
$hide_cart = true;
|
|
|
|
}
|
|
|
|
|
|
if($task == 'main') {
|
|
// show cart contents & payment buttons
|
|
|
|
$cart = new semods_cart();
|
|
if($cart->cart_exists == false) {
|
|
|
|
$is_error = 1;
|
|
$error_message = 100015074;
|
|
$hide_cart = true;
|
|
|
|
} else {
|
|
|
|
if($cart->has_recurring_payments()) {
|
|
$sql = "SELECT paymentgateway_id FROM se_semods_paymentgateways WHERE paymentgateway_enabled = 1 AND paymentgateway_handle_recurringpayments = 1";
|
|
} else {
|
|
$sql = "SELECT paymentgateway_id FROM se_semods_paymentgateways WHERE paymentgateway_enabled = 1";
|
|
}
|
|
|
|
// Load up payment gateways
|
|
$paymentgateways = array();
|
|
$rows = $database->database_query( $sql );
|
|
while($row = $database->database_fetch_assoc($rows)) {
|
|
$gateway = semods_paymengtw_factory( $row['paymentgateway_id'] );
|
|
if($gateway) {
|
|
$checkout_data = $gateway->create_checkout_blob($cart);
|
|
$paymentgateways[] = array( 'gateway_id' => $row['paymentgateway_id'],
|
|
'gateway_checkout' => $checkout_data['checkout'],
|
|
'gateway_blob' => $checkout_data['blob']
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($cart) {
|
|
$smarty->assign( 'cart', $cart );
|
|
$smarty->assign( 'cart_total', $cart->total() );
|
|
$smarty->assign( 'cart_updateable', $cart->is_updateable() );
|
|
}
|
|
|
|
$currency_code = semods::get_setting('payment_currency');
|
|
if(empty($currency_code))
|
|
$currency_code = 'USD';
|
|
|
|
// ASSIGN VARIABLES AND INCLUDE FOOTER
|
|
$smarty->assign('paymentgateways', $paymentgateways);
|
|
$smarty->assign('is_error', $is_error);
|
|
$smarty->assign('result', $result);
|
|
$smarty->assign('error_message', $error_message);
|
|
$smarty->assign('success_message', $success_message);
|
|
$smarty->assign('currency_code', $currency_code);
|
|
$smarty->assign('hide_cart', $hide_cart);
|
|
include "footer.php";
|
|
?>
|