diff --git a/src/Merchant.php b/src/Merchant.php new file mode 100644 index 0000000..92e707b --- /dev/null +++ b/src/Merchant.php @@ -0,0 +1,130 @@ + 'interkassa', + 'label' => 'InterKassa', + 'actionUrl' => 'https://sci.interkassa.com/', + 'confirmText' => 'OK', + ]; + + public function isNewVersion() + { + return !strpos($this->purse, '-'); + } + + public function getPaymentNo() + { + return $this->username . '_' . $this->cents . '_' . $this->uniqId; + } + + public function getPaymentId() + { + return (strpos($this->username,'@') === false ? $this->username : substr($this->username, 0, strpos($this->username)+1)) .'_'. $this->uniqId, + } + + public function getBaggageFields() + { + return $this->currency . ' ' . $this->username; + } + + public function getInputs() + { + return $this->isNewVersion() ? [ + 'ik_co_id' => strtolower($this->purse), + 'ik_am' => $this->total, + 'ik_pm_no' => $this->paymentNo, + 'ik_desc' => $this->description, + 'ik_cur' => $this->currency, + 'ik_pnd_u' => $this->confirmUrl, + 'ik_suc_u' => $this->successUrl, + 'ik_fal_u' => $this->failureUrl, + 'ik_pnd_m' => 'POST', + 'ik_suc_m' => 'POST', + 'ik_fal_m' => 'POST', + ] : [ + 'ik_shop_id' => $this->purse, + 'ik_payment_amount' => $this->total, + 'ik_payment_id' => $this->paymentId, + 'ik_payment_desc' => $this->description, + 'ik_baggage_fields' => $this->baggageFields, + 'ik_status_url' => $this->confirmUrl, + 'ik_success_url' => $this->successUrl, + 'ik_fail_url' => $this->failureUrl, + 'ik_success_method' => 'POST', + 'ik_fail_method' => 'POST', + 'ik_status_method' => 'POST', + ]; + } + + public function validateConfirmation($data) + { + return $this->isNewVersion() + ? $this->validateNewVersion($data) + : $this->validateOldVersion($data) + ; + } + + public function validateNewVersion($data) + { + $iks = $data; + if ($data['ik_co_id'] != $this->purse) { + return 'Wrong purse'; + } + if ($data['ik_inv_st'] != 'success') { + return 'Wrong state'; + } + unset($iks['ik_sign']); + foreach ($iks as $k=>$v) if (substr($k,0,3)!='ik_') unset($iks[$k]); + array_push($iks, $this->secret); + ksort($iks, SORT_STRING); + $hash = base64_encode(md5(implode(':',$iks), true)); + if ($hash != strtolower($data['ik_sign'])) { + return 'Wrong hash'; + } + $this->mset([ + 'from' => $data['ik_pm_no'], + 'txn' => $data['ik_trn_id '], + 'sum' => $data['ik_am'], + 'time' => $this->formatDatetime($data['ik_inv_prc']), + ]); + return null; + } + + public function validateOldVersion($data) + { + $iks = $data; + if ($data['ik_shop_id'] != $this->purse) { + return 'Wrong purse'; + } + if ($data['ik_payment_state'] != 'success') { + return 'Wrong state'; + } + unset($iks['ik_sign_hash'], $iks['ik_payment_desc'], $iks['ik_payment_timestamp']); + foreach ($iks as $k=>$v) if (substr($k,0,3)!='ik_') unset($iks[$k]); + array_push($iks, $this->secret); + $hash = md5(implode(':', $iks)); + if ($hash != strtolower($data['ik_sign_hash'])) { + return 'Wrong hash'; + } + $this->mset(array( + 'from' => $data['ik_payment_id'], + 'txn' => $data['ik_trans_id'], + 'sum' => $data['ik_payment_amount'], + 'time' => $this->formatDatetime($data['ik_payment_timestamp']), + )); + return null; + } +} diff --git a/src/assets/logo.png b/src/assets/logo.png new file mode 100644 index 0000000..a4e13c9 Binary files /dev/null and b/src/assets/logo.png differ diff --git a/src/assets/style.css b/src/assets/style.css new file mode 100644 index 0000000..6a17950 --- /dev/null +++ b/src/assets/style.css @@ -0,0 +1,3 @@ +.merchant-interkassa-bg { + background: url(logo.png) no-repeat right; +}