This commit is contained in:
Alan
2026-02-14 19:34:54 +03:00
commit 5c3329238b
867 changed files with 214778 additions and 0 deletions

84
payment/Paypal/Paypal.php Normal file
View File

@@ -0,0 +1,84 @@
<?php
/**
* Simpla CMS
*
* @copyright 2011 Denis Pikusov
* @link http://simplacms.ru
* @author Denis Pikusov
*
* Paypal checkout button
*
*/
require_once('api/Simpla.php');
class Paypal extends Simpla
{
public function checkout_form($order_id, $button_text = null)
{
if(empty($button_text))
$button_text = 'Checkout with Paypal';
$order = $this->orders->get_order((int)$order_id);
$purchases = $this->orders->get_purchases(array('order_id'=>intval($order->id)));
$payment_method = $this->payment->get_payment_method($order->payment_method_id);
$currency = $this->money->get_currency(intval($payment_method->currency_id));
$payment_settings = $this->payment->get_payment_settings($payment_method->id);
if($payment_settings['mode'] == 'sandbox') $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
else $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
$ipn_url = $this->config->root_url.'/payment/Paypal/callback.php';
$success_url = $this->config->root_url.'/order/'.$order->url;
$fail_url = $this->config->root_url.'/order/'.$order->url;
$button = "<form method='post' action= '".$paypal_url."'>
<input type='hidden' name='charset' value='utf-8'>
<input type='hidden' name='currency_code' value='".$currency->code."'>
<input type='hidden' name='invoice' value='".$order->id."'>
<input type='hidden' name='business' value='".$payment_settings['business']."'>
<input type='hidden' name='cmd' value='_cart'>
<input type='hidden' name='upload' value='1'>
<input type='hidden' name='rm' value='2'>
<input type='hidden' name='notify_url' value='$ipn_url'>
<input type='hidden' name='return' value='$success_url'>
<input type='hidden' name='cancel_return' value='$fail_url'>
";
if($order->discount>0)
$button .= "<input type='hidden' name='discount_rate_cart' value='".$order->discount."'>";
if($order->coupon_discount>0)
{
$coupon_discount = $this->money->convert($order->coupon_discount, $payment_method->currency_id, false);
$button .= "<input type='hidden' name='discount_amount_cart' value='".$coupon_discount."'>";
}
$i = 1;
foreach($purchases as $purchase)
{
$price = $this->money->convert($purchase->price, $payment_method->currency_id, false);
$price = number_format($price, 2, '.', '');
$button .= "<input type='hidden' name='item_name_".$i."' value='".$purchase->product_name.' '.$purchase->variant_name."'>
<input type='hidden' name='amount_".$i."' value='".$price."'>
<input type='hidden' name='quantity_".$i."' value='".$purchase->amount."'>";
$i++;
}
$delivery_price = 0;
if($order->delivery_id && !$order->separate_delivery && $order->delivery_price>0)
{
$delivery_price = $this->money->convert($order->delivery_price, $payment_method->currency_id, false);
$delivery_price = number_format($delivery_price, 2, '.', '');
$button .= "<input type='hidden' name='shipping_1' value='".$delivery_price."'>";
}
$button .= "<input type='image' src='https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif' value='".$button_text."'>
</form>";
return $button;
}
}

112
payment/Paypal/callback.php Normal file
View File

@@ -0,0 +1,112 @@
<?php
/**
* Simpla CMS
*
* @copyright 2011 Denis Pikusov
* @link http://simplacms.ru
* @author Denis Pikusov
*
* IPN Script for Paypal
*
*/
// Working in root dir
chdir ('../../');
// Including simpla API
require_once('api/Simpla.php');
$simpla = new Simpla();
// Get the order
$order = $simpla->orders->get_order(intval($simpla->request->post('invoice')));
if(empty($order))
die('Order not found');
// Get payment method from this order
$method = $simpla->payment->get_payment_method(intval($order->payment_method_id));
if(empty($method))
die("Unknown payment method");
// Payment method settings
$settings = unserialize($method->settings);
if($settings['mode'] == 'sandbox') $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
else $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
// Verify transaction
$postdata = "";
foreach ($_POST as $key=>$value) $postdata.=$key."=".urlencode($value)."&";
$postdata .= "cmd=_notify-validate";
$curl = curl_init($paypal_url);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec($curl);
curl_close ($curl);
if ($response != "VERIFIED")
die("Could not verify transaction");
// Check payment status
if($_POST["payment_status"] != "Completed" )
die('Incorrect status '.$_POST["payment_status"].$_POST["pending_reason"]);
// Verify merchant email
if ($simpla->request->post('receiver_email') != $settings['business'])
die("Incorrect merchant email");
// Verify transaction type
if ($simpla->request->post('txn_type') != 'cart')
die("Incorrect txn_type");
// Is order already paid
if($order->paid)
die('Duplicate payment');
////////////////////////////////////
// Verify total payment amount
////////////////////////////////////
$total_price = 0;
// Get order purchases
$purchases = $simpla->orders->get_purchases(array('order_id'=>intval($order->id)));
foreach($purchases as $purchase)
{
$price = $simpla->money->convert($purchase->price, $method->currency_id, false);
$price = round($price, 2);
$total_price += $price*$purchase->amount;
}
// Substract the discount
if($order->discount)
{
$total_price *= (100-$order->discount)/100;
$total_price = round($total_price, 2);
}
// Adding delivery price
if($order->delivery_id && !$order->separate_delivery && $order->delivery_price>0)
{
$delivery_price = $simpla->money->convert($order->delivery_price, $payment_method->currency_id, false);
$delivery_price =round($delivery_price, 2);
$total_price += $delivery_price;
}
if($total_price != $simpla->request->post('mc_gross'))
die("Incorrect total price (".$total_price."!=".$simpla->request->post('mc_gross').")");
// Set order status paid
$simpla->orders->update_order(intval($order->id), array('paid'=>1));
// Write off products
$simpla->orders->close(intval($order->id));
$simpla->notify->email_order_user(intval($order->id));
$simpla->notify->email_order_admin(intval($order->id));
function logg($str)
{
file_put_contents('payment/Paypal/log.txt', file_get_contents('payment/Paypal/log.txt')."\r\n".date("m.d.Y H:i:s").' '.$str);
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module>
<name>
Paypal
</name>
<settings>
<variable>business</variable>
<name>Merchant email</name>
</settings>
<settings>
<variable>mode</variable>
<name>Mode</name>
<options>
<name>Real payments</name>
<value>real</value>
</options>
<options>
<name>Sandbox mode</name>
<value>sandbox</value>
</options>
</settings>
</module>