-
Notifications
You must be signed in to change notification settings - Fork 1
/
Model.php
83 lines (64 loc) · 2.09 KB
/
Model.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
<?php
/**
* @package ImpressPages
*/
namespace Plugin\PayPalSubscription;
class Model
{
public static function createPayment($paymentData, $userId = null)
{
if ($userId == null) {
$userId = ipUser()->userId();
}
$data = array(
'item' => $paymentData['item'],
'cancelUrl' => empty($paymentData['cancelUrl']) ? '' : $paymentData['cancelUrl'],
'successUrl' => empty($paymentData['successUrl']) ? '' : $paymentData['successUrl'],
'currency' => $paymentData['currency'],
'userId' => $userId,
'securityCode' => self::randomString(32),
'createdAt' => date('Y-m-d H:i:s')
);
switch($paymentData['periodType']) {
case 'day':
$data['t3'] = 'D';
break;
case 'week':
$data['t3'] = 'W';
break;
case 'month':
$data['t3'] = 'M';
break;
case 'year':
$data['t3'] = 'Y';
break;
}
$data['p3'] = $paymentData['period'];
$data['a3'] = $paymentData['amount'];
if (!empty($paymentData['title'])) {
$data['title'] = $paymentData['title'];
} else {
$data['title'] = $data['item'];
}
$orderId = ipDb()->insert('paypal_subscription', $data);
return $orderId;
}
public static function getPayment($orderId)
{
$order = ipDb()->selectRow('paypal_subscription', '*', array('id' => $orderId));
return $order;
}
public static function update($orderId, $data)
{
ipDb()->update('paypal_subscription', $data, array('id' => $orderId));
}
protected static function randomString($length)
{
return substr(sha1(rand()), 0, $length);
}
public static function getActiveSubscription($item, $userId)
{
$subscription = ipDb()->selectRow('paypal_subscription', '*', array('item' => $item, 'userId' => $userId, 'isActive' => 1));
return $subscription;
}
}