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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php
class PaymentRecord extends BaseModel { protected $table = "payment_record";
public function order() { return $this->belongsTo('Order'); }
public function invoice() { return $this->belongsTo('Invoice'); }
public function paymentRefunds() { return $this->hasMany('PaymentRefund', 'code', 'v_oid'); }
public function payable() { return $this->morphTo(); }
public function confirm($api) { if ($this->status == "") { // process refund } $this->sendEmailSupplier(); $this->sendEmailCustomer(); }
// protected function excute() // { // if ($this->payment) {
// // different api call based on payment type // switch ($payment['type']) { // case 'TRUSTPAY': // $this->excuteTrustpay(); // require_once "../trustpay/ebusclient/PaymentRequest.php"; // // TrustPay settings // // putenv('ABCMerchantIniFile=' . $master_settings['ABC_MERCHANT_FOLDER'] . '/TrustMerchant.ini'); // putenv('ABCMerchantIniFile=E:\\htdocs\\b2b2c\\protected\\TrustMerchant.ini' ); // # code... // break;
// case 'PAYEASE_DOKU': // $this->excutePayeaseDoku(); // break;
// case 'PAYEASE': // default: // $this->excutePayease(); // break; // }
// $paymentRecord = PaymentRecord::createbyate([ // 'refund_id' => $id, // 'code' => $code, // 'status' => $status, // 'amount' => $amount, // 'v_mid' => $v_mid, // 'v_oid' => $v_oid, // 'v_refoprt' => $v_refoprt, // 'name_em' => $name_em, // 'desc_en' => $desc_en, // ]); // } // }
// protected function excutePayease() // { // // vdump($payment['code'], $refund_amount, "Refund", $master_settings['PAYEASE_REFOPRT']); exit; // $payease = new PayEase(); // // TODO: change to Platform's v_refoprt // $result = $payease->ref_ack_submit($payment['code'], $refund_amount, "Refund", MasterSetting::get('PAYEASE_REFOPRT')); // $json_result = json_encode($result); // $result = json_decode($json_result); // }
// protected function excutePayeaseDoku() // { // # code... // }
// protected function excuteTrustpay() // { // # code... // }
protected function sendEmailCustomer() {
global $site_info; global $langcode;
$customer_info = $this->order->customer->decrypt();
$x_mail = new PHPMailer(); // default values $x_mail->IsSMTP(); $x_mail->IsHTML(true); // $x_mail->SMTPDebug = 1; // $x_mail->SMTPDebug = true; $x_mail->Host = MasterSetting::get('SMTP_HOST') ?: $x_mail->Host; $x_mail->Port = MasterSetting::get('SMTP_PORT') ?: $x_mail->Port; $x_mail->SMTPAuth = MasterSetting::get('SMTP_SMTPAUTH') ? true : false; $x_mail->Username = MasterSetting::get('SMTP_USERNAME'); $x_mail->Password = MasterSetting::get('SMTP_PASSWORD'); $x_mail->SMTPSecure = MasterSetting::get('SMTP_SMTPSECURE') ?: $x_mail->SMTPSecure; $x_mail->CharSet = "UTF-8"; $x_mail->WordWrap = 50; $x_mail->Sender = MasterSetting::get('PLATFORM_ORDER_EMAIL'); $x_mail->From = MasterSetting::get('PLATFORM_ORDER_EMAIL'); $x_mail->FromName = $site_info{"companyname_" . $langcode}; $x_mail->Subject = $site_info{"companyname_" . $langcode} . " " . $this->code; $x_mail->AddAddress($customer_info->email, $customer_info->fullname());
ob_start(); require __DIR__ . '/../resources/refund_customer.php'; $x_mail->Body = ob_get_contents(); ob_end_clean();
// echo $x_mail->Body;
if ($x_mail->Send()) { $this->sendEmailCustomer = 1; $send_result = lang("We have received your order. Your order will process as soon as possible. <br><br> You can get your order detail in your email account."); } else { // vdump($x_mail->ErrorInfo); $this->sendEmailCustomer = 0; $send_result = lang("We have received your order. Your order will process as soon as possible. <br><br> Email cannot send to you."); }
$this->save(); return $send_result; }
protected function sendEmailSupplier() {
global $site_info; global $langcode;
$supplier_info = $this->supplierOrder->supplier; if (empty($supplier_info["receive_order_email"])) { return; }
$supplier_email_langcode = $supplier_info["email_langcode"];
// get item info in supplier language
$x_mail = new PHPMailer(); // default values $x_mail->IsSMTP(); $x_mail->IsHTML(true); // $x_mail->SMTPDebug = 1; // $x_mail->SMTPDebug = true; $x_mail->Host = MasterSetting::get('SMTP_HOST') ?: $x_mail->Host; $x_mail->Port = MasterSetting::get('SMTP_PORT') ?: $x_mail->Port; $x_mail->SMTPAuth = MasterSetting::get('SMTP_SMTPAUTH') ? true : false; $x_mail->Username = MasterSetting::get('SMTP_USERNAME'); $x_mail->Password = MasterSetting::get('SMTP_PASSWORD'); $x_mail->SMTPSecure = MasterSetting::get('SMTP_SMTPSECURE') ?: $x_mail->SMTPSecure; $x_mail->CharSet = "UTF-8"; $x_mail->WordWrap = 50; $x_mail->Sender = MasterSetting::get('PLATFORM_ORDER_EMAIL'); $x_mail->From = MasterSetting::get('PLATFORM_ORDER_EMAIL'); $x_mail->FromName = $site_info{"companyname_" . $langcode}; $x_mail->Subject = $site_info{"companyname_" . $langcode} . " " . $this->code; $x_mail->AddAddress($customer_info->email, $customer_info->fullname());
ob_start(); require __DIR__ . '/../resources/refund_supplier.php'; $x_mail->Body = ob_get_contents(); ob_end_clean();
// echo $x_mail->Body;
if ($x_mail->Send()) { $this->sendEmailSupplier = 1; }
$this->save(); } }
|