-
Notifications
You must be signed in to change notification settings - Fork 1
/
SiteController.php
86 lines (63 loc) · 2.4 KB
/
SiteController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @package ImpressPages
*/
namespace Plugin\PayPalSubscription;
class SiteController extends \Ip\Controller
{
public function subscribe($paymentId, $securityCode)
{
if (PayPalModel::instance()->isInSkipMode()) {
PayPalModel::instance()->markAsPaid($paymentId);
$response = PayPalModel::instance()->successStatusPage($paymentId, $securityCode);
return $response;
}
$payment = Model::getPayment($paymentId);
if (!$payment) {
throw new \Ip\Exception('Order ' . $paymentId . ' doesn\'t exist');
}
if ($payment['securityCode'] != $securityCode) {
throw new \Ip\Exception('Payment security code is incorrect. Order Id '. $paymentId . '. SecurityCode ' . $securityCode);
}
if (!$payment['userId']) {
if (!ipUser()->loggedIn()) {
$_SESSION['User_redirectAfterLogin'] = ipRequest()->getUrl();
return new \Ip\Response\Redirect(ipRouteUrl('User_login'));
}
Model::update($paymentId, array('userId' => ipUser()->userId()));
}
$paypalModel = PayPalModel::instance();
$data = array(
'form' => $paypalModel->getPaypalForm($paymentId)
);
$answer = ipView('view/page/paymentRedirect.php', $data)->render();
return $answer;
}
public function cancel($subscriptionId, $securityCode)
{
$subscription = Model::getPayment($subscriptionId);
if (!$subscription) {
throw new \Ip\Exception("Unknown subscription");
}
$data = array (
'subscriptionTitle' => $subscription['title']
);
return ipView('view/page/cancelInstructions.php', $data);
}
public function status($paymentId, $securityCode)
{
$payment = Model::getPayment($paymentId);
if (!$payment) {
throw new \Ip\Exception('Unknown order. Id: ' . $paymentId);
}
if ($payment['securityCode'] != $securityCode) {
throw new \Ip\Exception('Incorrect order security code');
}
$data = array(
'payment' => $payment,
'paymentUrl' => ipRouteUrl('PayPalSubscription_pay', array('paymentId' => $payment['id'], 'securityCode' => $payment['securityCode']))
);
$view = ipView('view/page/status.php', $data);
return $view;
}
}