/var/www/vhosts/nabawater/frontend/controllers
Edit: /var/www/vhosts/nabawater/frontend/controllers/PaymentController.php (33114B)
getUniqueId(), ['payment/mobile-success','payment/mobile-failure', 'payment/success','payment/failure'])) {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
/**
* @return string
* @throws \yii\base\InvalidParamException
* @throws NotFoundHttpException
* @throws \Exception
* @throws \Throwable
* @throws \yii\db\StaleObjectException
*/
public function actionIndex()
{
$request = Yii::$app->getRequest()->get();
if($request['type'] == 1) {
return $this->orderPayment($request['request_key']);
} else if($request['type'] == 2) {
return $this->promotionPayment($request['request_key']);
} else if($request['type'] == 3) {
return $this->TopupPayment($request['request_key']);
}
}
public function actionOrderPayment($id)
{
$params['order_id'] = $id;
return $this->renderPartial('card_details',['params' => $params]);
// $result = ['status' => 422 , 'msg' => 'Bad request'];
// $order = Order::findOne(['order_key' => yii::$app->request->get('id')]);
// if($order == null){
// $result['msg'] = 'Invalid order';
// goto skip;
// }
// if($order->payment_status == Order::PAYMENT_STATUS_SUCCESS){
// $result['msg'] = 'Payment already done';
// goto skip;
// }
// return PaymentHelper::processPayment($order);
// skip:
// Com::failureFlash($result['msg']);
// return $this->goHome();
}
public function actionPaymentDedection()
{
$result = ['status' => 422 , 'msg' => 'Bad request'];
$order = Order::findOne(['order_key' => yii::$app->request->post('order_id')]);
if($order == null){
$result['msg'] = 'Invalid order';
goto skip;
}
// if($order->payment_status == Order::PAYMENT_STATUS_SUCCESS){
// $result['msg'] = 'Payment already done';
// goto skip;
// }
$_POST['amount']=$order->order_total;
$paymentResult = StripeHelper::stripePayment($_POST);
//print_r($paymentResult); die;
if(isset($paymentResult['paymentResponse'])){
$order->payment_response = json_encode($paymentResult['paymentResponse']);
$order->transaction_id = isset($paymentResult['paymentResponse']['id'])?$paymentResult['paymentResponse']['id']:"";
}
// print_r($_POST);die;
$result['msg'] = 'Payment failure';
if($paymentResult['status'] == 200) {
$result['msg'] = 'Payment Success';
$result['status'] = 200;
$order->payment_status = Order::PAYMENT_STATUS_SUCCESS;
$order->order_status = Order::ORDER_STATUS_PENDING;
if($order->save(false)){
$userWebToken = User::find()
->select('device_token')
->where(['user_id' => $order->user_id])
->andWhere(['not', ['device_token' => null]])
->one();
if ($userWebToken != null ) {
$token = trim($userWebToken->device_token);
try {
$oneSignal = OneSignal::getInstance();
$oneSignal->setAppId(Configuration::get(Configuration::PUSH_NOTIFICATION_APP_ID));
$oneSignal->setRestApiKey(Configuration::get(Configuration::PUSH_NOTIFICATION_REST_API_KEY));
$oneSignal->setIcon('http://poc1.duceapps.com:4005/frontend/web/theme/images/notification.png');
$oneSignal->push(
['en' => 'Order status'],
['en' => 'Order Placed Successfully.'],
[$token],
['status' => 'Message Sent Successfully']
);
} catch (Exception $e) {
echo $e->getMessage();
}
}
$modelVendor = Vendor::find()
->where(['vendor_id' => $order->vendor_id])
->one();
if ($modelVendor->device_token != null ) {
$token = trim($modelVendor->device_token);
try {
$oneSignal = OneSignal::getInstance();
$oneSignal->setAppId(Configuration::get(Configuration::VENDOR_ONESIGNAL_APP_ID));
$oneSignal->setRestApiKey(Configuration::get(Configuration::VENDOR_PUSH_NOTIFICATION_REST_API_KEY));
$oneSignal->setIcon('http://poc1.duceapps.com:4005/frontend/web/theme/images/notification.png');
$oneSignal->vendorpush(
['en' => 'Order status'],
['en' => 'You Have New Order..'],
[$token],
['status' => 'Message Sent Successfully']
);
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
}
skip:
if(!yii::$app->request->get('type') == 'mobile'){
if($paymentResult['status'] == 200){
return $this->redirect(Url::to(['/branch/order-confirmation','order_key'=>$order->order_key]));
}else{
Com::failureFlash($result['msg']);
return $this->redirect(['branch/checkout']);
}
}else{
if($paymentResult['status'] == 200){
return $this->asJson(['status' => 200, 'msg' => 'Payment Success']);
}else{
Com::failureFlash($result['msg']);
return $this->asJson(['status' => 417, 'msg' => 'Payment Failure']);
}
// return $this->asJson($result);
}
die;
}
public function actionSuccess()
{
$request = Yii::$app->request->post();
$order = Order::findOne(['order_key' => yii::$app->request->get('id')]);
$paymentResult = PaymentHelper::checkValidPayment($request);
if(isset($paymentResult['status'])){
$order->payment_response = json_encode($request);
}
$result['msg'] = 'Payment failure';
if(isset($paymentResult['status']) && $paymentResult['status'] == 200) {
$result['msg'] = 'Payment Success';
$result['status'] = 200;
$order->payment_status = Order::PAYMENT_STATUS_SUCCESS;
$order->order_status = Order::ORDER_STATUS_PENDING;
$order->order_date_time = date('Y-m-d H:i:s');
$order->save(false);
$this->sendMailNotification($order->order_key);
} else {
$order->save(false);
$result['msg'] = 'Payment Failure';
goto skip;
}
skip:
if(isset($result['status']) && $result['status'] == 200){
Com::setSession(Com::SES_CART,'');
Com::setSession(Com::SES_CHECKOUT, '');
Com::setSession(Com::ITEM_COUNT, '');
return $this->redirect(Url::to(['/branch/order-confirmation']));
}else{
Com::failureFlash($result['msg']);
return $this->goHome();
}
die;
}
public function actionMobileSuccess()
{
$request = Yii::$app->request->post();
$paymentResult = PaymentHelper::checkValidPayment($request);
$order = Order::findOne(['order_key' => yii::$app->request->get('id')]);
if(isset($paymentResult['status'])){
$order->payment_response = json_encode($request);
}
$result['msg'] = 'Payment failure';
if(isset($paymentResult['status']) && $paymentResult['status'] == 200) {
$result['msg'] = 'Payment Success';
$result['status'] = 200;
$result['order_key'] = $order->order_key;
$result['order_number'] = $order->order_number;
$order->payment_status = Order::PAYMENT_STATUS_SUCCESS;
$order->order_status = Order::ORDER_STATUS_PENDING;
$order->order_date_time = date('Y-m-d H:i:s');
$order->save(false);
$this->sendMailNotification($order->order_key);
} else {
$order->save(false);
$result['msg'] = 'Payment Failure';
goto skip;
}
skip:
return $this->asJson($result);
die;
}
public function actionFailure()
{
$request = Yii::$app->request->post();
$paymentResult = PaymentHelper::checkValidPayment($request);
$order = Order::findOne(['order_key' => yii::$app->request->get('id')]);
if(isset($paymentResult['status'])){
$order->payment_response = json_encode($request);
}
$result['msg'] = 'Payment failure';
$result['status'] = 400;
Com::failureFlash($result['msg']);
return $this->redirect(['branch/checkout']);
die;
}
public function actionMobileFailure()
{
$request = Yii::$app->request->post();
$paymentResult = PaymentHelper::checkValidPayment($request);
$order = Order::findOne(['order_key' => yii::$app->request->get('id')]);
$result['msg'] = 'Payment failure';
$result['status'] = 400;
return $this->asJson($result);
}
public function actionTransfer()
{
PaymentHelper::stripTransfer(\Yii::$app->request->get('order_id'));
return;
}
private function sendMailNotification($order_key)
{
$modelOrder = Order::find()
->select([
'order_id',
'vendor_id',
'branch_id',
'payment_option',
'delivery_option',
'order_type',
'order_number',
'user_id',
'vat',
'vat_cgst',
'vat_sgst',
'vat_igst',
'vat_percent',
'service_tax',
'service_tax_percent',
'item_total',
'delivery_fee',
'package_price',
'delivery_boy_tip',
'coupon_offer_value',
'order_total',
'order_date_time',
'pickup_delivery_date_time'
])
->orderBy(['order_id' => SORT_DESC])
->where(['order_key' => $order_key])
->one();
$modelUser = User::findOne(['user_id' =>$modelOrder->user_id]);
$user_token = Yii::$app->getUser()->getIdentity();
$token = isset($user_token['auth_key']) ? $user_token['auth_key'] : "";
$orderData = ApiHelper::getInstance()
->setRequestMethod(ApiHelper::REQUEST_METHOD_GET)
->setUrl('order/details-new',['order_key'=> $order_key]);
$apiResponse = $orderData->run();
if(!$apiResponse->isSuccess())
{
$message = $apiResponse->getMessage();
$response['status'] = false;
$response['message'] = $message;
Com::failureFlash($message);
}
$results = [];
$ingResult = [];
$quantities = [];
if(!empty($apiResponse->getData()))
{
$orderData = $apiResponse->getData();
$orderItem = $orderData['items'];
foreach($orderItem as $item) {
$result = [
'item_total_price' => $item['item_total_price'],
'item_name' => $item['item_name'],
'item_description' => $item['item_description'],
'item_price' => $item['item_price'],
'ingredients' => $item['ingredients']
];
$results[] = $result;
$quantities[] = $item['quantity'];
}
}
$userWebToken = User::find()
->select('device_token')
->where(['user_id' => $modelOrder->user_id])
->andWhere(['not', ['device_token' => null]])
->one();
if ($userWebToken != null ) {
$token = trim($userWebToken->device_token);
try {
$oneSignal = OneSignal::getInstance();
$oneSignal->setAppId(Configuration::get(Configuration::PUSH_NOTIFICATION_APP_ID));
$oneSignal->setRestApiKey(Configuration::get(Configuration::PUSH_NOTIFICATION_REST_API_KEY));
$oneSignal->setIcon('http://online.kitokey.com/frontend/web/theme/images/notification.png');
$oneSignal->push(
['en' => 'Order status'],
['en' => 'Order Placed Successfully.'],
[$token],
['status' => 'Message Sent Successfully']
);
} catch (Exception $e) {
echo $e->getMessage();
}
}
$vendorDeviceToken = Vendor::find()
->select('device_token')
->where(['vendor_id' => $modelOrder->vendor_id])
->andWhere(['not', ['device_token' => null]])
->one();
$vendorDetails = Vendor::find()->alias('V')
->select(['VL.vendor_name'])
->leftJoin(['VL' => VendorLang::tableName()],'VL.vendor_id = V.vendor_id')
->where(['V.vendor_id' => $modelOrder->vendor_id])
->one();
if ((Configuration::get(Configuration::IS_VENDOR_NOTIFICATION_ENABLED)) == 1)
{
if ($vendorDeviceToken != null ) {
$token = trim($vendorDeviceToken->device_token);
try {
$oneSignal = OneSignal::getInstance();
$oneSignal->setAppId(Configuration::get(Configuration::VENDOR_ONESIGNAL_APP_ID));
$oneSignal->setIcon('http://online.kitokey.com/frontend/web/theme/images/notification.png');
$oneSignal->setRestApiKey(Configuration::get(Configuration::VENDOR_PUSH_NOTIFICATION_REST_API_KEY));
$oneSignal->vendorpush(
['en' => 'Order Details'],
['en' => 'You have new order'],
[$token],
['status' => 'Message Sent Successfully']
);
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
$modelBranchlist = Branch::find()
->where(['branch_id' => $modelOrder->branch_id])
->one();
$modelVendor = Vendor::find()
->where(['vendor_id' => $modelOrder->vendor_id])
->one();
$paymentOption = Order::getPaymentOptionLabel((int)$modelOrder->payment_option);
if($modelUser != null && $modelUser->email != null) {
$resposeArray = \backend\models\Order::find()
->where(['order_id' => $modelOrder->getPrimaryKey()])
->orderBy(['order_id' => SORT_DESC])
->one();
$qr_path = \common\helpers\QrHelper::getInstance()->generate($resposeArray['order_date_time'], $resposeArray['order_total'], $resposeArray['vat_cgst']);
$html = $this->renderPartial('mail', [
'model' => $resposeArray->toArray(),
'qr_path' => $qr_path
//'key' => $post['key']
]);
$mpdf = new mPDF(['tempDir' => Yii::getAlias('@approot').'/uploads/mpdfTemp']);
$mpdf->WriteHTML($html);
$filname = $resposeArray->order_number.' - '. Date('Y-m-d-h-i-s').'pdf';
$uploadHelper = UploadHelper::getInstance();
$uploadHelper->setPath($uploadHelper::ORDER_PDF);
$path = $uploadHelper->getPath();
$file = $mpdf->Output($path.'/'.$filname.'.pdf', 'F');
$path = $uploadHelper->getRealPath($path);
$finalFile = Yii::getAlias('@approot').'/'.$path.'/'.$filname.'.pdf';
$modelOrder->qr_pdf_path = $path.'/'.$filname.'.pdf';
$modelOrder->save(false);
chmod($finalFile, 0775);
MailerQueueHelper::getInstance()
->setTo($modelUser->email)
->setSubject('Order Placed')
// ->setAttach($finalFile)
->setView('orderPlaced',[
'name' => $modelUser->first_name,
'orderId' => $modelOrder->order_number,
'date' => $modelOrder->order_date_time,
'pickup_delivery' => $modelOrder->pickup_delivery_date_time,
'payment_option' => $modelOrder->payment_option,
'order_type' => $modelOrder->order_type,
'delivery_option' => $modelOrder->delivery_option,
'order_key' => $modelOrder->order_key,
'itemStatus' => $results,
'itemQuantity' => $quantities,
'vat' => $modelOrder->vat,
'cgst' => $modelOrder->vat_cgst,
'sgst' => $modelOrder->vat_sgst,
'igst' => $modelOrder->vat_igst,
'packagingFee' => $modelOrder->package_price,
'itemTotalPrice' => $modelOrder->item_total,
'deliveryFee' => $modelOrder->delivery_fee,
'coupon_offer_value' => $modelOrder->coupon_offer_value,
'deliveryboytip' => $modelOrder->delivery_boy_tip,
'subTotal'=> $modelOrder->order_total,
'qr_path' => $qr_path
])->push();
}
return;
}
public function actionHyperpayPayment($order_key, $type = 'web')
{
//print_r($order_key); die;
$modelOrder = Order::find()->where(['order_key' => $order_key])->one();
$userAddress = UserAddressLang::findOne(['user_address_id' => $modelOrder->user_address_id]);
$entityId = '';
$paymentType = 'VISA MASTER';
if($modelOrder->payment_option == Order::PAYMENT_OPTION_VISA_MASTER) {
$entityId = Configuration::get(Configuration::MASTER_VISA_ENTITY_ID);
}
if($modelOrder->payment_option == Order::PAYMENT_OPTION_MADA) {
$paymentType = 'MADA';
$entityId = Configuration::get(Configuration::MADA_ENTITY_ID);
}
if($modelOrder->payment_option == Order::PAYMENT_OPTION_STC) {
$paymentType = 'STC_PAY';
$entityId = Configuration::get(Configuration::STC_PAY_ENTITY_ID);
}
if($modelOrder->payment_option == 6) {
$paymentType = 'APPLEPAY';
$entityId = '8ac9a4ca7c78e3f5017c8e865d7c0449';
}
$url = "https://oppwa.com/v1/checkouts";
$data = "entityId=".$entityId .
"&amount=".number_format($modelOrder->order_total + $modelOrder->total_subscription_price, 2, '.', '')."" .
"¤cy=SAR".
"&paymentType=DB&merchantTransactionId=".$modelOrder->order_number;
// "&customer.email=".$modelOrder->customer_email.
// // "&testMode=EXTERNAL
// "&billing.street1=".$userAddress->street_name.
// "&billing.city=".$userAddress->city.
// "&billing.state=".$userAddress->area.
// "&billing.country=SA".
// "&billing.postcode=".$userAddress->postcode.
// "&customer.givenName=".$modelOrder->customer_first_name.
// "&customer.surname=".$modelOrder->customer_first_name;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:Bearer '.Configuration::get(Configuration::PAYMENT_ACCESS_TOKEN)));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if(curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
$result = json_decode($responseData);
$track = ['request' => $data, 'response' => $result];
$modelOrder->payment_request_data = json_encode($track);
$modelOrder->payment_id = $result->id;
$modelOrder->save(false);
if($type == 'mobile') {
return $this->asJson($result);
}
$url = Yii::$app->request->hostInfo.'/payment/payment-reseponse?key='.$modelOrder->order_key;
return $this->renderPartial('view', ['paymentID' => $result->id, 'url' => $url, 'paymentType' => $paymentType, 'userAddress' => $userAddress]);
//return $responseData;
}
public function actionPaymentReseponse($key = null)
{
$request = Yii::$app->request->get();
$order = Order::findOne(['order_key' => $key]);
$entityId = '';
if($order->payment_option == Order::PAYMENT_OPTION_VISA_MASTER) {
$entityId = Configuration::get(Configuration::MASTER_VISA_ENTITY_ID);
}
if($order->payment_option == Order::PAYMENT_OPTION_MADA) {
$entityId = Configuration::get(Configuration::MADA_ENTITY_ID);
}
if($order->payment_option == Order::PAYMENT_OPTION_STC) {
$entityId = Configuration::get(Configuration::STC_PAY_ENTITY_ID);
}
if($order->payment_option == 6) {
$paymentType = 'APPLEPAY';
$entityId = '8ac9a4ca7c78e3f5017c8e865d7c0449';
}
$url = "https://oppwa.com/v1/checkouts/".$request['id']."/payment";
$url .= "?entityId=".$entityId;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:Bearer '.Configuration::get(Configuration::PAYMENT_ACCESS_TOKEN)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if(curl_errno($ch)) {
return curl_error($ch);
}
$result = json_decode($responseData);
if($result->result->code == "000.000.000") {
$order->payment_status = Order::PAYMENT_STATUS_SUCCESS;
$order->order_status = Order::ORDER_STATUS_PENDING;
$order->order_date_time = date('Y-m-d H:i:s');
$order->payment_response = json_encode($result);
$order->save(false);
$modelEmail = EmailQueue::find()->where(['order_id' => $order->order_id])->one();
if($modelEmail != null) {
$mailer = Mailer::getInstance()->setTo($modelEmail->to_address);
$mailer->setSubject($modelEmail->subject);
$mailer->setMessage($modelEmail->content);
$mailer->send(); //mail updated by lakshmanan
}
if(Yii::$app->getUser()->getId()) {
Com::successFlash('Payment Recevied Successfully');
return $this->redirect(Url::to(['/branch/order-confirmation','id' => $key]));
}
return $this->asJson(['status' => 200 , 'msg' => 'Payment Successfully']);
}
$order->payment_url = $url;
$order->payment_response = json_encode($result);
$order->save(false);
if(Yii::$app->getUser()->getId()) {
Com::failureFlash('Payment failure');
return $this->redirect(Url::to(['/branch/checkout?type=1']));
}
return $this->asJson(['status' => 401 , 'msg' => 'Payment Failure']);
die();
}
public function actionHyperSuccess($type = null)
{
return $this->render('sucess', ['type' => $type]);
}
public function actionHyperFail()
{
return $this->render('fail');
}
public function actionHyperpayPaymentWallet($key, $type = 'web')
{
//print_r($order_key); die;
$modelOrder = WalletTransaction::find()->where(['wallet_transaction_key' => $key])->one();
if($modelOrder == null){
return $this->redirect(['hyper-fail']);
}
$entityId = '';
$paymentType = 'VISA MASTER';
if($modelOrder->payment_option == Order::PAYMENT_OPTION_VISA_MASTER) {
$entityId = Configuration::get(Configuration::MASTER_VISA_ENTITY_ID);
}
if($modelOrder->payment_option == Order::PAYMENT_OPTION_MADA) {
$paymentType = 'MADA';
$entityId = Configuration::get(Configuration::MADA_ENTITY_ID);
}
if($modelOrder->payment_option == Order::PAYMENT_OPTION_STC) {
$paymentType = 'STC_PAY';
$entityId = Configuration::get(Configuration::STC_PAY_ENTITY_ID);
}
if($modelOrder->payment_option == 6) {
$paymentType = 'APPLEPAY';
$entityId = '8ac9a4ca7c78e3f5017c8e865d7c0449';
}
// print_r($modelOrder); die;
$url = "https://oppwa.com/v1/checkouts";
$data = "entityId=".$entityId.
"&amount=".number_format($modelOrder->amount, 2, '.', '')."" .
"¤cy=SAR" .
"&paymentType=DB".
"&paymentBrand=MADA";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:Bearer OGFjN2E0Yzg3N2YzMGU0MDAxNzdmMzU5YjE3MjAyOTV8MkZYRGJkRlFRcw=='));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if(curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
$result = json_decode($responseData);
//print_r($result); die;
if($type == 'mobile') {
return $this->asJson($result);
}
$url = Yii::$app->request->hostInfo.'/payment/hyperpay-payment-wallet-response?key='.$modelOrder->wallet_transaction_key;
return $this->render('view', ['paymentID' => $result->id, 'url' => $url, 'paymentType' => $paymentType]);
//return $responseData;
}
public function actionHyperpayPaymentWalletResponse($key = null)
{
$request = Yii::$app->request->get();
$order = WalletTransaction::findOne(['wallet_transaction_key' => $key]);
$entityId = '';
if($order->payment_option == Order::PAYMENT_OPTION_VISA_MASTER) {
$entityId = Configuration::get(Configuration::MASTER_VISA_ENTITY_ID);
}
if($order->payment_option == Order::PAYMENT_OPTION_MADA) {
$entityId = Configuration::get(Configuration::MADA_ENTITY_ID);
}
if($order->payment_option == Order::PAYMENT_OPTION_STC) {
$entityId = Configuration::get(Configuration::STC_PAY_ENTITY_ID);
}
if($order->payment_option == 6) {
$paymentType = 'APPLEPAY';
$entityId = '8ac9a4ca7c78e3f5017c8e865d7c0449';
}
$url = "https://oppwa.com/v1/checkouts/".$request['id']."/payment";
$url .= "?entityId=".$entityId;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:Bearer OGFjN2E0Yzg3N2YzMGU0MDAxNzdmMzU5YjE3MjAyOTV8MkZYRGJkRlFRcw=='));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if(curl_errno($ch)) {
return curl_error($ch);
}
$result = json_decode($responseData);
if($result->result->code == "000.000.000") {
$order->transaction_status = WalletTransaction::TRANSACTION_SUCCESS;
//$order->order_status = Order::ORDER_STATUS_PENDING;
// $order->order_date_time = date('Y-m-d H:i:s');
$order->response_json = json_encode($result);
$order->save(false);
$userIdentity = User::findOne(['user_key' => $order->user_key]);
$userIdentity->wallet_point += $order->amount;
$userIdentity->save(false);
if(Yii::$app->getUser()->getId()) {
Com::successFlash('Payment Recevied Successfully');
return $this->redirect(Url::to(['/user/wallet']));
}
return $this->asJson(['status' => 200 , 'msg' => 'Payment Successfully']);
}
if(Yii::$app->getUser()->getId()) {
Com::failureFlash('Payment failure');
return $this->redirect(Url::to(['/user/wallet']));
}
return $this->asJson(['status' => 401 , 'msg' => 'Payment Failure']);
return $this->redirect(['hyper-fail']);
die();
}
public function actionStc()
{
$url = "https://test.oppwa.com/v1/payment";
$url .= "?entityId=8ac7a4c877f30e400177f35b9bbc02a1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:Bearer '.Configuration::get(Configuration::PAYMENT_ACCESS_TOKEN)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if(curl_errno($ch)) {
return curl_error($ch);
}
$result = json_decode($responseData);
echo "
";
print_r($result); die;
}
}