/** * @param PaymentResponse $response * @throws Exception * @throws PaymentResponseException */ public function verifyPaymentResponse(PaymentResponse $response) { // verify digest & digest1 try { $responseParams = $response->getParams(); $this->signer->verify($responseParams, $response->getDigest()); $responseParams['MERCHANTNUMBER'] = $this->merchantNumber; $this->signer->verify($responseParams, $response->getDigest1()); } catch (SignerException $e) { throw new Exception($e->getMessage(), $e->getCode(), $e); } // verify PRCODE and SRCODE if (false !== $response->hasError()) { throw new PaymentResponseException($response->getParams()['prcode'], $response->getParams()['srcode'], "Response has an error."); } }
/** * Send the request with specified data * * @param mixed $data The data to send * @return PaymentResponse */ public function sendData($data) { $response = new PaymentResponse($this, $data); $response->setVerifier($this->getVerifier()); return $this->response = $response; }
/** * */ public function processRequest() { $dataField = \Yii::$app->request->post('Data'); $interfaceVersion = \Yii::$app->request->post('InterfaceVersion'); $seal = \Yii::$app->request->post('Seal'); // Check InterfaceVersion and validate Data-field integrity if ($dataField === null || $interfaceVersion !== $this->interfaceVersion || hash('sha256', $dataField . $this->secretKey) !== $seal) { throw new \yii\web\BadRequestHttpException(); } // Parse Data-field $data = []; $dataField = explode('|', $dataField); foreach ($dataField as $concat) { $field = explode('=', $concat, 2); if (count($field) == 2) { $data[$field[0]] = $field[1]; } } // Create the response object and make sure everything's there $paymentResponse = new PaymentResponse($data); if ($paymentResponse->validate()) { return $paymentResponse; } throw new \yii\web\BadRequestHttpException(); }
public function response() { if ($this->request->is("post")) { $this->layout = "default"; $PaymentResponse = new PaymentResponse(); $user = $this->Auth->user(); $data = $this->request->data; $result = $PaymentResponse->getResponse($data); $dataSize = sizeof($result); $course_id = $this->Session->read("courses"); $cmt = $this->Session->read("purchasemode"); $commet = $this->Session->read("sourcefrom"); $levelid = $this->Session->read("studentlevel"); $usr = $this->Session->read("user_type"); $student = $this->Student->findById($user['Student']['id']); if ($commet == "thinkvidya" || $commet == "quiz" || $commet == "free_signup" || $commet == "hindu_direct") { if ($levelid == 1) { $levels = "Junior"; } else { if ($levelid == 2) { $levels = "Seniors"; } } $data = array(); $coupon_code = $this->Session->read('coupon_code'); $sesscoupon = substr($this->Session->read('coupon_code'), 0, 4); if (stripos($coupon_code, "APC2") !== FALSE) { $commet .= ",by PromoCoupon " . $coupon_code; $code = $coupon_code; } $rawstring = "<p>Dear studentname,</p>\n <p>Welcome to AhaGuru!</p>\n <p>You have successfully registered for The Hindu AhaGuru Physics Challenge 2 - levels !</p>\n <p><b>Step 1:</b> Please go to www.ahaguru.com and login to your AhaGuru account:</p>\n <p>Your AhaGuru UserName is uname</p>\n <p>Your AhaGuru Password is upwd</p>\n <p><b>Step 2:</b> You will find 'The Hindu AhaGuru Physics Challenge 2 - levels' Course added to your 'My Courses' page. Click on it to start learning\n <p><b>Step 3:</b> Complete all the online lessons and take the written test on October 25th, 2015.</p>\n <p>Please write to us at <a href=learn@ahaguru.com>learn@ahaguru.com </a> in case of any difficulties!\n <p>All the best!</p>\n <p>AhaGuru Team</p>\n <p>www.ahaguru.com</p>"; $placeholders = array('studentname', 'uname', 'upwd', 'levels'); $string = array($user['Student']['name'], $user['Student']['email'], $student['Student']['password'], $levels); $rawstr = str_replace($placeholders, $string, $rawstring); for ($i = 0; $i < $dataSize; $i++) { $information = explode('=', $result[$i]); //if($i==3) $order_status=$information[1]; $data[$information[0]] = $information[1]; } $courses = implode(',', $course_id); if (empty($courses)) { $data['course_ids'] = $course_id; } else { $data['course_ids'] = $courses; } $data['student_id'] = $user['Student']['id']; CakeLog::write('debug', "data from ccavenue" . print_r($data, true)); if ($data['order_status'] == 'Success') { $this->Payment->save($data); if (stripos($coupon_code, "APC2") !== FALSE) { $subscription = array(); if ($student['Student']['standard'] > 4) { $std = 1; } else { $std = $student['Student']['standard']; } $con = array('StdCourseMap.course_id' => array(44, 45, 46, 47), 'StdCourseMap.standard_id' => $std); $course_subscribed = $this->StdCourseMap->find("first", array('conditions' => $con)); $studsubscrption = $this->AgPuzzlerSubscription->find("all", array('conditions' => array('AgPuzzlerSubscription.STUDENT_ID' => $student['Student']['id'], 'AgPuzzlerSubscription.COURSE_ID' => $course_subscribed['StdCourseMap']['course_id']))); CakeLog::write('debug', "subscribe? " . print_r($studsubscrption, true)); $datediff = date_diff(date_create("31-12-2015"), date_create(date("Y-m-d H:i:s"))); $datediff = $datediff->days + 1; $week = round($datediff / 7); $week = $week + 1; if (empty($studsubscrption)) { $subscription['COURSE_ID'] = $course_subscribed['StdCourseMap']['course_id']; $subscription['STUDENT_ID'] = $user['Student']['id']; $subscription['SUBSCRIPTION_PERIOD'] = $week; $subscription['SUBSCRIPTION_DATE'] = date('Y-m-d H:i:s'); $this->AgPuzzlerSubscription->save($subscription); } } foreach ($course_id as $ids) { $mapdata = array(); $con = array('StudentCourseMap.student_id' => $user['Student']['id'], 'StudentCourseMap.course_id' => $ids, 'StudentCourseMap.deleted' => 0); $crsmap = $this->StudentCourseMap->find("first", array('conditions' => $con)); CakeLog::write('debug', "crs exists? " . print_r($crsmap, true)); if (!empty($crsmap)) { $mapdata['id'] = $crsmap['StudentCourseMap']['id']; } $mapdata['student_id'] = $user['Student']['id']; $mapdata['course_id'] = $ids; $mapdata['status'] = 1; $mapdata['coupon_code'] = $code; $mapdata['payment'] = 2; $mapdata['deleted'] = 0; if ($cmt == "hindu signup") { $mapdata['challenge_type'] = "PC2"; // $mapdata['comments'] = $commet.",Hindu New Student Online_Payment"; $mapdata['comments'] = $commet . ",Hindu New Student Online_Payment"; } else { if ($cmt == "hindu login purchase") { if (!empty($crsmap)) { // $comments = $crsmap['StudentCourseMap']['comments']; // $comments .= ",Hindu Existing Student Online_Payment"; // $mapdata['comments'] = $commet.",".$comments; $comments = $crsmap['StudentCourseMap']['comments']; $comments .= ",Hindu Existing Student Online_Payment"; $mapdata['challenge_type'] = "PC2"; $mapdata['comments'] = $commet . "," . $comments; } else { $mapdata['challenge_type'] = "PC2"; $mapdata['comments'] = $commet . ",Hindu Existing Student Online_Payment"; } } else { $mapdata['comments'] = $commet . ",Online_Payment"; } } CakeLog::write('debug', "saved mapping" . print_r($mapdata, true)); $this->StudentCourseMap->saveAll($mapdata); } $this->sendEmail($user['Student']['email'], null, "Ahaguru: Registration", $rawstr, null); session_destroy(); $this->redirect("/payment_success"); // $this->redirect("/student/course"); } else { $this->Payment->save($data); if ($usr == "newuser") { $failurestud = $student['Student']; $this->HinduStudent->save($failurestud); $this->Student->delete($student['Student']['id']); } else { $failurestud = $student['Student']; $failurestud['challenge_type'] = "PC2"; $this->HinduStudent->save($failurestud); } session_destroy(); $this->redirect("/hindu"); } } else { $data = array(); for ($i = 0; $i < $dataSize; $i++) { $information = explode('=', $result[$i]); //if($i==3) $order_status=$information[1]; $data[$information[0]] = $information[1]; } $courses = implode(',', $course_id); if (empty($courses)) { $data['course_ids'] = $course_id; } else { $data['course_ids'] = $courses; } $data['student_id'] = $user['Student']['id']; CakeLog::write('debug', "data from ccavenue" . print_r($data, true)); if ($data['order_status'] == 'Success') { $this->Payment->save($data); foreach ($course_id as $ids) { $mapdata = array(); $con = array('StudentCourseMap.student_id' => $user['Student']['id'], 'StudentCourseMap.course_id' => $ids, 'StudentCourseMap.deleted' => 0); $crsmap = $this->StudentCourseMap->find("first", array('conditions' => $con)); CakeLog::write('debug', "crs exists? " . print_r($crsmap, true)); if (!empty($crsmap)) { $mapdata['id'] = $crsmap['StudentCourseMap']['id']; } $mapdata['student_id'] = $user['Student']['id']; $mapdata['course_id'] = $ids; $mapdata['status'] = 1; $mapdata['payment'] = 2; // $mapdata['challenge_type'] = "PC2"; $mapdata['deleted'] = 0; if ($cmt == "hindu signup") { $mapdata['challenge_type'] = "PC2"; $mapdata['comments'] = $commet . ",Hindu New Student Online_Payment"; } else { if ($cmt == "hindu login purchase") { if (!empty($crsmap)) { $comments = $crsmap['StudentCourseMap']['comments']; $comments .= ",Hindu Existing Student Online_Payment"; $mapdata['challenge_type'] = "PC2"; $mapdata['comments'] = $commet . "," . $comments; } else { $mapdata['challenge_type'] = "PC2"; $mapdata['comments'] = $commet . ",Hindu Existing Student Online_Payment"; } } else { $mapdata['comments'] = $commet . ",Online_Payment"; } } CakeLog::write('debug', "saved mapping" . print_r($mapdata, true)); $this->StudentCourseMap->saveAll($mapdata); } $this->redirect("/student/course"); } else { $this->Payment->save($data); $this->redirect("/student/course"); } } } }
/** * This method is called when the customer goes back to shop, after he made a payment. * The customer will redirected either to the order confirmation page or to an error page * @return mixed */ public function postProcess() { require_once dirname(__FILE__) . '/../../api/loader.php'; $alipay = new Alipay(); $payment_response = new PaymentResponse(); $payment_response->getPostData(); if ($payment_response->getTradeStatus() == 'TRADE_FINISHED') { $payment_response->setIdModule($this->module->id); if (!$payment_response->processResponse()) { $errors = $payment_response->getErrors(); if ($errors) { foreach ($errors as $error) { $this->errors[] = $error; } return $this->setTemplate('error.tpl'); } } if ($payment_response->getIdOrder()) { $params = array('id_cart' => $payment_response->getIdCart(), 'id_module' => $payment_response->getIdModule(), 'id_order' => $payment_response->getIdOrder(), 'key' => $payment_response->getSecureKey()); $s = $this->context->link->getModuleLink('alipay', 'confirmation', $params); Tools::redirect($s); } else { $this->context->smarty->assign($payment_response->getTplVars()); return $this->setTemplate('check_order.tpl'); } } $this->errors[] = $alipay->l('An error occured. Please contact the merchant to have more informations'); return $this->setTemplate('error.tpl'); }
public function __construct($invoice) { parent::__construct($invoice, self::VALUE_OK); }
/** * @dataProvider errorCodesProvider */ public function testHasError($codes, $result) { $response = new PaymentResponse('operation', 'ordernumber', 'merordernum', $codes['prcode'], $codes['srcode'], 'resultext', 'digest', 'digest1'); $this->assertEquals($result, $response->hasError()); }
public function __construct($invoice) { parent::__construct($invoice, self::VALUE_MISSING_PAYMENT); }