diff --git a/CHANGELOG.md b/CHANGELOG.md index 05771de6..5c5c26f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 3.2.0 (2021-11-02) +Improvements: +- Migrate Kredivo to XenInvoice +- Data housekeeping + ## 3.1.0 (2021-10-03) Improvements: - Add Shopeepay payment method diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index 4d3ae193..0198bbef 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -79,7 +79,6 @@ public function execute() if ($method === 'cc_subscription') { $billingAddress = $orders[0]->getBillingAddress(); // billing address of 1st order - $shippingAddress = $orders[0]->getShippingAddress(); // shipping address of 1st order $requestData = [ 'payer_email' => $billingAddress->getEmail(), diff --git a/Xendit/M2Invoice/Controller/Checkout/CardlessCreditMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CardlessCreditMultishipping.php deleted file mode 100644 index 4f01cba0..00000000 --- a/Xendit/M2Invoice/Controller/Checkout/CardlessCreditMultishipping.php +++ /dev/null @@ -1,211 +0,0 @@ -getRequest()->getParam('order_ids'); - $orderIds = explode("-", $rawOrderIds); - $transactionAmount = 0; - $orderProcessed = false; - $orders = []; - $items = []; - $orderIncrementIds = ''; - $c = 0; - - foreach ($orderIds as $key => $value) { - $order = $this->getOrderFactory()->create(); - $order->load($value); - if ($c>0) { - $orderIncrementIds .= "-"; - } - $orderIncrementIds .= $order->getRealOrderId(); - - $orderState = $order->getState(); - if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) { - $orderProcessed = true; - continue; - } - - $order->setState(Order::STATE_PENDING_PAYMENT) - ->setStatus(Order::STATE_PENDING_PAYMENT) - ->addStatusHistoryComment("Pending Xendit payment."); - - // item details - $orderItems = $order->getAllItems(); - foreach ($orderItems as $orderItem) { - $item = []; - $product = $orderItem->getProduct(); - $item['id'] = $product->getId(); - $item['name'] = $product->getName(); - $item['price'] = $product->getPrice(); - $item['type'] = $product->getTypeId(); // TODO; improve - $item['url'] = $product->getProductUrl(); - $item['quantity'] = (int) $orderItem->getQtyOrdered(); - $items[] = $item; - } - - array_push($orders, $order); - // save order - $order->save(); - $transactionAmount += (int)$order->getTotalDue(); - $c++; - } - - if ($orderProcessed) { - return $this->_redirect('multishipping/checkout/success'); - } - // customer details (from last order) - $customerDetails['first_name'] = $order->getCustomerFirstname(); - $customerDetails['last_name'] = $order->getCustomerLastname(); - $customerDetails['email'] = $order->getCustomerEmail(); - $customerDetails['phone'] = $order->getShippingAddress()->getTelephone(); - // shipping address details (from last order) - $shippingAddress = $order->getShippingAddress(); - $shippingAddressData['first_name'] = $shippingAddress->getData('firstname'); - $shippingAddressData['last_name'] = $shippingAddress->getData('lastname'); - $shippingAddressData['address'] = $shippingAddress->getData('street'); - $shippingAddressData['city'] = $shippingAddress->getData('city'); - $shippingAddressData['postal_code'] = $shippingAddress->getData('postcode'); - $shippingAddressData['phone'] = $shippingAddress->getData('telephone'); - $shippingAddressData['country_code'] = 'IDN'; // TODO: make dynamic - - $preferredMethod = $this->getRequest()->getParam('preferred_method'); - - $args = [ - 'cardless_credit_type' => strtoupper($preferredMethod), - 'external_id' => $this->getDataHelper()->getExternalId($rawOrderIds), - 'amount' => round($transactionAmount), - 'payment_type' => '3_months', - 'items' => $items, - 'description' => $rawOrderIds, - 'customer_details' => $customerDetails, - 'shipping_address' => $shippingAddressData, - 'redirect_url' => $this->getDataHelper()->getSuccessUrl(true), - 'callback_url' => $this->getDataHelper()->getCheckoutUrl()."/payment/xendit/cardless-credit/callback", - 'platform_callback_url' => $this->getXenditCallbackUrl() - ]; - - // add 'payment_type' - if ($this->getCookieManager()->getCookie('xendit_payment_type')) { - $args['payment_type'] = $this->getCookieManager()->getCookie('xendit_payment_type'); - $this->getCookieManager()->deleteCookie('xendit_payment_type'); - } - - // send Cardless Credit Payment request - $cardlessCreditPayment = $this->requestCardlessCreditPayment($args); - - // handle '422' error - if ( isset($cardlessCreditPayment['error_code']) ) { - // handle duplicate payment error - if ($cardlessCreditPayment['error_code'] == 'DUPLICATE_PAYMENT_ERROR') { - $args = array_replace($args, [ - 'external_id' => $this->getDataHelper()->getExternalId($orderIncrementIds, true) - ]); - // re-send Cardless Credit Payment request - $cardlessCreditPayment = $this->requestCardlessCreditPayment($args); - } - if (isset($cardlessCreditPayment['error_code'])) { - $message = $this->getErrorHandler()->mapCardlessCreditErrorCode($cardlessCreditPayment['error_code']); - // cancel order and redirect to cart - return $this->processFailedPayment($orderIds, $message); - } - } - - if (isset($cardlessCreditPayment['redirect_url'])) { - $redirectUrl = $cardlessCreditPayment['redirect_url']; - $resultRedirect = $this->getRedirectFactory()->create(); - $resultRedirect->setUrl($redirectUrl); - // redirect to Xendit Payment channel - return $resultRedirect; - } - } catch (\Exception $e) { - $message = 'Exception caught on xendit/checkout/redirect: ' . $e->getMessage(); - $this->getLogger()->info($message); - return $this->redirectToCart("There was an error in the Xendit payment. Failure reason: Unexpected Error"); - } - } - - /** - * @param $failureReason - * @return \Magento\Framework\Controller\ResultInterface - */ - private function redirectToCart($failureReason) - { - $failureReasonInsight = $this->getDataHelper()->failureReasonInsight($failureReason); - $this->getMessageManager()->addErrorMessage(__( - $failureReasonInsight - )); - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $resultRedirect->setUrl($this->_url->getUrl('checkout/cart'), [ '_secure'=> false ]); - return $resultRedirect; - } - - /** - * @param $requestData - * @param bool $isRetried - * @return mixed - * @throws \Exception - */ - private function requestCardlessCreditPayment($requestData, $isRetried = true) - { - $this->logger->info(json_encode($requestData)); - - $cardlessCreditUrl = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/cardless-credit"; - $cardlessCreditMethod = Request::METHOD_POST; - $options = [ - 'timeout' => 60 - ]; - - try { - $cardlessCreditPayment = $this->getApiHelper()->request( - $cardlessCreditUrl, - $cardlessCreditMethod, - $requestData, - null, - null, - $options, - [ - 'x-api-version' => '2020-02-01' - ] - ); - $this->logger->info(json_encode($cardlessCreditPayment)); - } catch (\Exception $e) { - $this->logger->info(json_encode($e)); - - throw $e; - } - - return $cardlessCreditPayment; - } - - /** - * @param $orderIds - * @param string $failureReason - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - private function processFailedPayment($orderIds, $failureReason = 'Unexpected Error with empty charge') - { - $this->getCheckoutHelper()->processOrdersFailedPayment($orderIds, $failureReason); - - $failureReasonInsight = $this->getDataHelper()->failureReasonInsight($failureReason); - $this->getMessageManager()->addErrorMessage(__( - $failureReasonInsight - )); - $this->_redirect('checkout/cart', ['_secure'=> false]); - } -} diff --git a/Xendit/M2Invoice/Controller/Checkout/Invoice.php b/Xendit/M2Invoice/Controller/Checkout/Invoice.php index eb9373d3..25100199 100644 --- a/Xendit/M2Invoice/Controller/Checkout/Invoice.php +++ b/Xendit/M2Invoice/Controller/Checkout/Invoice.php @@ -63,7 +63,28 @@ private function getApiRequestData($order) $orderId = $order->getRealOrderId(); $preferredMethod = $this->getRequest()->getParam('preferred_method'); - $billingaddress = $order->getBillingAddress(); + $shippingAddress = $order->getShippingAddress(); + $address = [ + 'street_line1' => $shippingAddress->getData('street') ?: 'N/A', + 'city' => $shippingAddress->getData('city') ?: 'N/A', + 'state' => $shippingAddress->getData('region') ?: 'N/A', + 'postal_code' => $shippingAddress->getData('postcode') ?: 'N/A', + 'country' => $shippingAddress->getData('country_id') ?: 'ID' + ]; + + $orderItems = $order->getAllItems(); + $items = []; + foreach ($orderItems as $orderItem) { + $item = []; + $product = $orderItem->getProduct(); + $item['reference_id'] = $product->getId(); + $item['name'] = $product->getName(); + $item['price'] = $product->getPrice(); + $item['type'] = 'PRODUCT'; + $item['url'] = $product->getProductUrl(); + $item['quantity'] = (int) $orderItem->getQtyOrdered(); + $items[] = (object) $item; + } $requestData = [ 'external_id' => $this->getDataHelper()->getExternalId($orderId), @@ -78,10 +99,13 @@ private function getApiRequestData($order) 'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(), 'failure_redirect_url' => $this->getDataHelper()->getFailureUrl($orderId), 'customer' => (object) [ - 'given_names' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(), - 'email' => $order->getCustomerEmail(), - 'mobile_number' => $billingaddress->getTelephone() - ] + 'given_names' => $order->getCustomerFirstname() ?: 'N/A', + 'surname' => $order->getCustomerLastname() ?: 'N/A', + 'email' => $order->getCustomerEmail() ?: 'noreply@mail.com' , + 'mobile_number' => $shippingAddress->getTelephone() ?: 'N/A', + 'addresses' => [(object) $address] + ], + 'items' => $items ]; return $requestData; diff --git a/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php index e8d5b8cb..b8abf4bf 100644 --- a/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php @@ -26,8 +26,10 @@ public function execute() $transactionAmount = 0; $orderProcessed = false; $orders = []; + $addresses = []; + $items = []; - $orderIncrementIds = ''; + $orderIncrementIds = ''; $c = 0; foreach ($orderIds as $key => $value) { @@ -53,11 +55,32 @@ public function execute() $order->save(); $transactionAmount += (int)$order->getTotalDue(); - $billingEmail = $order->getCustomerEmail(); - $billingFirstName = $order->getCustomerFirstname(); - $billingLastName = $order->getCustomerLastname(); - $billingaddress = $order->getBillingAddress(); + $billingEmail = $order->getCustomerEmail() ?: 'noreply@mail.com'; + $shippingAddress = $order->getShippingAddress(); $currency = $order->getBaseCurrencyCode(); + + $address = [ + 'street_line1' => $shippingAddress->getData('street') ?: 'N/A', + 'city' => $shippingAddress->getData('city') ?: 'N/A', + 'state' => $shippingAddress->getData('region') ?: 'N/A', + 'postal_code' => $shippingAddress->getData('postcode') ?: 'N/A', + 'country' => $shippingAddress->getData('country_id') ?: 'ID' + ]; + $addresses[] = (object) $address; + + $orderItems = $order->getAllItems(); + foreach ($orderItems as $orderItem) { + $item = []; + $product = $orderItem->getProduct(); + $item['reference_id'] = $product->getId(); + $item['name'] = $product->getName(); + $item['price'] = $product->getPrice(); + $item['type'] = 'PRODUCT'; + $item['url'] = $product->getProductUrl(); + $item['quantity'] = (int) $orderItem->getQtyOrdered(); + $items[] = (object) $item; + } + $c++; } @@ -83,10 +106,13 @@ public function execute() 'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(true), 'failure_redirect_url' => $this->getDataHelper()->getFailureUrl($orderIncrementIds, true), 'customer' => (object) [ - 'given_names' => $billingFirstName . ' ' . $billingLastName, - 'email' => $billingEmail, - 'mobile_number' => $billingaddress->getTelephone() - ] + 'given_names' => $order->getCustomerFirstname() ?: 'N/A', + 'surname' => $order->getCustomerLastname() ?: 'N/A', + 'email' => $billingEmail, + 'mobile_number' => $shippingAddress->getTelephone() ?: 'N/A', + 'addresses' => $addresses + ], + 'items' => $items ]; $invoice = $this->createInvoice($requestData); diff --git a/Xendit/M2Invoice/Controller/Checkout/Notification.php b/Xendit/M2Invoice/Controller/Checkout/Notification.php index f22437f1..f40429a6 100644 --- a/Xendit/M2Invoice/Controller/Checkout/Notification.php +++ b/Xendit/M2Invoice/Controller/Checkout/Notification.php @@ -134,13 +134,9 @@ public function execute() $this->logger->info("callbackPayload"); $this->logger->info($post); - if (!empty($callbackPayload["callback_authentication_token"]) && $callbackPayload["cardless_credit_type"] === "KREDIVO") { - // Kredivo - return $this->handleKredivoCallback($callbackPayload); - } else { - // Invoice: Regular CC, Ewallet, Retail Outlet - return $this->handleInvoiceCallback($callbackPayload); - } + // Invoice: Regular CC, Ewallet, Retail Outlet, PayLater + return $this->handleInvoiceCallback($callbackPayload); + } catch (\Exception $e) { $message = "Error invoice callback: " . $e->getMessage(); $this->logger->info($message); @@ -207,58 +203,6 @@ public function handleInvoiceCallback($callbackPayload) } } - /** - * @param $callbackPayload - * @return \Magento\Framework\Controller\Result\Json - * @throws LocalizedException - */ - public function handleKredivoCallback($callbackPayload) - { - if ( - !isset($callbackPayload['description']) || - !isset($callbackPayload['transaction_status']) || - !isset($callbackPayload['callback_authentication_token']) || - !isset($callbackPayload['cardless_credit_type']) - ) { - $result = $this->jsonResultFactory->create(); - /** You may introduce your own constants for this custom REST API */ - $result->setHttpResponseCode(Exception::HTTP_BAD_REQUEST); - $result->setData([ - 'status' => __('ERROR'), - 'message' => 'Callback body is invalid' - ]); - - return $result; - } - - // Kredivo description is Magento's order ID - $description = $callbackPayload['description']; - // in case of multishipping, we separate order IDs with `-` - $orderIds = explode("-", $description); - - $isMultishipping = (count($orderIds) > 1) ? true : false; - - if ($isMultishipping) { - foreach ($orderIds as $key => $value) { - $order = $this->orderFactory->create(); - $order->load($value); - - $result = $this->checkOrder($order, $callbackPayload, null, $description); - } - - return $result; - } else { - $order = $this->getOrderById($description); - - if (!$order) { - $order = $this->orderFactory->create(); - $order->load($description); - } - - return $this->checkOrder($order, $callbackPayload, null, $description); - } - } - /** * @param $order * @param $callbackPayload @@ -314,23 +258,6 @@ private function checkOrder($order, $callbackPayload, $invoice, $callbackDescrip } } } - // Kredivo - else { - $transactionId = $callbackPayload['transaction_id']; - $paymentStatus = $callbackPayload['transaction_status']; - - if ($callbackPayload["callback_authentication_token"] !== $this->dataHelper->getKredivoCallbackAuthenticationToken()) { - $result = $this->jsonResultFactory->create(); - /** You may introduce your own constants for this custom REST API */ - $result->setHttpResponseCode(Exception::HTTP_BAD_REQUEST); - $result->setData([ - 'status' => __('ERROR'), - 'message' => 'The callback is not for this order' - ]); - - return $result; - } - } $this->logger->info($paymentStatus); $statusList = [ @@ -424,33 +351,6 @@ private function getXenditInvoice($invoiceId) return $invoice; } - /** - * @param $ewalletType - * @param $externalId - * @return string - * @throws \Magento\Payment\Gateway\Http\ClientException - */ - private function getEwalletStatus($ewalletType, $externalId) - { - $ewalletUrl = $this->dataHelper->getCheckoutUrl() . "/payment/xendit/ewallets?ewallet_type=" . $ewalletType . "&external_id=" . $externalId; - $ewalletMethod = Request::METHOD_GET; - - try { - $response = $this->apiHelper->request($ewalletUrl, $ewalletMethod); - } catch (LocalizedException $e) { - throw new LocalizedException( - new Phrase($e->getMessage()) - ); - } - - $statusList = ["COMPLETED", "PAID", "SUCCESS_COMPLETED"]; //OVO, DANA, LINKAJA - if (in_array($response['status'], $statusList)) { - return "COMPLETED"; - } - - return $response['status']; - } - /** * @param $order * @param $transactionId diff --git a/Xendit/M2Invoice/Controller/Checkout/Redirect.php b/Xendit/M2Invoice/Controller/Checkout/Redirect.php index 6c54d3d6..73e2bff2 100755 --- a/Xendit/M2Invoice/Controller/Checkout/Redirect.php +++ b/Xendit/M2Invoice/Controller/Checkout/Redirect.php @@ -5,7 +5,6 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Payment\Transaction; -use Magento\Framework\Exception\LocalizedException; /** * Class Redirect @@ -15,7 +14,6 @@ class Redirect extends AbstractAction { /** * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface - * @throws \Magento\Framework\Exception\LocalizedException */ public function execute() { @@ -35,7 +33,7 @@ public function execute() $this->cancelOrder($order, $failureReason); return $this->redirectToCart($failureReason); } - // Dana / Kredivo / Linkaja / CC Subscription + // CC Subscription if ($payment->getAdditionalInformation('xendit_redirect_url') !== null) { $redirectUrl = $payment->getAdditionalInformation('xendit_redirect_url'); @@ -63,44 +61,6 @@ public function execute() $resultRedirect->setPath('xendit/checkout/qrcode', $urlData); return $resultRedirect; } - // OVO payment - if ($payment->getAdditionalInformation('xendit_ovo_external_id') !== null) { - $isSuccessful = false; - $loopCondition = true; - $startTime = time(); - while ($loopCondition && (time() - $startTime < 70)) { - $order = $this->getOrderById($orderId); - - if ($order->getState() !== Order::STATE_PENDING_PAYMENT) { - $loopCondition = false; - $isSuccessful = $order->getState() === Order::STATE_PROCESSING; - } - sleep(1); - } - - if ($order->getState() === Order::STATE_PENDING_PAYMENT) { - $ewalletStatus = $this->getEwalletStatus('OVO', $payment->getAdditionalInformation('xendit_ovo_external_id')); - - if ($ewalletStatus === 'COMPLETED') { - $isSuccessful = true; - } - } - - if ($isSuccessful) { - $this->getMessageManager()->addSuccessMessage(__("Your payment with Xendit is completed")); - return $this->_redirect('checkout/onepage/success', [ '_secure'=> false ]); - } else { - $payment = $order->getPayment(); - $failureCode = $payment->getAdditionalInformation('xendit_ewallet_failure_code'); - - if ($failureCode === null) { - $failureCode = 'Payment is ' . $ewalletStatus; - } - - $this->getCheckoutHelper()->restoreQuote(); - return $this->redirectToCart($failureCode); - } - } $this->cancelOrder($order, 'No payment recorded'); @@ -113,33 +73,6 @@ public function execute() } } - /** - * @param $ewalletType - * @param $externalId - * @return string - * @throws LocalizedException - */ - private function getEwalletStatus($ewalletType, $externalId) - { - $ewalletUrl = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/ewallets?ewallet_type=".$ewalletType."&external_id=".$externalId; - $ewalletMethod = \Zend\Http\Request::METHOD_GET; - - try { - $response = $this->getApiHelper()->request($ewalletUrl, $ewalletMethod); - } catch (LocalizedException $e) { - throw new LocalizedException( - new Phrase($e->getMessage()) - ); - } - - $statusList = array("COMPLETED", "PAID", "SUCCESS_COMPLETED"); //OVO, DANA, LINKAJA - if (in_array($response['status'], $statusList)) { - return "COMPLETED"; - } - - return $response['status']; - } - /** * @param $failureReason * @return \Magento\Framework\Controller\ResultInterface diff --git a/Xendit/M2Invoice/Controller/Checkout/Success.php b/Xendit/M2Invoice/Controller/Checkout/Success.php index d3040bc5..ab8e7d3b 100644 --- a/Xendit/M2Invoice/Controller/Checkout/Success.php +++ b/Xendit/M2Invoice/Controller/Checkout/Success.php @@ -2,9 +2,6 @@ namespace Xendit\M2Invoice\Controller\Checkout; -use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Phrase; - /** * Class Success * @package Xendit\M2Invoice\Controller\Checkout @@ -13,56 +10,12 @@ class Success extends AbstractAction { /** * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function execute() { $type = $this->getRequest()->getParam('type'); - $paymentType = $this->getRequest()->getParam('payment_type'); - $ewalletType = $this->getRequest()->getParam('ewallet_type'); - $externalId = $this->getRequest()->getParam('external_id'); - - if (strtoupper($paymentType) === 'EWALLET') { - /** - * For eWallet payment (DANA/LINKAJA), there is only `redirect_url` parameter on API, - * meaning all eWallet transaction will eventually ended up in this endpoint, regardless - * of the transaction result (failed or successful). - * - * The logic inside processEwalletRedirect() makes sure that ewallet transaction will be - * redirected to the appropriate page: - * - Thank you page -> if eWallet transaction is successful - * - Cart page -> if eWallet transaction is failed - */ - $this->processEwalletRedirect($type, $externalId, $ewalletType); - } - else{ - $this->redirectToThankYouPage($type); - } - } - - /** - * @param $type - * @param $externalId - * @param $ewalletType - * @return \Magento\Framework\App\ResponseInterface|void - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - private function processEwalletRedirect($type, $externalId, $ewalletType) - { - if (empty($externalId) || empty($ewalletType)) { - $this->getMessageManager()->addWarningMessage(__("Xendit payment failed. Please retry your order.")); - $this->_redirect('checkout/cart'); - } - - $ewalletStatus = $this->getEwalletStatus($ewalletType, $externalId); - if ($ewalletStatus === 'COMPLETED') { - $this->redirectToThankYouPage($type); - } else { - $this->handleEwalletPaymentFailed($type); - } + $this->redirectToThankYouPage($type); } /** @@ -88,72 +41,4 @@ private function redirectToThankYouPage($type) $this->_redirect('checkout/onepage/success', [ '_secure'=> false ]); } } - - /** - * @param $type - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - private function handleEwalletPaymentFailed($type) - { - if ($type == 'multishipping') { - $orderIds = explode('-', $this->getRequest()->get('order_id')); - foreach ($orderIds as $orderId) { - $order = $this->getOrderFactory()->create(); - $order ->load($orderId); - - if ($order) { - $this->getLogger()->debug('Requested order payment is failed. OrderId: ' . $order->getIncrementId()); - $this->cancelOrder($order, "customer failed the payment."); - - $quoteId = $order->getQuoteId(); - $quote = $this->getQuoteRepository()->get($quoteId); - - $this->getCheckoutHelper()->restoreQuote($quote); //restore cart - } - } - } else { //onepage - $order = $this->getOrderById($this->getRequest()->get('order_id')); - - if ($order) { - $this->getLogger()->debug('Requested order payment is failed. OrderId: ' . $order->getIncrementId()); - $this->cancelOrder($order, "customer failed the payment."); - - $quoteId = $order->getQuoteId(); - $quote = $this->getQuoteRepository()->get($quoteId); - - $this->getCheckoutHelper()->restoreQuote($quote); //restore cart - } - } - - $this->getMessageManager()->addWarningMessage(__("Xendit payment failed. Please click on 'Update Shopping Cart'.")); - $this->_redirect('checkout/cart'); - } - - /** - * @param $ewalletType - * @param $externalId - * @return string - * @throws LocalizedException - */ - private function getEwalletStatus($ewalletType, $externalId) - { - $ewalletUrl = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/ewallets?ewallet_type=".strtoupper($ewalletType)."&external_id=".$externalId; - $ewalletMethod = \Zend\Http\Request::METHOD_GET; - - try { - $response = $this->getApiHelper()->request($ewalletUrl, $ewalletMethod); - } catch (LocalizedException $e) { - throw new LocalizedException( - new Phrase($e->getMessage()) - ); - } - - $statusList = array("COMPLETED", "PAID", "SUCCESS_COMPLETED"); //OVO, DANA, LINKAJA - if (in_array($response['status'], $statusList)) { - return "COMPLETED"; - } - - return $response['status']; - } } diff --git a/Xendit/M2Invoice/Controller/Payment/OverviewPost.php b/Xendit/M2Invoice/Controller/Payment/OverviewPost.php index a152aff3..8f017ccf 100755 --- a/Xendit/M2Invoice/Controller/Payment/OverviewPost.php +++ b/Xendit/M2Invoice/Controller/Payment/OverviewPost.php @@ -145,13 +145,10 @@ public function execute() $params = implode("-", $orderIds); $xenditCCMethods = ['cc_subscription']; - $xenditCardlessCreditMethods = ['kredivo']; $xenditQrCodeMethods = ['qr_codes']; if (in_array($xenditPaymentMethod, $xenditCCMethods)) { $redirect = $baseUrl . '/xendit/checkout/ccmultishipping?order_ids=' . $params . '&preferred_method=' . $xenditPaymentMethod; - } elseif (in_array($xenditPaymentMethod, $xenditCardlessCreditMethods)) { - $redirect = $baseUrl . '/xendit/checkout/cardlesscreditmultishipping?order_ids=' . $params . '&preferred_method=' . $xenditPaymentMethod; } elseif (in_array($xenditPaymentMethod, $xenditQrCodeMethods)) { $redirect = $baseUrl . '/xendit/checkout/qrcodemultishipping?order_ids=' . $params . '&preferred_method=' . $xenditPaymentMethod; } else { diff --git a/Xendit/M2Invoice/Helper/ApiRequest.php b/Xendit/M2Invoice/Helper/ApiRequest.php index 573f94ce..cd39676b 100644 --- a/Xendit/M2Invoice/Helper/ApiRequest.php +++ b/Xendit/M2Invoice/Helper/ApiRequest.php @@ -110,7 +110,7 @@ private function getHeaders($isPublicRequest, $preferredMethod = null, $customHe 'Content-Type' => 'application/json', 'x-plugin-name' => 'MAGENTO2', 'user-agent' => 'Magento 2 Module', - 'x-plugin-version' => '3.1.0' + 'x-plugin-version' => '3.2.0' ]; if ($preferredMethod !== null) { diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index 9f6d6296..6bca327e 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -105,23 +105,22 @@ class Data extends AbstractHelper const XML_PATH_DANA_DESCRIPTION = 'payment/dana/description'; /* - * Indomarat + * Indomaret */ - const XML_PATH_INDOMARAT_ACTIVE = 'payment/indomaret/active'; - const XML_PATH_INDOMARAT_TITLE = 'payment/indomaret/title'; - const XML_PATH_INDOMARAT_MIN_AMOUNT = 'payment/indomaret/min_order_total'; - const XML_PATH_INDOMARAT_MAX_AMOUNT = 'payment/indomaret/max_order_total'; - const XML_PATH_INDOMARAT_DESCRIPTION = 'payment/indomaret/description'; + const XML_PATH_INDOMARET_ACTIVE = 'payment/indomaret/active'; + const XML_PATH_INDOMARET_TITLE = 'payment/indomaret/title'; + const XML_PATH_INDOMARET_MIN_AMOUNT = 'payment/indomaret/min_order_total'; + const XML_PATH_INDOMARET_MAX_AMOUNT = 'payment/indomaret/max_order_total'; + const XML_PATH_INDOMARET_DESCRIPTION = 'payment/indomaret/description'; /* * Kredivo */ - const XML_PATH_KREDIVO_ACTIVE = 'payment/kredivo/active'; - const XML_PATH_KREDIVO_TITLE = 'payment/kredivo/title'; - const XML_PATH_KREDIVO_MIN_AMOUNT = 'payment/kredivo/min_order_total'; - const XML_PATH_KREDIVO_MAX_AMOUNT = 'payment/kredivo/max_order_total'; - const XML_PATH_KREDIVO_DESCRIPTION = 'payment/kredivo/description'; - const XML_PATH_KREDIVO_CALLBACK_AUTHENTICATION_TOKEN = 'payment/kredivo/callback_authentication_token'; + const XML_PATH_KREDIVO_ACTIVE = 'payment/kredivo/active'; + const XML_PATH_KREDIVO_TITLE = 'payment/kredivo/title'; + const XML_PATH_KREDIVO_MIN_AMOUNT = 'payment/kredivo/min_order_total'; + const XML_PATH_KREDIVO_MAX_AMOUNT = 'payment/kredivo/max_order_total'; + const XML_PATH_KREDIVO_DESCRIPTION = 'payment/kredivo/description'; /* * Linkaja @@ -1102,41 +1101,41 @@ public function getDdBriMaxOrderAmount() /** * @return mixed */ - public function getIndomaratActive() + public function getIndomaretActive() { - return $this->scopeConfig->getValue(self::XML_PATH_INDOMARAT_ACTIVE, ScopeInterface::SCOPE_STORE); + return $this->scopeConfig->getValue(self::XML_PATH_INDOMARET_ACTIVE, ScopeInterface::SCOPE_STORE); } /** * @return mixed */ - public function getIndomaratTitle() + public function getIndomaretTitle() { - return $this->scopeConfig->getValue(self::XML_PATH_INDOMARAT_TITLE, ScopeInterface::SCOPE_STORE); + return $this->scopeConfig->getValue(self::XML_PATH_INDOMARET_TITLE, ScopeInterface::SCOPE_STORE); } /** * @return mixed */ - public function getIndomaratDescription() + public function getIndomaretDescription() { - return $this->scopeConfig->getValue(self::XML_PATH_INDOMARAT_DESCRIPTION, ScopeInterface::SCOPE_STORE); + return $this->scopeConfig->getValue(self::XML_PATH_INDOMARET_DESCRIPTION, ScopeInterface::SCOPE_STORE); } /** * @return mixed */ - public function getIndomaratMinOrderAmount() + public function getIndomaretMinOrderAmount() { - return $this->scopeConfig->getValue(self::XML_PATH_INDOMARAT_MIN_AMOUNT, ScopeInterface::SCOPE_STORE); + return $this->scopeConfig->getValue(self::XML_PATH_INDOMARET_MIN_AMOUNT, ScopeInterface::SCOPE_STORE); } /** * @return mixed */ - public function getIndomaratMaxOrderAmount() + public function getIndomaretMaxOrderAmount() { - return $this->scopeConfig->getValue(self::XML_PATH_INDOMARAT_MAX_AMOUNT, ScopeInterface::SCOPE_STORE); + return $this->scopeConfig->getValue(self::XML_PATH_INDOMARET_MAX_AMOUNT, ScopeInterface::SCOPE_STORE); } /** @@ -1179,14 +1178,6 @@ public function getKredivoMaxOrderAmount() return $this->scopeConfig->getValue(self::XML_PATH_KREDIVO_MAX_AMOUNT, ScopeInterface::SCOPE_STORE); } - /** - * @return mixed - */ - public function getKredivoCallbackAuthenticationToken() - { - return $this->scopeConfig->getValue(self::XML_PATH_KREDIVO_CALLBACK_AUTHENTICATION_TOKEN, ScopeInterface::SCOPE_STORE); - } - /** * @return mixed */ diff --git a/Xendit/M2Invoice/Helper/ErrorHandler.php b/Xendit/M2Invoice/Helper/ErrorHandler.php index 19671bd1..381a9610 100644 --- a/Xendit/M2Invoice/Helper/ErrorHandler.php +++ b/Xendit/M2Invoice/Helper/ErrorHandler.php @@ -37,29 +37,10 @@ public function mapInvoiceErrorCode($errorCode) return 'There is no available payment code in your retail outlet range.'; case 'INVALID_REMINDER_TIME': return 'The reminder_time value is not allowed.'; - default: - return "Failed to pay with Invoice. Error code: $errorCode"; - } - } - - /** - * @param $errorCode - * @return string - */ - public function mapCardlessCreditErrorCode($errorCode) - { - switch ( $errorCode ) { case 'MERCHANT_NOT_FOUND': return 'You are not registered yet to use this payment method.'; - case 'GENERATE_CHECKOUT_URL_ERROR': - return 'Your request did not meet the requirement or there is a problem in the Kredivo / Partner server..'; - case 'PHONE_NUMBER_NOT_REGISTERED': - return 'Your number is not registered in DANA, please register first or contact DANA Customer Service.'; - case 'REQUEST_FORBIDDEN_ERROR': - return 'API key in use does not have necessary permissions to perform the request. - Please assign proper permissions for the key.'; default: - return "Failed to pay with Kredivo. Error code: $errorCode"; + return "Failed to pay with Invoice. Error code: $errorCode"; } } diff --git a/Xendit/M2Invoice/Model/Payment/Indomaret.php b/Xendit/M2Invoice/Model/Payment/Indomaret.php index 4351de33..f3261528 100644 --- a/Xendit/M2Invoice/Model/Payment/Indomaret.php +++ b/Xendit/M2Invoice/Model/Payment/Indomaret.php @@ -41,11 +41,11 @@ public function isAvailable(CartInterface $quote = null) $amount = ceil($quote->getSubtotal() + $quote->getShippingAddress()->getShippingAmount()); - if ($amount < $this->dataHelper->getIndomaratMinOrderAmount() || $amount > $this->dataHelper->getIndomaratMaxOrderAmount()) { + if ($amount < $this->dataHelper->getIndomaretMinOrderAmount() || $amount > $this->dataHelper->getIndomaretMaxOrderAmount()) { return false; } - if(!$this->dataHelper->getIndomaratActive()){ + if(!$this->dataHelper->getIndomaretActive()){ return false; } diff --git a/Xendit/M2Invoice/Model/Payment/KREDIVO.php b/Xendit/M2Invoice/Model/Payment/KREDIVO.php index 8c31fc8f..336abf0f 100644 --- a/Xendit/M2Invoice/Model/Payment/KREDIVO.php +++ b/Xendit/M2Invoice/Model/Payment/KREDIVO.php @@ -2,14 +2,21 @@ namespace Xendit\M2Invoice\Model\Payment; -use Magento\Framework\Phrase; -use Zend\Http\Request; use Magento\Quote\Api\Data\CartInterface; -use Magento\Framework\Exception\LocalizedException; -use Magento\Payment\Model\InfoInterface; +/** + * Class KREDIVO + * @package Xendit\M2Invoice\Model\Payment + */ class KREDIVO extends AbstractInvoice { + /** + * Payment Method feature + * + * @var bool + */ + protected $_isInitializeNeeded = true; + /** * Payment code * @@ -42,222 +49,6 @@ public function isAvailable(CartInterface $quote = null) return false; } - if(empty($this->dataHelper->getKredivoCallbackAuthenticationToken())){ - return false; - } - return true; } - - /** - * @param InfoInterface $payment - * @param float $amount - * @return $this|KREDIVO - * @throws LocalizedException - * @throws \Magento\Framework\Exception\FileSystemException - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function authorize(InfoInterface $payment, $amount) - { - $payment->setIsTransactionPending(true); - $additionalData = $this->getAdditionalData(); - - $order = $payment->getOrder(); - $orderItems = $order->getAllItems(); - $quoteId = $order->getQuoteId(); - $quote = $this->quoteRepository->get($quoteId); - $orderId = $order->getRealOrderId(); - $items = []; - $customerDetails = []; - $shippingAddressData = []; - - if ($quote->getIsMultiShipping()) { - return $this; - } - - try { - $shippingAddress = $order->getShippingAddress(); - - // items details - if ($orderItems) { - foreach ($orderItems as $orderItem) { - $item = []; - $product = $orderItem->getProduct(); - $item['id'] = $product->getId(); - $item['name'] = $product->getName(); - $item['price'] = $product->getPrice(); - $item['type'] = $product->getTypeId(); // TODO; improve - $item['url'] = $product->getProductUrl(); - $item['quantity'] = (int) $orderItem->getQtyOrdered(); - $items[] = $item; - } - } - // customer details - $customerDetails['first_name'] = $order->getCustomerFirstname(); - $customerDetails['last_name'] = $order->getCustomerLastname(); - $customerDetails['email'] = $order->getCustomerEmail(); - $customerDetails['phone'] = $order->getShippingAddress()->getTelephone(); - // shipping address details - $shippingAddressData['first_name'] = $shippingAddress->getData('firstname'); - $shippingAddressData['last_name'] = $shippingAddress->getData('lastname'); - $shippingAddressData['address'] = $shippingAddress->getData('street'); - $shippingAddressData['city'] = $shippingAddress->getData('city'); - $shippingAddressData['postal_code'] = $shippingAddress->getData('postcode'); - $shippingAddressData['phone'] = $shippingAddress->getData('telephone'); - $shippingAddressData['country_code'] = 'IDN'; // TODO: make dynamic - - $args = [ - 'cardless_credit_type' => $this->methodCode, - 'external_id' => $this->dataHelper->getExternalId($order->getRealOrderId()), - 'amount' => round($amount), - 'payment_type' => '3_months', - 'items' => $items, - 'description' => $order->getRealOrderId(), - 'customer_details' => $customerDetails, - 'shipping_address' => $shippingAddressData, - 'redirect_url' => $this->dataHelper->getSuccessUrl(false), - 'callback_url' => $this->dataHelper->getCheckoutUrl()."/payment/xendit/cardless-credit/callback", - 'platform_callback_url' => $this->getXenditCallbackUrl() - ]; - - if (isset($additionalData['xendit_payment_type'])) { - $args['payment_type'] = $additionalData['xendit_payment_type']; - } - - // send Cardless Credit Payment request - $cardlessCreditPayment = $this->requestCardlessCreditPayment($args); - - // handle '422' error - if ( isset($cardlessCreditPayment['error_code']) ) { - // handle duplicate payment error - if ($cardlessCreditPayment['error_code'] == 'DUPLICATE_PAYMENT_ERROR') { - $args = array_replace($args, [ - 'external_id' => $this->dataHelper->getExternalId($orderId, true) - ]); - // re-send Cardless Credit Payment request - $cardlessCreditPayment = $this->requestCardlessCreditPayment($args); - } - - if (isset($cardlessCreditPayment['error_code'])) { - $message = $this->errorHandler->mapCardlessCreditErrorCode($cardlessCreditPayment['error_code']); - $this->processFailedPayment($payment, $message); - - throw new LocalizedException( - new Phrase($message) - ); - } - } - // set additional info - if (isset($cardlessCreditPayment['external_id'])) { - $payment->setAdditionalInformation('xendit_external_id', $cardlessCreditPayment['external_id']); - } - if (isset($cardlessCreditPayment['redirect_url'])) { - $payment->setAdditionalInformation('xendit_redirect_url', $cardlessCreditPayment['redirect_url']); - } - if (isset($cardlessCreditPayment['order_id'])) { - $payment->setAdditionalInformation('xendit_order_id', $cardlessCreditPayment['order_id']); - } - if (isset($cardlessCreditPayment['cardless_credit_type'])) { - $payment->setAdditionalInformation('xendit_cardless_credit_type', $cardlessCreditPayment['cardless_credit_type']); - } - - } catch (\Exception $e) { - $errorMsg = $e->getMessage(); - throw new LocalizedException( - new Phrase($errorMsg) - ); - } - } - - /** - * @return array - * @throws \Magento\Framework\Exception\FileSystemException - */ - private function getAdditionalData() - { - static $data = []; - if (count($data) < 1) { - $data = (array) $this->getPaymentMethod(); - } - - return $this->elementFromArray($data, 'additional_data'); - } - - /** - * @return array - * @throws \Magento\Framework\Exception\FileSystemException - */ - private function getPaymentMethod() - { - /** - * @var array $data - * Holds submitted JSOn data in a PHP associative array - */ - static $data = []; - if (count($data) < 1) { - $data = (array) $this->dataHelper->jsonData(); - } - return $this->elementFromArray($data, 'paymentMethod'); - } - - /** - * @param $data - * @param $element - * @return array - */ - private function elementFromArray($data, $element) - { - $r = []; - if (key_exists($element, $data)) { - $r = (array) $data[$element]; - } - - return $r; - } - - /** - * @param $requestData - * @param bool $isRetried - * @return mixed - * @throws \Exception - */ - private function requestCardlessCreditPayment($requestData, $isRetried = true) - { - $this->_logger->info(json_encode($requestData)); - - $cardlessCreditUrl = $this->dataHelper->getCheckoutUrl() . "/payment/xendit/cardless-credit"; - $cardlessCreditMethod = Request::METHOD_POST; - $options = [ - 'timeout' => 60 - ]; - - try { - $cardlessCreditPayment = $this->apiHelper->request( - $cardlessCreditUrl, - $cardlessCreditMethod, - $requestData, - false, - null, - $options, - [ - 'x-api-version' => '2020-02-01' - ] - ); - $this->_logger->info(json_encode($cardlessCreditPayment)); - } catch (\Exception $e) { - $this->_logger->info(json_encode($e)); - throw $e; - } - - return $cardlessCreditPayment; - } - - /** - * @param $payment - * @param $message - */ - private function processFailedPayment($payment, $message) - { - $payment->setAdditionalInformation('xendit_failure_reason', $message); - } } diff --git a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php index 634228aa..019aac83 100644 --- a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php +++ b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php @@ -103,10 +103,10 @@ public function getConfig() 'description' => $this->xenditHelper->getAlfamartDescription() ], 'indomaret' => [ - 'title' => $this->xenditHelper->getIndomaratTitle(), - 'min_order_amount' => $this->xenditHelper->getIndomaratMinOrderAmount(), - 'max_order_amount' => $this->xenditHelper->getIndomaratMaxOrderAmount(), - 'description' => $this->xenditHelper->getIndomaratDescription() + 'title' => $this->xenditHelper->getIndomaretTitle(), + 'min_order_amount' => $this->xenditHelper->getIndomaretMinOrderAmount(), + 'max_order_amount' => $this->xenditHelper->getIndomaretMaxOrderAmount(), + 'description' => $this->xenditHelper->getIndomaretDescription() ], 'bcava' => [ 'title' => $this->xenditHelper->getBcaVaTitle(), diff --git a/Xendit/M2Invoice/composer.json b/Xendit/M2Invoice/composer.json index f49d5aeb..d6caf8bf 100644 --- a/Xendit/M2Invoice/composer.json +++ b/Xendit/M2Invoice/composer.json @@ -2,7 +2,7 @@ "name": "xendit/m2invoice", "description": "Xendit Payment Gateway Module", "type": "magento2-module", - "version": "3.1.0", + "version": "3.2.0", "license": [ "GPL-3.0" ], diff --git a/Xendit/M2Invoice/etc/adminhtml/cashless_credit/kredivo.xml b/Xendit/M2Invoice/etc/adminhtml/paylater/kredivo.xml similarity index 85% rename from Xendit/M2Invoice/etc/adminhtml/cashless_credit/kredivo.xml rename to Xendit/M2Invoice/etc/adminhtml/paylater/kredivo.xml index 445d82a2..947dccbb 100644 --- a/Xendit/M2Invoice/etc/adminhtml/cashless_credit/kredivo.xml +++ b/Xendit/M2Invoice/etc/adminhtml/paylater/kredivo.xml @@ -25,9 +25,5 @@ validate-zero-or-greater payment/kredivo/max_order_total - - - payment/kredivo/callback_authentication_token - diff --git a/Xendit/M2Invoice/etc/adminhtml/retail_outlets/indomarat.xml b/Xendit/M2Invoice/etc/adminhtml/retail_outlets/indomaret.xml similarity index 100% rename from Xendit/M2Invoice/etc/adminhtml/retail_outlets/indomarat.xml rename to Xendit/M2Invoice/etc/adminhtml/retail_outlets/indomaret.xml diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index 9173493e..9216b705 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -195,7 +195,7 @@ \Magento\Config\Block\System\Config\Form\Fieldset 0 - + @@ -217,11 +217,11 @@ - - + + \Magento\Config\Block\System\Config\Form\Fieldset 0 - + diff --git a/Xendit/M2Invoice/etc/config.xml b/Xendit/M2Invoice/etc/config.xml index e37cd2fb..c2ec1422 100644 --- a/Xendit/M2Invoice/etc/config.xml +++ b/Xendit/M2Invoice/etc/config.xml @@ -63,7 +63,7 @@ 1 - initialize + initialize Xendit\M2Invoice\Model\Payment\BRIVA Bank Transfer - BRI Bayar pesanan dengan transfer bank BRI dengan virtual account melalui Xendit @@ -76,7 +76,7 @@ 1 - initialize + initialize Xendit\M2Invoice\Model\Payment\MandiriVA Bank Transfer - Mandiri Bayar pesanan dengan transfer bank Mandiri dengan virtual account melalui Xendit @@ -89,7 +89,7 @@ 1 - initialize + initialize Xendit\M2Invoice\Model\Payment\PermataVA Bank Transfer - Permata Bayar pesanan dengan transfer bank Permata dengan virtual account melalui Xendit @@ -166,14 +166,13 @@ 11 - 0 - authorize + 1 + initialize Xendit\M2Invoice\Model\Payment\KREDIVO Kredivo Bayar pesanan dengan akun Kredivo anda melalui Xendit 10000 - 1000000000 - + 30000000 1 1 1 @@ -190,11 +189,11 @@ 1 1 1 - 14 + 13 1 - authorize + initialize Xendit\M2Invoice\Model\Payment\OVO OVO Bayar pesanan dengan akun OVO anda melalui Xendit @@ -222,7 +221,7 @@ 1 - authorize + initialize Xendit\M2Invoice\Model\Payment\SHOPEEPAY ShopeePay Bayar pesanan dengan akun ShopeePay anda melalui Xendit @@ -231,7 +230,7 @@ 1 1 1 - 14 + 16 diff --git a/Xendit/M2Invoice/etc/module.xml b/Xendit/M2Invoice/etc/module.xml index 19b1dc9e..f065f304 100644 --- a/Xendit/M2Invoice/etc/module.xml +++ b/Xendit/M2Invoice/etc/module.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/kredivo.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/kredivo.js index b3662681..44b91897 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/kredivo.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/kredivo.js @@ -2,18 +2,12 @@ define( [ 'Magento_Checkout/js/view/payment/default', 'mage/url', - 'Magento_Checkout/js/model/quote', - 'underscore', - 'jquery', - 'Magento_Checkout/js/action/place-order' + 'Magento_Checkout/js/model/quote' ], function ( Component, url, - quote, - _, - $, - placeOrderAction + quote ) { 'use strict'; @@ -21,8 +15,8 @@ define( return Component.extend({ defaults: { - template: 'Xendit_M2Invoice/payment/kredivo', - redirectAfterPlaceOrder: false + template: 'Xendit_M2Invoice/payment/invoiceva', + redirectAfterPlaceOrder: false, }, initialize: function() { @@ -60,7 +54,7 @@ define( }, afterPlaceOrder: function () { - window.location.replace(url.build('xendit/checkout/redirect')); + window.location.replace(url.build(`xendit/checkout/invoice?preferred_method=${self.getMethod()}`)); }, validate: function() { @@ -75,71 +69,6 @@ define( return true; - }, - - placeOrder: function (data, event) { - this.isPlaceOrderActionAllowed(false); - var self = this; - - try { - let errorMessageBlock = $(".messages .message-error div"); - let messageBlock = $(".messages"); - // hide error message block - errorMessageBlock.html(""); - messageBlock.hide(); - - var kredivoPaymentType = $('#kredivo_payment_type').val(); - - if (!kredivoPaymentType || kredivoPaymentType === "") { - errorMessageBlock.html("Please select a payment type first."); - messageBlock.show(); - self.isPlaceOrderActionAllowed(true); // enable "pay now" button - return false; - } - var paymentData = self.getData(); - paymentData.additional_data = { - xendit_payment_type: kredivoPaymentType - }; - - var placeOrder = placeOrderAction(paymentData, false); - - $.when(placeOrder) - .fail(function () { - self.isPlaceOrderActionAllowed(true); - //self.unblock(); - }) - .done(function () { - self.afterPlaceOrder(); - }); - return false; - } catch (e) { - alert(e); - self.isPlaceOrderActionAllowed(true); - } - }, - /** - * Get list of available Payment Types values - * @returns {Object} - */ - getPaymentTypeValues: function () { - return _.map(this.getPaymentTypes(), function (key, value) { - return { - 'value': value, - 'text': key - }; - }); - }, - /** - * Get list of available Payment Types - * @returns {Object} - */ - getPaymentTypes: function () { - return { - '30_days':'30 days', - '3_months':'3 months', - '6_months':'6 months', - '12_months':'12 months' - }; } }); } diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/kredivo.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/kredivo.js index b63da19c..cbc78296 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/kredivo.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/kredivo.js @@ -1,75 +1,16 @@ define( [ - 'jquery', - 'Xendit_M2Invoice/js/view/payment/method-renderer/kredivo', - 'utility' + 'Xendit_M2Invoice/js/view/payment/method-renderer/kredivo' ], function ( - $, - Component, - utility - ) { + Component + ) { 'use strict'; return Component.extend({ defaults: { - template: 'Xendit_M2Invoice/payment/multishipping/kredivo', + template: 'Xendit_M2Invoice/payment/multishipping/description', redirectAfterPlaceOrder: false, - }, - - placeOrder: function () { - this.isPlaceOrderActionAllowed(false); - var self = this; - - try { - let errorMessageBlock = $(".messages .message-error div"); - let messageBlock = $(".messages"); - // hide error message block - errorMessageBlock.html(""); - messageBlock.hide(); - - var kredivoPaymentType = $('#kredivo_payment_type').val(); - - if (!kredivoPaymentType || kredivoPaymentType === "") { - errorMessageBlock.html("Please select a payment type first."); - messageBlock.show(); - self.isPlaceOrderActionAllowed(true); // enable "pay now" button - return false; - } - // set the cookie value - utility.setCookie('xendit_payment_type',kredivoPaymentType,true); - - $('#multishipping-billing-form').submit(); - - return true; - } catch (e) { - alert(e); - self.isPlaceOrderActionAllowed(true); - } - }, - /** - * Get list of available Payment Types values - * @returns {Object} - */ - getPaymentTypeValues: function () { - return _.map(this.getPaymentTypes(), function (key, value) { - return { - 'value': value, - 'text': key - }; - }); - }, - /** - * Get list of available Payment Types - * @returns {Object} - */ - getPaymentTypes: function () { - return { - '30_days':'30 days', - '3_months':'3 months', - '6_months':'6 months', - '12_months':'12 months' - }; } }); } diff --git a/Xendit/M2Invoice/view/frontend/web/template/payment/kredivo-form.html b/Xendit/M2Invoice/view/frontend/web/template/payment/kredivo-form.html deleted file mode 100644 index 44c82ab0..00000000 --- a/Xendit/M2Invoice/view/frontend/web/template/payment/kredivo-form.html +++ /dev/null @@ -1,23 +0,0 @@ -
-
-
- - -
-
-
\ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/web/template/payment/kredivo.html b/Xendit/M2Invoice/view/frontend/web/template/payment/kredivo.html deleted file mode 100644 index b0865f67..00000000 --- a/Xendit/M2Invoice/view/frontend/web/template/payment/kredivo.html +++ /dev/null @@ -1,38 +0,0 @@ -
-
- - -
-
-
-
- - -
-
- -
-
-
- -
-
-
-
\ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/web/template/payment/multishipping/kredivo.html b/Xendit/M2Invoice/view/frontend/web/template/payment/multishipping/kredivo.html deleted file mode 100644 index 2413432f..00000000 --- a/Xendit/M2Invoice/view/frontend/web/template/payment/multishipping/kredivo.html +++ /dev/null @@ -1,23 +0,0 @@ -
-
-
-
- - -
- - - -
-
- -
-
-
-
- diff --git a/docker/README.md b/docker/README.md index 5a525e9d..d4ed9372 100644 --- a/docker/README.md +++ b/docker/README.md @@ -68,6 +68,7 @@ php bin/magento setup:install \ Magento 2.4 ``` php bin/magento setup:install \ +--cleanup-database \ --admin-firstname=Admin \ --admin-lastname=TPI \ --admin-email=tpi@admin.com \