1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @title Payment Design |
4
|
|
|
* |
5
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
6
|
|
|
* @copyright (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved. |
7
|
|
|
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
8
|
|
|
* @package PH7 / App / System / Module / Payment / Inc / Class / Design |
9
|
|
|
*/ |
10
|
|
|
namespace PH7; |
11
|
|
|
|
12
|
|
|
use PH7\Framework\Payment\Gateway\Api\Api as PaymentApi; |
13
|
|
|
use PH7\Framework\Mvc\Router\Uri; |
14
|
|
|
use stdClass; |
15
|
|
|
|
16
|
|
|
class PaymentDesign extends Framework\Core\Core |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param stdClass $oMembership |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function buttonPayPal(stdClass $oMembership) |
24
|
|
|
{ |
25
|
|
|
$oPayPal = new PayPal($this->config->values['module.setting']['sandbox.enabled']); |
26
|
|
|
|
27
|
|
|
$oPayPal->param('business', $this->config->values['module.setting']['paypal.email']) |
28
|
|
|
->param('custom', base64_encode($oMembership->groupId . '|' . $oMembership->price)) // Use base64_encode() to discourage curious people |
29
|
|
|
->param('amount', $oMembership->price) |
30
|
|
|
->param('item_number', $oMembership->groupId) |
31
|
|
|
->param('item_name', $this->registry->site_name . ' ' . $oMembership->name) |
32
|
|
|
->param('no_note', 1) |
33
|
|
|
->param('no_shipping', 1) |
34
|
|
|
->param('currency_code', $this->config->values['module.setting']['currency']) |
35
|
|
|
->param('tax_cart', $this->config->values['module.setting']['vat_rate']) |
36
|
|
|
->param('return', Uri::get('payment', 'main', 'process', 'paypal')) |
37
|
|
|
->param('rm', 2) // Auto redirection in POST data |
38
|
|
|
->param('notify_url', Uri::get('payment', 'main', 'notification', 'PayPal,' . $oMembership->groupId)) |
39
|
|
|
->param('cancel_return', Uri::get('payment', 'main', 'membership', '?msg=' . t('The payment was aborted. No charge has been taken from your account.'), false)); |
40
|
|
|
|
41
|
|
|
echo static::displayGatewayForm($oPayPal, $oMembership->name, 'PayPal'); |
42
|
|
|
|
43
|
|
|
unset($oPayPal, $oMembership); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Generates Stripe Payment form thanks the Stripe API. |
48
|
|
|
* |
49
|
|
|
* @param stdClass $oMembership |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function buttonStripe(stdClass $oMembership) |
54
|
|
|
{ |
55
|
|
|
$oStripe = new Stripe; |
56
|
|
|
|
57
|
|
|
$oStripe->param('item_number', $oMembership->groupId) |
58
|
|
|
->param('amount', $oMembership->price); |
59
|
|
|
|
60
|
|
|
echo |
61
|
|
|
'<form action="', $oStripe->getUrl(), '" method="post">', |
62
|
|
|
$oStripe->generate(), |
63
|
|
|
'<script |
64
|
|
|
src="https://checkout.stripe.com/checkout.js" class="stripe-button" |
65
|
|
|
data-key="', $this->config->values['module.setting']['stripe.publishable_key'], '" |
66
|
|
|
data-name="', $this->registry->site_name, '" |
67
|
|
|
data-description="', $oMembership->name, '" |
68
|
|
|
data-amount="', Stripe::getAmount($oMembership->price), '" |
69
|
|
|
data-currency="', $this->config->values['module.setting']['currency'], '" |
70
|
|
|
data-allow-remember-me="true" |
71
|
|
|
data-bitcoin="true"> |
72
|
|
|
</script> |
73
|
|
|
</form>'; |
74
|
|
|
|
75
|
|
|
unset($oStripe); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param stdClass $oMembership |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function button2CheckOut(stdClass $oMembership) |
84
|
|
|
{ |
85
|
|
|
$o2CO = new TwoCO($this->config->values['module.setting']['sandbox.enabled']); |
86
|
|
|
|
87
|
|
|
$o2CO->param('sid', $this->config->values['module.setting']['2co.vendor_id']) |
88
|
|
|
->param('id_type', 1) |
89
|
|
|
->param('cart_order_id', $oMembership->groupId) |
90
|
|
|
->param('merchant_order_id', $oMembership->groupId) |
91
|
|
|
->param('c_prod', $oMembership->groupId) |
92
|
|
|
->param('c_price', $oMembership->price) |
93
|
|
|
->param('total', $oMembership->price) |
94
|
|
|
->param('c_name', $this->registry->site_name . ' ' . $oMembership->name) |
95
|
|
|
->param('tco_currency', $this->config->values['module.setting']['currency']) |
96
|
|
|
->param('c_tangible', 'N') |
97
|
|
|
->param('x_receipt_link_url', Uri::get('payment', 'main', 'process', '2co')); |
98
|
|
|
|
99
|
|
|
echo static::displayGatewayForm($o2CO, $oMembership->name, '2CO'); |
100
|
|
|
|
101
|
|
|
unset($o2CO); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param stdClass $oMembership |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function buttonCCBill(stdClass $oMembership) |
110
|
|
|
{ |
111
|
|
|
// Not implemented yet. |
112
|
|
|
// Feel free to contribute on our open source repo: https://github.com/pH7Software/pH7-Social-Dating-CMS |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param PaymentApi $oPaymentProvider |
117
|
|
|
* @param string $sMembershipName |
118
|
|
|
* @param string $sProviderName |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
protected function displayGatewayForm(PaymentApi $oPaymentProvider, $sMembershipName, $sProviderName) |
123
|
|
|
{ |
124
|
|
|
echo '<form action="', $oPaymentProvider->getUrl(), '" method="post">', |
125
|
|
|
$oPaymentProvider->generate(), |
126
|
|
|
'<button class="btn btn-primary btn-md" type="submit" name="submit">', static::buyTxt($sMembershipName, $sProviderName), '</button> |
|
|
|
|
127
|
|
|
</form>'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Build a "buy message". |
132
|
|
|
* |
133
|
|
|
* @param string $sMembershipName Membership name (e.g., Platinum, Silver, ...). |
134
|
|
|
* @param string $sProviderName Provider name (e.g., PayPal, 2CO, ...). |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
private static function buyTxt($sMembershipName, $sProviderName) |
139
|
|
|
{ |
140
|
|
|
return t('Buy %0% with %1%!', $sMembershipName, '<b>' . $sProviderName . '</b>'); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: