From d66024a043893f39c03cc7878843303e1b2e411a Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Thu, 10 Sep 2020 20:23:16 +0700 Subject: [PATCH 01/49] add subscription callback & create order function --- .../Checkout/SubscriptionCallback.m22.php | 177 ++++++++++++++++ .../Checkout/SubscriptionCallback.m23.php | 191 ++++++++++++++++++ .../Checkout/SubscriptionCallback.php | 9 + Xendit/M2Invoice/Helper/Data.php | 161 ++++++++++++++- Xendit/M2Invoice/Model/Payment/CC.php | 22 +- 5 files changed, 552 insertions(+), 8 deletions(-) create mode 100644 Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php create mode 100644 Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php create mode 100644 Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.php diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php new file mode 100644 index 00000000..4bb7f0da --- /dev/null +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php @@ -0,0 +1,177 @@ +getJsonResultFactory()->create(); + + try { + $post = $this->getRequest()->getContent(); + $payload = json_decode($post, true); + + $invoiceId = $payload['id']; + $chargeId = $payload['credit_card_charge_id']; + + //verify callback + $callback = $this->getCallbackByInvoiceId($invoiceId); + if (isset($callback['error_code']) || !isset($callback['status'])) { + $result->setData([ + 'status' => __('ERROR'), + 'message' => (!empty($callback['error_code']) ?: 'Callback not found') + ]); + + return $result; + } else if ($callback['status'] == 'COMPLETED') { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Callback already processed' + ]); + + return $result; + } + + //verify charge + $charge = $this->getCreditCardCharge($chargeId); //child charge + if ($charge['status'] != 'CAPTURED' && $charge['status'] != 'SETTLED') { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Charge is ' . $charge['status'] + ]); + + return $result; + } + + $childTokenId = $charge['token_id']; //currently endpoint doesn't return token_id + + $orderIds = explode('-', $payload['description']); //parent order id(s) + $isTokenMatched = false; + + foreach ($orderIds as $key => $value) { + $order = $this->getOrderFactory()->create(); + $order->load($value); + $payment = $order->getPayment(); + + //match token id of parent & child's order just once + if (!$isTokenMatched) { + $parentTokenId = $payment->getAdditionalInformation('token_id'); + if ($parentTokenId == $childTokenId) { + $isTokenMatched = true; + } + else { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Token mismatched' + ]); + + return $result; + } + } + + $billing = $order->getBillingAddress(); + $shipping = $order->getShippingAddress(); + + //create items array + $items = array(); + $allItems = $order->getAllItems(); + foreach ($allItems as $product) { + array_push($items, array( + 'product_id' => $product->getProductId(), + 'qty' => $product->getQtyOrdered(), + 'price' => $product->getPrice() + )); + } + + $orderData = array( + 'currency_id' => $order->getBaseCurrencyCode(), + 'email' => $order->getCustomerEmail(), + 'billing_address' => array( + 'firstname' => $order->getCustomerFirstname(), + 'lastname' => $order->getCustomerLastname(), + 'street' => $billing->getStreetLine(1), + 'city' => $billing->getCity(), + 'country_id' => $billing->getCountryId(), + 'region' => $billing->getRegion(), + 'postcode' => $billing->getPostcode(), + 'telephone' => $billing->getTelephone(), + 'fax' => $billing->getFax(), + 'save_in_address_book' => 0 + ), + 'shipping_address' => array( + 'firstname' => $order->getCustomerFirstname(), + 'lastname' => $order->getCustomerLastname(), + 'street' => $shipping->getStreetLine(1), + 'city' => $shipping->getCity(), + 'country_id' => $shipping->getCountryId(), + 'region' => $shipping->getRegion(), + 'postcode' => $shipping->getPostcode(), + 'telephone' => $shipping->getTelephone(), + 'fax' => $shipping->getFax(), + 'save_in_address_book' => 0 + ), + 'shipping_method' => $order->getShippingMethod(), + 'items' => $items, + 'payment' => $payment->getData(), + 'transaction_id' => $chargeId, + 'is_multishipping' => (count($orderIds) > 1 ? true : false) + ); + + //create order + $this->getObjectManager()->get('Xendit\M2Invoice\Helper\Data')->createMageOrder($orderData); + } + + $result->setData([ + 'status' => __('OK'), + 'message' => 'Callback processed successfully.' + ]); + + return $result; + } catch (\Exception $e) { + $result->setHttpResponseCode(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST); + $result->setData([ + 'status' => __('ERROR'), + 'message' => $e->getMessage() + ]); + + return $result; + } + } + + private function getCallbackByInvoiceId($invoiceId) + { + $url = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/callbacks/invoice/" . $invoiceId; + $method = \Zend\Http\Request::METHOD_GET; + + try { + $response = $this->getApiHelper()->request( + $url, $method + ); + + return $response; + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase($e->getMessage()) + ); + } + } + + private function getCreditCardCharge($chargeId) + { + $url = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/credit-card/charges/" . $chargeId; + $method = \Zend\Http\Request::METHOD_GET; + + try { + $response = $this->getApiHelper()->request( + $url, $method + ); + + return $response; + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase($e->getMessage()) + ); + } + } +} diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php new file mode 100644 index 00000000..7fde4d06 --- /dev/null +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php @@ -0,0 +1,191 @@ +getJsonResultFactory()->create(); + + try { + $post = $this->getRequest()->getContent(); + $payload = json_decode($post, true); + + $invoiceId = $payload['id']; + $chargeId = $payload['credit_card_charge_id']; + + //verify callback + $callback = $this->getCallbackByInvoiceId($invoiceId); + if (isset($callback['error_code']) || !isset($callback['status'])) { + $result->setData([ + 'status' => __('ERROR'), + 'message' => (!empty($callback['error_code']) ?: 'Callback not found') + ]); + + return $result; + } else if ($callback['status'] == 'COMPLETED') { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Callback already processed' + ]); + + return $result; + } + + //verify charge + $charge = $this->getCreditCardCharge($chargeId); //child charge + if ($charge['status'] != 'CAPTURED' && $charge['status'] != 'SETTLED') { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Charge is ' . $charge['status'] + ]); + + return $result; + } + + $childTokenId = $charge['token_id']; //currently endpoint doesn't return token_id + + $orderIds = explode('-', $payload['description']); //parent order id(s) + $isTokenMatched = false; + + foreach ($orderIds as $key => $value) { + $order = $this->getOrderFactory()->create(); + $order->load($value); + $payment = $order->getPayment(); + + //match token id of parent & child's order just once + if (!$isTokenMatched) { + $parentTokenId = $payment->getAdditionalInformation('token_id'); + if ($parentTokenId == $childTokenId) { + $isTokenMatched = true; + } + else { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Token mismatched' + ]); + + return $result; + } + } + + $billing = $order->getBillingAddress(); + $shipping = $order->getShippingAddress(); + + //create items array + $items = array(); + $allItems = $order->getAllItems(); + foreach ($allItems as $product) { + array_push($items, array( + 'product_id' => $product->getProductId(), + 'qty' => $product->getQtyOrdered(), + 'price' => $product->getPrice() + )); + } + + $orderData = array( + 'currency_id' => $order->getBaseCurrencyCode(), + 'email' => $order->getCustomerEmail(), + 'billing_address' => array( + 'firstname' => $order->getCustomerFirstname(), + 'lastname' => $order->getCustomerLastname(), + 'street' => $billing->getStreetLine(1), + 'city' => $billing->getCity(), + 'country_id' => $billing->getCountryId(), + 'region' => $billing->getRegion(), + 'postcode' => $billing->getPostcode(), + 'telephone' => $billing->getTelephone(), + 'fax' => $billing->getFax(), + 'save_in_address_book' => 0 + ), + 'shipping_address' => array( + 'firstname' => $order->getCustomerFirstname(), + 'lastname' => $order->getCustomerLastname(), + 'street' => $shipping->getStreetLine(1), + 'city' => $shipping->getCity(), + 'country_id' => $shipping->getCountryId(), + 'region' => $shipping->getRegion(), + 'postcode' => $shipping->getPostcode(), + 'telephone' => $shipping->getTelephone(), + 'fax' => $shipping->getFax(), + 'save_in_address_book' => 0 + ), + 'shipping_method' => $order->getShippingMethod(), + 'items' => $items, + 'payment' => $payment->getData(), + 'transaction_id' => $chargeId, + 'is_multishipping' => (count($orderIds) > 1 ? true : false) + ); + + //create order + $this->getObjectManager()->get('Xendit\M2Invoice\Helper\Data')->createMageOrder($orderData); + } + + $result->setData([ + 'status' => __('OK'), + 'message' => 'Callback processed successfully.' + ]); + + return $result; + } catch (\Exception $e) { + $result->setHttpResponseCode(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST); + $result->setData([ + 'status' => __('ERROR'), + 'message' => $e->getMessage() + ]); + + return $result; + } + } + + private function getCallbackByInvoiceId($invoiceId) + { + $url = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/callbacks/invoice/" . $invoiceId; + $method = \Zend\Http\Request::METHOD_GET; + + try { + $response = $this->getApiHelper()->request( + $url, $method + ); + + return $response; + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new LocalizedException( + __($e->getMessage()) + ); + } + } + + private function getCreditCardCharge($chargeId) + { + $url = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/credit-card/charges/" . $chargeId; + $method = \Zend\Http\Request::METHOD_GET; + + try { + $response = $this->getApiHelper()->request( + $url, $method + ); + + return $response; + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new LocalizedException( + __($e->getMessage()) + ); + } + } + + public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException + { + return null; + } + + public function validateForCsrf(RequestInterface $request): ?bool + { + return true; + } +} diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.php new file mode 100644 index 00000000..dfcfa68e --- /dev/null +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.php @@ -0,0 +1,9 @@ +objectManager = $objectManager; $this->storeManager = $storeManager; $this->m2Invoice = $m2Invoice; $this->fileSystem = $fileSystem; + $this->product = $product; + $this->customerRepository = $customerRepository; + $this->customerFactory = $customerFactory; + $this->quote = $quote; + $this->quoteManagement = $quoteManagement; parent::__construct($context); } @@ -227,4 +253,137 @@ public function xenditPaymentMethod( $payment ){ return $response; } + + /** + * Create Order Programatically + * + * @param array $orderData + * @return array + * + */ + public function createMageOrder($orderData) { + $store = $this->getStoreManager()->getStore(); + $websiteId = $this->getStoreManager()->getStore()->getWebsiteId(); + + $customer = $this->customerFactory->create(); + $customer->setWebsiteId($websiteId); + $customer->loadByEmail($orderData['email']); //load customer by email address + + if(!$customer->getEntityId()){ + //if not available then create this customer + $customer->setWebsiteId($websiteId) + ->setStore($store) + ->setFirstname($orderData['shipping_address']['firstname']) + ->setLastname($orderData['shipping_address']['lastname']) + ->setEmail($orderData['email']) + ->setPassword($orderData['email']); + $customer->save(); + } + + $quote = $this->quote->create(); //create object of quote + $quote->setStore($store); + + $customer= $this->customerRepository->getById($customer->getEntityId()); + $quote->setCurrency(); + $quote->assignCustomer($customer); //assign quote to customer + + //add items in quote + foreach($orderData['items'] as $item){ + $product = $this->product->load($item['product_id']); + $product->setPrice($item['price']); + + $normalizedProductRequest = array_merge( + ['qty' => intval($item['qty'])], + array() + ); + $quote->addProduct( + $product, + new DataObject($normalizedProductRequest) + ); + } + + //set address + $quote->getBillingAddress()->addData($orderData['billing_address']); + $quote->getShippingAddress()->addData($orderData['shipping_address']); + + //collect rates, set shipping & payment method + $billingAddress = $quote->getBillingAddress(); + $shippingAddress = $quote->getShippingAddress(); + + $shippingAddress->setShippingMethod($orderData['shipping_method']) + ->setCollectShippingRates(true) + ->collectShippingRates(); + + $billingAddress->setShouldIgnoreValidation(true); + $shippingAddress->setShouldIgnoreValidation(true); + + $quote->collectTotals(); + $quote->setIsMultiShipping($orderData['is_multishipping']); + + if (!$quote->getIsVirtual()) { + if (!$billingAddress->getEmail()) { + $billingAddress->setSameAsBilling(1); + } + } + + $quote->setPaymentMethod($orderData['payment']['method']); + $quote->setInventoryProcessed(true); //update inventory + $quote->save(); + + //set required payment data + $orderData['payment']['cc_number'] = str_replace('X', '0', $orderData['payment']['additional_information']['masked_card_number']); + $orderData['payment']['cc_cid'] = $orderData['payment']['additional_information']['cc_cid']; + $quote->getPayment()->importData($orderData['payment']); + + foreach($orderData['payment']['additional_information'] AS $key=>$value) { + $quote->getPayment()->setAdditionalInformation($key, $value); + } + + //collect totals & save quote + $quote->collectTotals()->save(); + + //create order from quote + $order = $this->quoteManagement->submit($quote); + + //update order status + $orderState = \Magento\Sales\Model\Order::STATE_PROCESSING; + $message = "Xendit subscription payment completed. Transaction ID: " . $orderData['transaction_id'] . "."; + $message .= "Original Order: #" . $order->getRealOrderId() . "."; + $order->setState($orderState) + ->setStatus($orderState) + ->addStatusHistoryComment($message); + + $order->setEmailSent(0); + $order->save(); + + //save order payment details + $payment = $order->getPayment(); + $payment->setTransactionId($orderData['transaction_id']); + $payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE, null, true); + + //create invoice + if ($order->canInvoice()) { + $invoice = $this->objectManager->create('Magento\Sales\Model\Service\InvoiceService') + ->prepareInvoice($order); + + if ($invoice->getTotalQty()) { + $invoice->setTransactionId($orderData['transaction_id']); + $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_OFFLINE); + $invoice->register(); + + $transaction = $this->objectManager->create('Magento\Framework\DB\Transaction') + ->addObject($invoice) + ->addObject($invoice->getOrder()); + $transaction->save(); + } + } + + if($order->getEntityId()){ + $result['order_id'] = $order->getRealOrderId(); + }else{ + $result = array('error' => 1, 'msg' => 'Error creating order'); + } + + return $result; + } } diff --git a/Xendit/M2Invoice/Model/Payment/CC.php b/Xendit/M2Invoice/Model/Payment/CC.php index 3627a054..ffbe4b51 100644 --- a/Xendit/M2Invoice/Model/Payment/CC.php +++ b/Xendit/M2Invoice/Model/Payment/CC.php @@ -181,7 +181,11 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount) { $payment->setIsTransactionPending(true); - $additionalData = $this->getAdditionalData(); + $additionalData = $this->getAdditionalData(); + + if (!$additionalData) { //coming from callback - no need to process & charge the order + return $this; + } $order = $payment->getOrder(); $quoteId = $order->getQuoteId(); @@ -193,8 +197,8 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount $orderId = $order->getRealOrderId(); - $cvn = isset($additionalData['cc_cid']) ? $additionalData['cc_cid'] : null; - $bin = isset($additionalData['cc_number']) ? substr($additionalData['cc_number'], 0, 6) : null; + $cvn = !empty($additionalData['cc_cid']) ? $additionalData['cc_cid'] : null; + $bin = !empty($additionalData['cc_number']) ? substr($additionalData['cc_number'], 0, 6) : null; try { $promoResult = $this->calculatePromo($bin, $order); @@ -235,8 +239,9 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount 'type' => $this->dataHelper->mapSalesRuleType($promoResult['rule']->getSimpleAction()) )); } - + $charge = $this->requestCharge($requestData); + $chargeError = isset($charge['error_code']) ? $charge['error_code'] : null; if ($chargeError == 'EXTERNAL_ID_ALREADY_USED_ERROR') { @@ -245,13 +250,16 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount )); $charge = $this->requestCharge($newRequestData); } - - $chargeError = isset($charge['error_code']) ? $charge['error_code'] : null; - if ($chargeError == 'AUTHENTICATION_ID_MISSING_ERROR') { + else if ($chargeError == 'AUTHENTICATION_ID_MISSING_ERROR') { $this->handle3DSFlow($requestData, $payment, $order); return $this; } + else if ($chargeError) { + throw new \Magento\Framework\Exception\LocalizedException( + __($charge['message']) + ); + } if ($chargeError !== null) { $this->processFailedPayment($order, $payment, $charge); From c96e04c4a1b1c4f57adad4f59a9d8bc867181eab Mon Sep 17 00:00:00 2001 From: candra saputra Date: Fri, 11 Sep 2020 09:15:42 +0700 Subject: [PATCH 02/49] subscription --- .gitignore | 4 +- .../Controller/Payment/OverviewPost.php | 2 +- Xendit/M2Invoice/Helper/Data.php | 1 + .../Model/Adminhtml/Source/ChosenMethod.php | 1 + .../Adminhtml/Source/SubscriptionInterval.php | 21 +++ .../Model/Payment/AbstractInvoice.php | 2 +- .../Model/Payment/CCSubscription.php | 145 ++++++++++++++++++ Xendit/M2Invoice/etc/adminhtml/system.xml | 14 ++ Xendit/M2Invoice/etc/config.xml | 11 +- Xendit/M2Invoice/etc/payment.xml | 3 + .../layout/multishipping_checkout_billing.xml | 1 + .../multishipping/cc_subscription.phtml | 29 ++++ .../web/js/view/payment/method-renderer.js | 4 + .../method-renderer/cc_subscription.js | 29 ++++ .../multishipping/cc_subscription.js | 17 ++ 15 files changed, 280 insertions(+), 4 deletions(-) create mode 100644 Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php create mode 100644 Xendit/M2Invoice/Model/Payment/CCSubscription.php create mode 100644 Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml create mode 100644 Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js create mode 100644 Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/cc_subscription.js diff --git a/.gitignore b/.gitignore index 951d6b85..12afa309 100644 --- a/.gitignore +++ b/.gitignore @@ -87,4 +87,6 @@ fabric.properties *.zip -telepresence.log \ No newline at end of file +telepresence.log + +.DS_Store \ No newline at end of file diff --git a/Xendit/M2Invoice/Controller/Payment/OverviewPost.php b/Xendit/M2Invoice/Controller/Payment/OverviewPost.php index 5f7d2ce2..f8a9182a 100755 --- a/Xendit/M2Invoice/Controller/Payment/OverviewPost.php +++ b/Xendit/M2Invoice/Controller/Payment/OverviewPost.php @@ -112,7 +112,7 @@ public function execute() $params = implode("-", $ids); $baseUrl = $this->_objectManager->get('\Magento\Store\Model\StoreManagerInterface')->getStore()->getBaseUrl(); - if ($xenditPaymentMethod === 'cc' || $xenditPaymentMethod === 'cchosted' || $xenditPaymentMethod === 'cc_installment') { + if ($xenditPaymentMethod === 'cc' || $xenditPaymentMethod === 'cchosted' || $xenditPaymentMethod === 'cc_installment' || $xenditPaymentMethod === 'cc_subscription') { $redirect = $baseUrl . '/xendit/checkout/ccmultishipping?order_ids=' . $params . '&preferred_method=' . $xenditPaymentMethod; } else { $redirect = $baseUrl . '/xendit/checkout/invoicemultishipping?order_ids=' . $params.'&preferred_method='.$xenditPaymentMethod.'&billing_email='.$billingEmail; diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index 66c118db..d9e2ba4b 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -211,6 +211,7 @@ public function xenditPaymentMethod( $payment ){ "cc" => "cc", "cchosted" => "cchosted", "cc_installment" => "cc_installment", + "cc_subscription" => "cc_subscription", "bcava" => "bca", "bniva" => "bni", "briva" => "bri", diff --git a/Xendit/M2Invoice/Model/Adminhtml/Source/ChosenMethod.php b/Xendit/M2Invoice/Model/Adminhtml/Source/ChosenMethod.php index a867578c..01520409 100644 --- a/Xendit/M2Invoice/Model/Adminhtml/Source/ChosenMethod.php +++ b/Xendit/M2Invoice/Model/Adminhtml/Source/ChosenMethod.php @@ -27,6 +27,7 @@ public function toOptionArray($isMultiselect = false) ['value' => 'permatava', 'label' => __('Bank Transfer Permata')], ['value' => 'cc', 'label' => __('Credit Card')], ['value' => 'cc_installment', 'label' => __('Credit Card Installment')], + ['value' => 'cc_subscription', 'label' => __('Credit Card Subscription')], ['value' => 'ovo', 'label' => __('OVO')], ]; diff --git a/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php b/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php new file mode 100644 index 00000000..65e2e044 --- /dev/null +++ b/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php @@ -0,0 +1,21 @@ + 'MONTH', 'label' => __('MONTH')], + ['value' => 'WEEK', 'label' => __('WEEK')], + ['value' => 'DAY', 'label' => __('DAY')] + ]; + } +} diff --git a/Xendit/M2Invoice/Model/Payment/AbstractInvoice.php b/Xendit/M2Invoice/Model/Payment/AbstractInvoice.php index daad47c4..46131266 100755 --- a/Xendit/M2Invoice/Model/Payment/AbstractInvoice.php +++ b/Xendit/M2Invoice/Model/Payment/AbstractInvoice.php @@ -108,7 +108,7 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) $cardPaymentType = $this->dataHelper->getCardPaymentType(); - if (($cardPaymentType === 'popup' && $this->methodCode === 'CCHOSTED') || $this->methodCode === 'CC_INSTALLMENT') { + if (($cardPaymentType === 'popup' && $this->methodCode === 'CCHOSTED') || $this->methodCode === 'CC_INSTALLMENT' || $this->methodCode === 'CC_SUBSCRIPTION') { return true; } diff --git a/Xendit/M2Invoice/Model/Payment/CCSubscription.php b/Xendit/M2Invoice/Model/Payment/CCSubscription.php new file mode 100644 index 00000000..16fac52f --- /dev/null +++ b/Xendit/M2Invoice/Model/Payment/CCSubscription.php @@ -0,0 +1,145 @@ +setIsTransactionPending(true); + + $order = $payment->getOrder(); + $quoteId = $order->getQuoteId(); + $quote = $this->quoteRepository->get($quoteId); + + if ($quote->getIsMultiShipping()) { + return $this; + } + + try { + $orderId = $order->getRealOrderId(); + + $billingAddress = $order->getBillingAddress(); + $shippingAddress = $order->getShippingAddress(); + + $firstName = $billingAddress->getFirstname() ?: $shippingAddress->getFirstname(); + $country = $billingAddress->getCountryId() ?: $shippingAddress->getCountryId(); + $billingDetails = array( + 'given_names' => ($firstName ?: 'N/A'), + 'surname' => ($billingAddress->getLastname() ?: null), + 'email' => ($billingAddress->getEmail() ?: null), + 'phone_number' => ($billingAddress->getTelephone() ?: null), + 'address' => array( + 'country' => ($country ?: 'ID'), + 'street_line_1' => ($billingAddress->getStreetLine(1) ?: null), + 'street_line_2' => ($billingAddress->getStreetLine(2) ?: null), + 'city' => ($billingAddress->getCity() ?: null), + 'state' => ($billingAddress->getRegion() ?: null), + 'postal_code' => ($billingAddress->getPostcode() ?: null) + ) + ); + + $rawAmount = ceil($order->getSubtotal() + $order->getShippingAmount()); + + $args = array( + 'order_number' => $orderId, + 'amount' => $amount, + 'payment_type' => self::PAYMENT_TYPE, + 'store_name' => $this->storeManager->getStore()->getName(), + 'platform_name' => self::PLATFORM_NAME, + 'is_subscription' => "true", + 'subscription_callback_url' => '', + 'platform_callback_url' => '', + 'payer_email' => '', + 'subscription_option' => json_encode(array( + 'interval' => '', + 'interval_count' => '' + ), JSON_FORCE_OBJECT), + 'billing_details' => json_encode($billingDetails, JSON_FORCE_OBJECT) + ); + + $promo = $this->calculatePromo($order, $rawAmount); + + if (!empty($promo)) { + $args['promotions'] = json_encode($promo); + $args['amount'] = $rawAmount; + + $invalidDiscountAmount = $order->getBaseDiscountAmount(); + $order->setBaseDiscountAmount(0); + $order->setBaseGrandTotal($order->getBaseGrandTotal() - $invalidDiscountAmount); + + $invalidDiscountAmount = $order->getDiscountAmount(); + $order->setDiscountAmount(0); + $order->setGrandTotal($order->getGrandTotal() - $invalidDiscountAmount); + + $order->setBaseTotalDue($order->getBaseGrandTotal()); + $order->setTotalDue($order->getGrandTotal()); + + $payment->setBaseAmountOrdered($order->getBaseGrandTotal()); + $payment->setAmountOrdered($order->getGrandTotal()); + + $payment->setAmountAuthorized($order->getGrandTotal()); + $payment->setBaseAmountAuthorized($order->getBaseGrandTotal()); + } + + $hostedPayment = $this->requestHostedPayment($args); + + if (isset($hostedPayment['error_code'])) { + $message = isset($hostedPayment['message']) ? $hostedPayment['message'] : $hostedPayment['error_code']; + $this->processFailedPayment($payment, $message); + + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase($message) + ); + } elseif (isset($hostedPayment['id'])) { + $hostedPaymentId = $hostedPayment['id']; + $hostedPaymentToken = $hostedPayment['hp_token']; + + $payment->setAdditionalInformation('xendit_hosted_payment_id', $hostedPaymentId); + $payment->setAdditionalInformation('xendit_hosted_payment_token', $hostedPaymentToken); + } else { + $message = 'Error connecting to Xendit. Check your API key'; + $this->processFailedPayment($payment, $message); + + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase($message) + ); + } + } catch (\Exception $e) { + $errorMsg = $e->getMessage(); + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase($errorMsg) + ); + } + + return $this; + } +} \ No newline at end of file diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index 7b9b9f5c..fc2b9ca5 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -178,6 +178,20 @@ Customize your installment payment description on checkout page + + + + The frequency with which a subscription payment invoice should be billed. + + Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval + + + + + + The number of intervals (specified in the interval property) between subscription. + + diff --git a/Xendit/M2Invoice/etc/config.xml b/Xendit/M2Invoice/etc/config.xml index 879e4251..f0eb956e 100644 --- a/Xendit/M2Invoice/etc/config.xml +++ b/Xendit/M2Invoice/etc/config.xml @@ -107,6 +107,15 @@ VI,MC,AE,JCB 9 + + 1 + authorize + Xendit\M2Invoice\Model\Payment\CCSubscription + Credit Card Subscription + pending_payment + VI,MC,AE,JCB + 10 + 1 authorize @@ -115,7 +124,7 @@ 1 1 1 - 10 + 11 diff --git a/Xendit/M2Invoice/etc/payment.xml b/Xendit/M2Invoice/etc/payment.xml index b05165b2..4e282fec 100644 --- a/Xendit/M2Invoice/etc/payment.xml +++ b/Xendit/M2Invoice/etc/payment.xml @@ -36,6 +36,9 @@ https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Multishipp 1 + + 1 + 1 diff --git a/Xendit/M2Invoice/view/frontend/layout/multishipping_checkout_billing.xml b/Xendit/M2Invoice/view/frontend/layout/multishipping_checkout_billing.xml index 88d366fd..67aac533 100644 --- a/Xendit/M2Invoice/view/frontend/layout/multishipping_checkout_billing.xml +++ b/Xendit/M2Invoice/view/frontend/layout/multishipping_checkout_billing.xml @@ -14,6 +14,7 @@ Xendit_M2Invoice::multishipping/cc.phtml Xendit_M2Invoice::multishipping/cchosted.phtml Xendit_M2Invoice::multishipping/cc_installment.phtml + Xendit_M2Invoice::multishipping/cc_subscription.phtml Xendit_M2Invoice::multishipping/alfamart.phtml Xendit_M2Invoice::multishipping/bcava.phtml Xendit_M2Invoice::multishipping/bniva.phtml diff --git a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml new file mode 100644 index 00000000..a0f595c4 --- /dev/null +++ b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml @@ -0,0 +1,29 @@ + + + \ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer.js index ee4375a7..2e68f317 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer.js @@ -49,6 +49,10 @@ define( { type: 'cc_installment', component: 'Xendit_M2Invoice/js/view/payment/method-renderer/cc_installment' + }, + { + type: 'cc_subscription', + component: 'Xendit_M2Invoice/js/view/payment/method-renderer/cc_subscription' } ); return Component.extend({}); diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js new file mode 100644 index 00000000..f26507de --- /dev/null +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js @@ -0,0 +1,29 @@ +define( + [ + 'Xendit_M2Invoice/js/view/payment/method-renderer/cchosted' + ], + function ( + Component + ) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Xendit_M2Invoice/payment/cc-hosted', + redirectAfterPlaceOrder: false + }, + + getCode: function() { + return 'cc_subscription'; + }, + + getMethod: function() { + return 'CC_SUBSCRIPTION'; + }, + + getDescription: function() { + return window.checkoutConfig.payment.m2invoice.card_subscription_description; + } + }); + } +); \ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/cc_subscription.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/cc_subscription.js new file mode 100644 index 00000000..b846c9bc --- /dev/null +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/multishipping/cc_subscription.js @@ -0,0 +1,17 @@ +define( + [ + 'Xendit_M2Invoice/js/view/payment/method-renderer/cc_subscription' + ], + function ( + Component + ) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Xendit_M2Invoice/payment/multishipping/description', + redirectAfterPlaceOrder: false + } + }); + } +); \ No newline at end of file From 0e3777d40c10040b42ba337910180067164d2261 Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Fri, 11 Sep 2020 11:01:22 +0700 Subject: [PATCH 03/49] notify customer after order is created --- .../M2Invoice/Controller/Checkout/CCCallback.m22.php | 4 ---- .../M2Invoice/Controller/Checkout/CCCallback.m23.php | 4 ---- .../Controller/Checkout/SubscriptionCallback.m22.php | 1 + .../Controller/Checkout/SubscriptionCallback.m23.php | 1 + Xendit/M2Invoice/Helper/Data.php | 10 +++++++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCCallback.m22.php b/Xendit/M2Invoice/Controller/Checkout/CCCallback.m22.php index 9b24845d..0f99f455 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCCallback.m22.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCCallback.m22.php @@ -11,10 +11,6 @@ class CCCallback extends ProcessHosted public function execute() { try { - $post = $this->getRequest()->getContent(); - $callbackToken = $this->getRequest()->getHeader('X-CALLBACK-TOKEN'); - $decodedPost = json_decode($post, true); - $orderIds = explode('-', $this->getRequest()->getParam('order_ids')); $shouldRedirect = false; diff --git a/Xendit/M2Invoice/Controller/Checkout/CCCallback.m23.php b/Xendit/M2Invoice/Controller/Checkout/CCCallback.m23.php index 76034443..2af30984 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCCallback.m23.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCCallback.m23.php @@ -15,10 +15,6 @@ class CCCallback extends ProcessHosted implements CsrfAwareActionInterface public function execute() { try { - $post = $this->getRequest()->getContent(); - $callbackToken = $this->getRequest()->getHeader('X-CALLBACK-TOKEN'); - $decodedPost = json_decode($post, true); - $orderIds = explode('-', $this->getRequest()->getParam('order_ids')); $shouldRedirect = false; diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php index 4bb7f0da..f276bed8 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php @@ -115,6 +115,7 @@ public function execute() 'items' => $items, 'payment' => $payment->getData(), 'transaction_id' => $chargeId, + 'parent_order_id' => $order->getRealOrderId(), 'is_multishipping' => (count($orderIds) > 1 ? true : false) ); diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php index 7fde4d06..56a9d779 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php @@ -119,6 +119,7 @@ public function execute() 'items' => $items, 'payment' => $payment->getData(), 'transaction_id' => $chargeId, + 'parent_order_id' => $order->getRealOrderId(), 'is_multishipping' => (count($orderIds) > 1 ? true : false) ); diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index 434b8bd9..c50776ea 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -347,13 +347,12 @@ public function createMageOrder($orderData) { //update order status $orderState = \Magento\Sales\Model\Order::STATE_PROCESSING; - $message = "Xendit subscription payment completed. Transaction ID: " . $orderData['transaction_id'] . "."; - $message .= "Original Order: #" . $order->getRealOrderId() . "."; + $message = "Xendit subscription payment completed. Transaction ID: " . $orderData['transaction_id'] . ". "; + $message .= "Original Order: #" . $orderData['parent_order_id'] . "."; $order->setState($orderState) ->setStatus($orderState) ->addStatusHistoryComment($message); - $order->setEmailSent(0); $order->save(); //save order payment details @@ -378,6 +377,11 @@ public function createMageOrder($orderData) { } } + //notify customer + $this->objectManager->create('Magento\Sales\Model\OrderNotifier')->notify($order); + $order->setEmailSent(1); + $order->save(); + if($order->getEntityId()){ $result['order_id'] = $order->getRealOrderId(); }else{ From 6f462f75f3f666922af675fc9bf6907c41b76548 Mon Sep 17 00:00:00 2001 From: candra saputra Date: Mon, 14 Sep 2020 07:20:27 +0700 Subject: [PATCH 04/49] process payment --- .../Controller/Checkout/CCMultishipping.php | 12 ++++- Xendit/M2Invoice/Helper/Data.php | 10 +++++ .../Model/Payment/CCSubscription.php | 44 ++++++++++--------- Xendit/M2Invoice/Model/Payment/M2Invoice.php | 8 ++++ Xendit/M2Invoice/etc/adminhtml/system.xml | 1 - .../multishipping/cc_installment.phtml | 2 +- .../multishipping/cc_subscription.phtml | 2 +- .../method-renderer/cc_subscription.js | 2 +- 8 files changed, 55 insertions(+), 26 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index e6aa0e69..eabc1be9 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -5,6 +5,7 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Sales\Model\Order; use Xendit\M2Invoice\Enum\LogDNALevel; +use Magento\Framework\UrlInterface; class CCMultishipping extends AbstractAction { @@ -76,7 +77,7 @@ public function execute() return $this->processFailedPayment($orderIds, $charge['failure_reason']); } } - else if ($method === 'cchosted' || $method === 'cc_installment') { + else if ($method === 'cchosted' || $method === 'cc_installment' || $method === 'cc_subscription') { $requestData = array( 'order_number' => $rawOrderIds, 'amount' => $transactionAmount, @@ -111,6 +112,15 @@ public function execute() $requestData['is_installment'] = "true"; $requestData['billing_details'] = json_encode($billingDetails, JSON_FORCE_OBJECT); + } else if ($method === 'cc_subscription') { + $requestData['payment_type'] = 'CREDIT_CARD_SUBSCRIPTION'; + $requestData['is_subscription'] = "true"; + $requestData['subscription_callback_url'] = $this->getStoreManager()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK) . 'xendit/checkout/subscriptioncallback'; + $requestData['payer_email'] = $billingAddress->getEmail(); + $requestData['subscription_option'] = json_encode(array( + 'interval' => $this->getDataHelper()->getSubscriptionInterval(), + 'interval_count' => $this->getDataHelper()->getSubscriptionIntervalCount() + ), JSON_FORCE_OBJECT); } $hostedPayment = $this->requestHostedPayment($requestData); diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index d9e2ba4b..b909c0da 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -100,6 +100,16 @@ public function getPublicApiKey() return $this->m2Invoice->getPublicApiKey(); } + public function getSubscriptionInterval() + { + return $this->m2Invoice->getSubscriptionInterval() ?: 'MONTH'; + } + + public function getSubscriptionIntervalCount() + { + return $this->m2Invoice->getSubscriptionIntervalCount() ?: 1; + } + public function getEnvironment() { return $this->m2Invoice->getEnvironment(); diff --git a/Xendit/M2Invoice/Model/Payment/CCSubscription.php b/Xendit/M2Invoice/Model/Payment/CCSubscription.php index 16fac52f..8e54c06c 100644 --- a/Xendit/M2Invoice/Model/Payment/CCSubscription.php +++ b/Xendit/M2Invoice/Model/Payment/CCSubscription.php @@ -13,6 +13,8 @@ use Xendit\M2Invoice\Helper\ApiRequest; use Xendit\M2Invoice\Helper\LogDNA; use Xendit\M2Invoice\Enum\LogDNALevel; +use Magento\Framework\UrlInterface; +use Xendit\M2Invoice\Model\Payment\M2Invoice; class CCSubscription extends CCHosted { @@ -44,7 +46,17 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount return $this; } + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $customerSession = $objectManager->get('Magento\Customer\Model\Session'); + try { + if( !$customerSession->isLoggedIn() ) { + $message = 'You must logged in to use this payment method'; + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase($message) + ); + } + $orderId = $order->getRealOrderId(); $billingAddress = $order->getBillingAddress(); @@ -52,20 +64,6 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount $firstName = $billingAddress->getFirstname() ?: $shippingAddress->getFirstname(); $country = $billingAddress->getCountryId() ?: $shippingAddress->getCountryId(); - $billingDetails = array( - 'given_names' => ($firstName ?: 'N/A'), - 'surname' => ($billingAddress->getLastname() ?: null), - 'email' => ($billingAddress->getEmail() ?: null), - 'phone_number' => ($billingAddress->getTelephone() ?: null), - 'address' => array( - 'country' => ($country ?: 'ID'), - 'street_line_1' => ($billingAddress->getStreetLine(1) ?: null), - 'street_line_2' => ($billingAddress->getStreetLine(2) ?: null), - 'city' => ($billingAddress->getCity() ?: null), - 'state' => ($billingAddress->getRegion() ?: null), - 'postal_code' => ($billingAddress->getPostcode() ?: null) - ) - ); $rawAmount = ceil($order->getSubtotal() + $order->getShippingAmount()); @@ -76,14 +74,12 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount 'store_name' => $this->storeManager->getStore()->getName(), 'platform_name' => self::PLATFORM_NAME, 'is_subscription' => "true", - 'subscription_callback_url' => '', - 'platform_callback_url' => '', - 'payer_email' => '', + 'subscription_callback_url' => $this->getXenditSubscriptionCallbackUrl(), + 'payer_email' => $billingAddress->getEmail(), 'subscription_option' => json_encode(array( - 'interval' => '', - 'interval_count' => '' - ), JSON_FORCE_OBJECT), - 'billing_details' => json_encode($billingDetails, JSON_FORCE_OBJECT) + 'interval' => $this->dataHelper->getSubscriptionInterval(), + 'interval_count' => $this->dataHelper->getSubscriptionIntervalCount(), + ), JSON_FORCE_OBJECT) ); $promo = $this->calculatePromo($order, $rawAmount); @@ -142,4 +138,10 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount return $this; } + + protected function getXenditSubscriptionCallbackUrl() { + $baseUrl = $this->getStoreManager()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK); + + return $baseUrl . 'xendit/checkout/subscriptioncallback'; + } } \ No newline at end of file diff --git a/Xendit/M2Invoice/Model/Payment/M2Invoice.php b/Xendit/M2Invoice/Model/Payment/M2Invoice.php index dcebb564..3c587f31 100644 --- a/Xendit/M2Invoice/Model/Payment/M2Invoice.php +++ b/Xendit/M2Invoice/Model/Payment/M2Invoice.php @@ -29,6 +29,14 @@ public function getPublicApiKey() } } + public function getSubscriptionInterval() { + return $this->getConfigData('card_subscription_interval'); + } + + public function getSubscriptionIntervalCount() { + return $this->getConfigData('card_subscription_interval_count'); + } + public function isLive() { $xenditEnv = $this->getConfigData('xendit_env'); diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index fc2b9ca5..a75b987f 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -185,7 +185,6 @@ Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval - diff --git a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml index 5b544b46..4471e179 100644 --- a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml +++ b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml @@ -26,4 +26,4 @@ }) }) - + diff --git a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml index a0f595c4..78e429ab 100644 --- a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml +++ b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml @@ -26,4 +26,4 @@ }) }) - \ No newline at end of file + \ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js index f26507de..a282b71f 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js @@ -22,7 +22,7 @@ define( }, getDescription: function() { - return window.checkoutConfig.payment.m2invoice.card_subscription_description; + return 'Bayar pesanan langganan dengan kartu kredit melalui Xendit'; } }); } From b46e8403e316bc9bba096575680f27b64db90a6e Mon Sep 17 00:00:00 2001 From: candra saputra Date: Mon, 14 Sep 2020 09:48:49 +0700 Subject: [PATCH 05/49] update multishiping process --- .../Controller/Checkout/CCMultishipping.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index eabc1be9..e4dc9e4c 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -11,6 +11,9 @@ class CCMultishipping extends AbstractAction { public function execute() { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $customerSession = $objectManager->get('Magento\Customer\Model\Session'); + try { $rawOrderIds = $this->getRequest()->getParam('order_ids'); $method = $this->getRequest()->getParam('preferred_method'); @@ -20,6 +23,12 @@ public function execute() $tokenId = ''; $orders = []; + if ($method === 'cc_subscription' && !$customerSession->isLoggedIn()) { + $message = 'You must logged in to use this payment method'; + $this->getLogger()->info($message); + return $this->redirectToCart($message); + } + foreach ($orderIds as $key => $value) { $order = $this->getOrderFactory()->create(); $order ->load($value); @@ -89,10 +98,10 @@ public function execute() 'platform_callback_url' => $this->_url->getUrl('xendit/checkout/cccallback') . '?order_ids=' . $rawOrderIds ); - if ($method === 'cc_installment') { - $billingAddress = $orders[0]->getBillingAddress(); - $shippingAddress = $orders[0]->getShippingAddress(); + $billingAddress = $orders[0]->getBillingAddress(); + $shippingAddress = $orders[0]->getShippingAddress(); + if ($method === 'cc_installment') { $firstName = $billingAddress->getFirstname() ?: $shippingAddress->getFirstname(); $country = $billingAddress->getCountryId() ?: $shippingAddress->getCountryId(); $billingDetails = array( From d4689da89bd6cf45dd81a7871c00f6cbbe6bff1e Mon Sep 17 00:00:00 2001 From: candra saputra Date: Mon, 14 Sep 2020 13:58:47 +0700 Subject: [PATCH 06/49] test dev --- Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php | 2 +- Xendit/M2Invoice/Model/Payment/CCInstallment.php | 2 +- Xendit/M2Invoice/Model/Payment/CCSubscription.php | 2 +- Xendit/M2Invoice/etc/config.xml | 2 +- .../frontend/web/js/view/payment/method-renderer/cchosted.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index e4dc9e4c..f5eddf5e 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -145,7 +145,7 @@ public function execute() $this->addCCHostedData($orders, $hostedPayment); // redirect to hosted payment page - $redirect = "https://tpi-ui.xendit.co/hosted-payments/$hostedPaymentId?hp_token=$hostedPaymentToken"; + $redirect = "https://tpi-ui-dev.xendit.co/hosted-payments/$hostedPaymentId?hp_token=$hostedPaymentToken"; $resultRedirect = $this->getRedirectFactory()->create(); $resultRedirect->setUrl($redirect); diff --git a/Xendit/M2Invoice/Model/Payment/CCInstallment.php b/Xendit/M2Invoice/Model/Payment/CCInstallment.php index 168aaf40..6b3a1b45 100644 --- a/Xendit/M2Invoice/Model/Payment/CCInstallment.php +++ b/Xendit/M2Invoice/Model/Payment/CCInstallment.php @@ -45,7 +45,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount } try { - $orderId = $order->getRealOrderId(); + $orderId = $order->getEntityId(); $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); diff --git a/Xendit/M2Invoice/Model/Payment/CCSubscription.php b/Xendit/M2Invoice/Model/Payment/CCSubscription.php index 8e54c06c..cf04ad5b 100644 --- a/Xendit/M2Invoice/Model/Payment/CCSubscription.php +++ b/Xendit/M2Invoice/Model/Payment/CCSubscription.php @@ -57,7 +57,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount ); } - $orderId = $order->getRealOrderId(); + $orderId = $order->getEntityId(); $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); diff --git a/Xendit/M2Invoice/etc/config.xml b/Xendit/M2Invoice/etc/config.xml index f0eb956e..2937b7f5 100644 --- a/Xendit/M2Invoice/etc/config.xml +++ b/Xendit/M2Invoice/etc/config.xml @@ -5,7 +5,7 @@ test - https://tpi.xendit.co + https://tpi-dev.xendit.co 1 Xendit\M2Invoice\Model\Payment\M2Invoice M2Invoice diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js index c7850951..58d20129 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js @@ -67,7 +67,7 @@ define( afterPlaceOrder: function () { var xenditScript = document.createElement('script'); - xenditScript.src = 'https://tpi-ui.xendit.co/js/xendit-hp.min.js'; + xenditScript.src = 'https://tpi-ui-dev.xendit.co/js/xendit-hp.min.js'; document.body.appendChild(xenditScript); $.ajax({ From e54e93381300279cc61706e4c269d405b942e512 Mon Sep 17 00:00:00 2001 From: candra saputra Date: Tue, 15 Sep 2020 09:37:58 +0700 Subject: [PATCH 07/49] testing feedback --- Xendit/M2Invoice/Model/Ui/ConfigProvider.php | 4 +- Xendit/M2Invoice/etc/adminhtml/system.xml | 38 ++++++++++++------- .../multishipping/cc_installment.phtml | 2 +- .../method-renderer/cc_subscription.js | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php index 0706feea..64fd5e68 100644 --- a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php +++ b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php @@ -29,6 +29,7 @@ public function __construct( public function getConfig() { $defaultCCInstallmentDesc = "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"; + $defaultCCSubscriptionDesc = "Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"; $config = [ 'payment' => [ @@ -41,7 +42,8 @@ public function getConfig() 'months' => ['cc' => $this->ccConfig->getCcMonths()], 'years' => ['cc' => $this->ccConfig->getCcYears()], 'has_verification' => $this->ccConfig->hasVerification(), - 'card_installment_description' => ($this->m2Invoice->getConfigData('card_installment_description') ?: $defaultCCInstallmentDesc) + 'card_installment_description' => ($this->m2Invoice->getConfigData('card_installment_description') ?: $defaultCCInstallmentDesc), + 'card_subscription_description' => ($this->m2Invoice->getConfigData('card_subscription_description') ?: $defaultCCSubscriptionDesc) ] ] ]; diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index a75b987f..4fd8a2f5 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -102,8 +102,12 @@ dynamicShow(); shouldEnableSpecificMethod(); specificSelection.prop('size', 6); + jQuery("textarea[id*='m2invoice_card_installment_description']").attr("placeholder", "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI"); jQuery("textarea[id*='m2invoice_card_installment_description']").val("Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI"); + + jQuery("textarea[id*='m2invoice_card_subscription_description']").attr("placeholder", "Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"); + jQuery("textarea[id*='m2invoice_card_subscription_description']").val("Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"); }); ]]> @@ -178,19 +182,27 @@ Customize your installment payment description on checkout page - - - - The frequency with which a subscription payment invoice should be billed. - - Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval - - - - - The number of intervals (specified in the interval property) between subscription. - - + + + + + + + The frequency with which a subscription payment invoice should be billed. + + Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval + + + + + The number of intervals (specified in the interval property) between subscription. + + + + + Customize your Subscription payment description on checkout page + + diff --git a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml index 4471e179..5b544b46 100644 --- a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml +++ b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_installment.phtml @@ -26,4 +26,4 @@ }) }) - + diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js index a282b71f..f26507de 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cc_subscription.js @@ -22,7 +22,7 @@ define( }, getDescription: function() { - return 'Bayar pesanan langganan dengan kartu kredit melalui Xendit'; + return window.checkoutConfig.payment.m2invoice.card_subscription_description; } }); } From 922186e0a31d30acc5ee3bb1c32661a6e223246a Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Tue, 15 Sep 2020 10:52:22 +0700 Subject: [PATCH 08/49] modify getCreditCardCharge header --- .../Checkout/SubscriptionCallback.m22.php | 16 ++++++++++++---- .../Checkout/SubscriptionCallback.m23.php | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php index f276bed8..0542705a 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php @@ -34,7 +34,7 @@ public function execute() } //verify charge - $charge = $this->getCreditCardCharge($chargeId); //child charge + $charge = $this->getCreditCardCharge($chargeId, $payload['recurring_payment_id']); //child charge if ($charge['status'] != 'CAPTURED' && $charge['status'] != 'SETTLED') { $result->setData([ 'status' => __('ERROR'), @@ -44,7 +44,15 @@ public function execute() return $result; } - $childTokenId = $charge['token_id']; //currently endpoint doesn't return token_id + if (empty($charge['token_id'])) { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Token ID not found' + ]); + + return $result; + } + $childTokenId = $charge['token_id']; $orderIds = explode('-', $payload['description']); //parent order id(s) $isTokenMatched = false; @@ -158,14 +166,14 @@ private function getCallbackByInvoiceId($invoiceId) } } - private function getCreditCardCharge($chargeId) + private function getCreditCardCharge($chargeId, $recurringPaymentId) { $url = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/credit-card/charges/" . $chargeId; $method = \Zend\Http\Request::METHOD_GET; try { $response = $this->getApiHelper()->request( - $url, $method + $url, $method, null, false, null, array(), array('recurring_payment_id' => $recurringPaymentId) ); return $response; diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php index 56a9d779..53554a0d 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php @@ -38,7 +38,7 @@ public function execute() } //verify charge - $charge = $this->getCreditCardCharge($chargeId); //child charge + $charge = $this->getCreditCardCharge($chargeId, $payload['recurring_payment_id']); //child charge if ($charge['status'] != 'CAPTURED' && $charge['status'] != 'SETTLED') { $result->setData([ 'status' => __('ERROR'), @@ -48,7 +48,15 @@ public function execute() return $result; } - $childTokenId = $charge['token_id']; //currently endpoint doesn't return token_id + if (empty($charge['token_id'])) { + $result->setData([ + 'status' => __('ERROR'), + 'message' => 'Token ID not found' + ]); + + return $result; + } + $childTokenId = $charge['token_id']; $orderIds = explode('-', $payload['description']); //parent order id(s) $isTokenMatched = false; @@ -162,14 +170,14 @@ private function getCallbackByInvoiceId($invoiceId) } } - private function getCreditCardCharge($chargeId) + private function getCreditCardCharge($chargeId, $recurringPaymentId) { $url = $this->getDataHelper()->getCheckoutUrl() . "/payment/xendit/credit-card/charges/" . $chargeId; $method = \Zend\Http\Request::METHOD_GET; try { $response = $this->getApiHelper()->request( - $url, $method + $url, $method, null, false, null, array(), array('recurring_payment_id' => $recurringPaymentId) ); return $response; From 5578e0d7e8c5658d3d963354d363f36b8cb5a5cc Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Tue, 15 Sep 2020 10:56:50 +0700 Subject: [PATCH 09/49] update version & changelog --- CHANGELOG.md | 6 ++++++ README.md | 4 +++- Xendit/M2Invoice/Helper/ApiRequest.php | 2 +- Xendit/M2Invoice/composer.json | 2 +- Xendit/M2Invoice/etc/module.xml | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4f35656..ee8b60e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 2.2.0 (2020-09-15) + +Features: + +- Add Credit Card Subscription payment method + ## 2.1.0 (2020-09-04) Features: diff --git a/README.md b/README.md index 77f7d017..03a9f9b2 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,6 @@ To activate this feature, you need to follow this additional steps: - Done! The cron should already scheduling and running in the background. ## Supported Payment Method -Currently this plugins support collecting payment through Xendit from these payment channels: - Credit and Debit Card - Mandiri VA - BNI VA @@ -65,6 +64,9 @@ Since v1.3.0, online refund (full and partial) is supported for payment through ## Multishipping Support Since v2.0.0, multishipping checkout is supported for all payment methods. +## Installment & Subscription +Since v2.2.0, merchant can setup installment & subscription payment methods via credit card. + ## Unit Testing To run unit test, run this command from you `MAGENTO_DIR`: diff --git a/Xendit/M2Invoice/Helper/ApiRequest.php b/Xendit/M2Invoice/Helper/ApiRequest.php index 8b8b6b89..f30f20ae 100644 --- a/Xendit/M2Invoice/Helper/ApiRequest.php +++ b/Xendit/M2Invoice/Helper/ApiRequest.php @@ -85,7 +85,7 @@ private function getHeaders($isPublicRequest, $preferredMethod = null, $customHe 'Content-Type' => 'application/json', 'x-plugin-name' => 'MAGENTO2', 'user-agent' => 'Magento 2 Module', - 'x-plugin-version' => '2.0.0' + 'x-plugin-version' => '2.2.0' ]; if ($preferredMethod !== null) { diff --git a/Xendit/M2Invoice/composer.json b/Xendit/M2Invoice/composer.json index 65470106..e01c137e 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": "2.1.0", + "version": "2.2.0", "license": [ "GPL-3.0" ], diff --git a/Xendit/M2Invoice/etc/module.xml b/Xendit/M2Invoice/etc/module.xml index de627d00..1855c88c 100644 --- a/Xendit/M2Invoice/etc/module.xml +++ b/Xendit/M2Invoice/etc/module.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file From 33dc99375c49752ed84f8c71c01001ba6f65835b Mon Sep 17 00:00:00 2001 From: candra saputra Date: Tue, 15 Sep 2020 11:49:11 +0700 Subject: [PATCH 10/49] grouping --- .../Model/Adminhtml/Source/SubscriptionInterval.php | 6 +++--- Xendit/M2Invoice/Model/Payment/M2Invoice.php | 4 ++++ Xendit/M2Invoice/Model/Ui/ConfigProvider.php | 2 +- Xendit/M2Invoice/etc/adminhtml/system.xml | 10 ++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php b/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php index 65e2e044..4643cc5f 100644 --- a/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php +++ b/Xendit/M2Invoice/Model/Adminhtml/Source/SubscriptionInterval.php @@ -13,9 +13,9 @@ class SubscriptionInterval implements \Magento\Framework\Option\ArrayInterface public function toOptionArray() { return [ - ['value' => 'MONTH', 'label' => __('MONTH')], - ['value' => 'WEEK', 'label' => __('WEEK')], - ['value' => 'DAY', 'label' => __('DAY')] + ['value' => 'MONTH', 'label' => __('Month')], + ['value' => 'WEEK', 'label' => __('Week')], + ['value' => 'DAY', 'label' => __('Day')] ]; } } diff --git a/Xendit/M2Invoice/Model/Payment/M2Invoice.php b/Xendit/M2Invoice/Model/Payment/M2Invoice.php index 3c587f31..cc9b3286 100644 --- a/Xendit/M2Invoice/Model/Payment/M2Invoice.php +++ b/Xendit/M2Invoice/Model/Payment/M2Invoice.php @@ -37,6 +37,10 @@ public function getSubscriptionIntervalCount() { return $this->getConfigData('card_subscription_interval_count'); } + public function getSubscriptionDescription() { + return $this->getConfigData('card_subscription_card_subscription_description'); + } + public function isLive() { $xenditEnv = $this->getConfigData('xendit_env'); diff --git a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php index 64fd5e68..58795d5e 100644 --- a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php +++ b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php @@ -43,7 +43,7 @@ public function getConfig() 'years' => ['cc' => $this->ccConfig->getCcYears()], 'has_verification' => $this->ccConfig->hasVerification(), 'card_installment_description' => ($this->m2Invoice->getConfigData('card_installment_description') ?: $defaultCCInstallmentDesc), - 'card_subscription_description' => ($this->m2Invoice->getConfigData('card_subscription_description') ?: $defaultCCSubscriptionDesc) + 'card_subscription_description' => ($this->m2Invoice->getSubscriptionDescription() ?: $defaultCCSubscriptionDesc) ] ] ]; diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index 4fd8a2f5..09bbcf02 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -104,10 +104,8 @@ specificSelection.prop('size', 6); jQuery("textarea[id*='m2invoice_card_installment_description']").attr("placeholder", "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI"); - jQuery("textarea[id*='m2invoice_card_installment_description']").val("Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI"); jQuery("textarea[id*='m2invoice_card_subscription_description']").attr("placeholder", "Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"); - jQuery("textarea[id*='m2invoice_card_subscription_description']").val("Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"); }); ]]> @@ -183,19 +181,19 @@ Customize your installment payment description on checkout page - - + + - The frequency with which a subscription payment invoice should be billed. + The frequency with which a subscription payment invoice should be billed Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval - The number of intervals (specified in the interval property) between subscription. + The number of intervals (specified in the interval property) between subscription From 6adefa29cf2cc347e7ca59f121a39d5daf2ae5c0 Mon Sep 17 00:00:00 2001 From: candra saputra Date: Tue, 15 Sep 2020 13:22:11 +0700 Subject: [PATCH 11/49] ungroup --- Xendit/M2Invoice/Model/Payment/M2Invoice.php | 2 +- Xendit/M2Invoice/etc/adminhtml/system.xml | 37 +++++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Xendit/M2Invoice/Model/Payment/M2Invoice.php b/Xendit/M2Invoice/Model/Payment/M2Invoice.php index cc9b3286..ec28787f 100644 --- a/Xendit/M2Invoice/Model/Payment/M2Invoice.php +++ b/Xendit/M2Invoice/Model/Payment/M2Invoice.php @@ -38,7 +38,7 @@ public function getSubscriptionIntervalCount() { } public function getSubscriptionDescription() { - return $this->getConfigData('card_subscription_card_subscription_description'); + return $this->getConfigData('card_subscription_description'); } public function isLive() diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index 09bbcf02..ec5b3cd5 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -181,26 +181,23 @@ Customize your installment payment description on checkout page - - - - - - The frequency with which a subscription payment invoice should be billed - - Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval - - - - - The number of intervals (specified in the interval property) between subscription - - - - - Customize your Subscription payment description on checkout page - - + + + + The frequency with which a subscription payment invoice should be billed + + Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval + + + + + The number of intervals (specified in the interval property) between subscription + + + + + Customize your Subscription payment description on checkout page + From 3d0c23fcfba54d92e0b3356e331e7471c01feaec Mon Sep 17 00:00:00 2001 From: candra saputra Date: Tue, 15 Sep 2020 13:23:29 +0700 Subject: [PATCH 12/49] remove 2 --- .../view/frontend/templates/multishipping/cc_subscription.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml index 78e429ab..a0f595c4 100644 --- a/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml +++ b/Xendit/M2Invoice/view/frontend/templates/multishipping/cc_subscription.phtml @@ -26,4 +26,4 @@ }) }) - \ No newline at end of file + \ No newline at end of file From 744e26100a8c352aae8289772b3b15d456f8d02b Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Tue, 15 Sep 2020 13:25:54 +0700 Subject: [PATCH 13/49] change header format to dash --- .../M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php | 2 +- .../M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php index 0542705a..dbcd0a82 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php @@ -173,7 +173,7 @@ private function getCreditCardCharge($chargeId, $recurringPaymentId) try { $response = $this->getApiHelper()->request( - $url, $method, null, false, null, array(), array('recurring_payment_id' => $recurringPaymentId) + $url, $method, null, false, null, array(), array('recurring-payment-id' => $recurringPaymentId) ); return $response; diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php index 53554a0d..08a9bdb3 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php @@ -177,7 +177,7 @@ private function getCreditCardCharge($chargeId, $recurringPaymentId) try { $response = $this->getApiHelper()->request( - $url, $method, null, false, null, array(), array('recurring_payment_id' => $recurringPaymentId) + $url, $method, null, false, null, array(), array('recurring-payment-id' => $recurringPaymentId) ); return $response; From a6158c9812cf7cae7c828686d6178dfadc9afd9a Mon Sep 17 00:00:00 2001 From: Aulia Hakiem Date: Tue, 15 Sep 2020 14:07:00 +0700 Subject: [PATCH 14/49] group subscription config and change order number --- .../M2Invoice/Model/Payment/CCInstallment.php | 2 +- .../Model/Payment/CCSubscription.php | 2 +- Xendit/M2Invoice/etc/adminhtml/system.xml | 40 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Xendit/M2Invoice/Model/Payment/CCInstallment.php b/Xendit/M2Invoice/Model/Payment/CCInstallment.php index 6b3a1b45..168aaf40 100644 --- a/Xendit/M2Invoice/Model/Payment/CCInstallment.php +++ b/Xendit/M2Invoice/Model/Payment/CCInstallment.php @@ -45,7 +45,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount } try { - $orderId = $order->getEntityId(); + $orderId = $order->getRealOrderId(); $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); diff --git a/Xendit/M2Invoice/Model/Payment/CCSubscription.php b/Xendit/M2Invoice/Model/Payment/CCSubscription.php index cf04ad5b..8e54c06c 100644 --- a/Xendit/M2Invoice/Model/Payment/CCSubscription.php +++ b/Xendit/M2Invoice/Model/Payment/CCSubscription.php @@ -57,7 +57,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount ); } - $orderId = $order->getEntityId(); + $orderId = $order->getRealOrderId(); $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index ec5b3cd5..67802992 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -181,23 +181,29 @@ Customize your installment payment description on checkout page - - - - The frequency with which a subscription payment invoice should be billed - - Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval - - - - - The number of intervals (specified in the interval property) between subscription - - - - - Customize your Subscription payment description on checkout page - + + + + + + The frequency with which a subscription payment invoice should be billed + + payment/m2invoice/card_subscription_interval + Xendit\M2Invoice\Model\Adminhtml\Source\SubscriptionInterval + + + + + The number of intervals (specified in the interval property) between subscription + + payment/m2invoice/card_subscription_interval_count + + + + Customize your Subscription payment description on checkout page + payment/m2invoice/card_subscription_description + + From e66db3b33f787b723d1abc800dbdf8dca45934e1 Mon Sep 17 00:00:00 2001 From: Aulia Hakiem Date: Tue, 15 Sep 2020 14:22:45 +0700 Subject: [PATCH 15/49] add query param on subscription callback url --- .../M2Invoice/Controller/Checkout/CCMultishipping.php | 2 +- Xendit/M2Invoice/Helper/Data.php | 10 ++++++++++ Xendit/M2Invoice/Model/Payment/CCSubscription.php | 8 +------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index f5eddf5e..9b6ef4d3 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -124,7 +124,7 @@ public function execute() } else if ($method === 'cc_subscription') { $requestData['payment_type'] = 'CREDIT_CARD_SUBSCRIPTION'; $requestData['is_subscription'] = "true"; - $requestData['subscription_callback_url'] = $this->getStoreManager()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK) . 'xendit/checkout/subscriptioncallback'; + $requestData['subscription_callback_url'] = $this->getDataHelper()->getXenditSubscriptionCallbackUrl(true); $requestData['payer_email'] = $billingAddress->getEmail(); $requestData['subscription_option'] = json_encode(array( 'interval' => $this->getDataHelper()->getSubscriptionInterval(), diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index ef5b6711..344ce62d 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -177,6 +177,16 @@ public function jsonData() return (array) $inputs; } + public function getXenditSubscriptionCallbackUrl($isMultishipping = true) { + $baseUrl = $this->getStoreManager()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK) . 'xendit/checkout/subscriptioncallback'; + + if ($isMultishipping) { + $baseUrl .= '&type=multishipping'; + } + + return $baseUrl; + } + /** * Map card's failure reason to more detailed explanation based on current insight. * diff --git a/Xendit/M2Invoice/Model/Payment/CCSubscription.php b/Xendit/M2Invoice/Model/Payment/CCSubscription.php index 8e54c06c..cf5a89a4 100644 --- a/Xendit/M2Invoice/Model/Payment/CCSubscription.php +++ b/Xendit/M2Invoice/Model/Payment/CCSubscription.php @@ -74,7 +74,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount 'store_name' => $this->storeManager->getStore()->getName(), 'platform_name' => self::PLATFORM_NAME, 'is_subscription' => "true", - 'subscription_callback_url' => $this->getXenditSubscriptionCallbackUrl(), + 'subscription_callback_url' => $this->dataHelper->getXenditSubscriptionCallbackUrl(), 'payer_email' => $billingAddress->getEmail(), 'subscription_option' => json_encode(array( 'interval' => $this->dataHelper->getSubscriptionInterval(), @@ -138,10 +138,4 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount return $this; } - - protected function getXenditSubscriptionCallbackUrl() { - $baseUrl = $this->getStoreManager()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK); - - return $baseUrl . 'xendit/checkout/subscriptioncallback'; - } } \ No newline at end of file From b88b78878d8e80cb6e62f93a31fe1e292f743f5e Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Tue, 15 Sep 2020 14:30:51 +0700 Subject: [PATCH 16/49] fix callback --- .../Checkout/SubscriptionCallback.m22.php | 17 ++++++++++++++--- .../Checkout/SubscriptionCallback.m23.php | 17 ++++++++++++++--- .../M2Invoice/Model/Payment/CCInstallment.php | 4 ++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php index dbcd0a82..1e280155 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m22.php @@ -54,12 +54,23 @@ public function execute() } $childTokenId = $charge['token_id']; - $orderIds = explode('-', $payload['description']); //parent order id(s) + $isMultishipping = ($this->getRequest()->getParam('type') === 'multishipping'); $isTokenMatched = false; + if ($isMultishipping) { + $orderIds = explode('-', $payload['description']); + } else { + $orderIds = array($payload['description']); + } + foreach ($orderIds as $key => $value) { $order = $this->getOrderFactory()->create(); - $order->load($value); + if ($isMultishipping) { + $order->load($value); + } else { + $order->loadByIncrementId($value); + } + $payment = $order->getPayment(); //match token id of parent & child's order just once @@ -124,7 +135,7 @@ public function execute() 'payment' => $payment->getData(), 'transaction_id' => $chargeId, 'parent_order_id' => $order->getRealOrderId(), - 'is_multishipping' => (count($orderIds) > 1 ? true : false) + 'is_multishipping' => $isMultishipping ); //create order diff --git a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php index 08a9bdb3..5ab74641 100644 --- a/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php +++ b/Xendit/M2Invoice/Controller/Checkout/SubscriptionCallback.m23.php @@ -58,12 +58,23 @@ public function execute() } $childTokenId = $charge['token_id']; - $orderIds = explode('-', $payload['description']); //parent order id(s) + $isMultishipping = ($this->getRequest()->getParam('type') === 'multishipping'); $isTokenMatched = false; + if ($isMultishipping) { + $orderIds = explode('-', $payload['description']); + } else { + $orderIds = array($payload['description']); + } + foreach ($orderIds as $key => $value) { $order = $this->getOrderFactory()->create(); - $order->load($value); + if ($isMultishipping) { + $order->load($value); + } else { + $order->loadByIncrementId($value); + } + $payment = $order->getPayment(); //match token id of parent & child's order just once @@ -128,7 +139,7 @@ public function execute() 'payment' => $payment->getData(), 'transaction_id' => $chargeId, 'parent_order_id' => $order->getRealOrderId(), - 'is_multishipping' => (count($orderIds) > 1 ? true : false) + 'is_multishipping' => $isMultishipping ); //create order diff --git a/Xendit/M2Invoice/Model/Payment/CCInstallment.php b/Xendit/M2Invoice/Model/Payment/CCInstallment.php index 168aaf40..531f1ff8 100644 --- a/Xendit/M2Invoice/Model/Payment/CCInstallment.php +++ b/Xendit/M2Invoice/Model/Payment/CCInstallment.php @@ -59,8 +59,8 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount 'phone_number' => ($billingAddress->getTelephone() ?: null), 'address' => array( 'country' => ($country ?: 'ID'), - 'street_line_1' => ($billingAddress->getStreetLine(1) ?: null), - 'street_line_2' => ($billingAddress->getStreetLine(2) ?: null), + 'street_line_1' => ($billingAddress->getStreetLine(1) ?: null), + 'street_line_2' => ($billingAddress->getStreetLine(2) ?: null), 'city' => ($billingAddress->getCity() ?: null), 'state' => ($billingAddress->getRegion() ?: null), 'postal_code' => ($billingAddress->getPostcode() ?: null) From e5baa6feb5f99e49eea3911873335d811706df11 Mon Sep 17 00:00:00 2001 From: Aulia Hakiem Date: Tue, 15 Sep 2020 14:40:56 +0700 Subject: [PATCH 17/49] add missing module --- Xendit/M2Invoice/Helper/Data.php | 1 + Xendit/M2Invoice/Model/Payment/CCSubscription.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index 344ce62d..bd6c34c6 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -10,6 +10,7 @@ use Magento\Framework\App\Helper\Context; use Magento\Framework\DataObject; use Magento\Framework\Filesystem\Driver\File; +use Magento\Framework\UrlInterface; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteManagement; use Magento\Store\Model\StoreManagerInterface; diff --git a/Xendit/M2Invoice/Model/Payment/CCSubscription.php b/Xendit/M2Invoice/Model/Payment/CCSubscription.php index cf5a89a4..b830d35f 100644 --- a/Xendit/M2Invoice/Model/Payment/CCSubscription.php +++ b/Xendit/M2Invoice/Model/Payment/CCSubscription.php @@ -13,7 +13,6 @@ use Xendit\M2Invoice\Helper\ApiRequest; use Xendit\M2Invoice\Helper\LogDNA; use Xendit\M2Invoice\Enum\LogDNALevel; -use Magento\Framework\UrlInterface; use Xendit\M2Invoice\Model\Payment\M2Invoice; class CCSubscription extends CCHosted From fdbc527092068755b7506bb0f2f5caf6b4f40d6e Mon Sep 17 00:00:00 2001 From: Aulia Hakiem Date: Tue, 15 Sep 2020 14:51:54 +0700 Subject: [PATCH 18/49] fix query multishipping --- Xendit/M2Invoice/Helper/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index bd6c34c6..6db30ddb 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -182,7 +182,7 @@ public function getXenditSubscriptionCallbackUrl($isMultishipping = true) { $baseUrl = $this->getStoreManager()->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK) . 'xendit/checkout/subscriptioncallback'; if ($isMultishipping) { - $baseUrl .= '&type=multishipping'; + $baseUrl .= '?type=multishipping'; } return $baseUrl; From 5b301515ab3e5cacd143ed2cafe5f13e71355858 Mon Sep 17 00:00:00 2001 From: Aulia Hakiem Date: Tue, 15 Sep 2020 16:23:39 +0700 Subject: [PATCH 19/49] restructurize ui url --- Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php | 2 +- Xendit/M2Invoice/Helper/Data.php | 5 +++++ Xendit/M2Invoice/Model/Payment/M2Invoice.php | 5 +++++ Xendit/M2Invoice/Model/Ui/ConfigProvider.php | 1 + Xendit/M2Invoice/etc/adminhtml/system.xml | 2 +- Xendit/M2Invoice/etc/config.xml | 1 + .../frontend/web/js/view/payment/method-renderer/cchosted.js | 3 ++- 7 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php index 9b6ef4d3..30b5d9db 100644 --- a/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php +++ b/Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php @@ -145,7 +145,7 @@ public function execute() $this->addCCHostedData($orders, $hostedPayment); // redirect to hosted payment page - $redirect = "https://tpi-ui-dev.xendit.co/hosted-payments/$hostedPaymentId?hp_token=$hostedPaymentToken"; + $redirect = $this->getDataHelper()->getUiUrl() . "/hosted-payments/$hostedPaymentId?hp_token=$hostedPaymentToken"; $resultRedirect = $this->getRedirectFactory()->create(); $resultRedirect->setUrl($redirect); diff --git a/Xendit/M2Invoice/Helper/Data.php b/Xendit/M2Invoice/Helper/Data.php index 6db30ddb..7dfbcf61 100644 --- a/Xendit/M2Invoice/Helper/Data.php +++ b/Xendit/M2Invoice/Helper/Data.php @@ -71,6 +71,11 @@ public function getCheckoutUrl() return $this->m2Invoice->getConfigData('xendit_url'); } + public function getUiUrl() + { + return $this->m2Invoice->getUiUrl(); + } + public function getSuccessUrl($isMultishipping = false) { $baseUrl = $this->getStoreManager()->getStore()->getBaseUrl() . 'xendit/checkout/success'; diff --git a/Xendit/M2Invoice/Model/Payment/M2Invoice.php b/Xendit/M2Invoice/Model/Payment/M2Invoice.php index ec28787f..ddc222a7 100644 --- a/Xendit/M2Invoice/Model/Payment/M2Invoice.php +++ b/Xendit/M2Invoice/Model/Payment/M2Invoice.php @@ -62,6 +62,11 @@ public function getUrl() return $this->getConfigData('xendit_url'); } + public function getUiUrl() + { + return $this->getConfigData('ui_url'); + } + public function getCardPaymentType() { return $this->getConfigData('card_payment_type'); diff --git a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php index 58795d5e..2745877a 100644 --- a/Xendit/M2Invoice/Model/Ui/ConfigProvider.php +++ b/Xendit/M2Invoice/Model/Ui/ConfigProvider.php @@ -38,6 +38,7 @@ public function getConfig() 'test_prefix' => $this->m2Invoice->getConfigData('checkout_test_prefix'), 'test_content' => $this->m2Invoice->getConfigData('checkout_test_content'), 'public_api_key' => $this->m2Invoice->getPublicApiKey(), + 'ui_url' => $this->m2Invoice->getUiUrl(), 'available_types' => ['cc' => $this->ccConfig->getCcAvailableTypes()], 'months' => ['cc' => $this->ccConfig->getCcMonths()], 'years' => ['cc' => $this->ccConfig->getCcYears()], diff --git a/Xendit/M2Invoice/etc/adminhtml/system.xml b/Xendit/M2Invoice/etc/adminhtml/system.xml index 67802992..85defb07 100644 --- a/Xendit/M2Invoice/etc/adminhtml/system.xml +++ b/Xendit/M2Invoice/etc/adminhtml/system.xml @@ -105,7 +105,7 @@ jQuery("textarea[id*='m2invoice_card_installment_description']").attr("placeholder", "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI"); - jQuery("textarea[id*='m2invoice_card_subscription_description']").attr("placeholder", "Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"); + jQuery("textarea[id*='m2invoice_card_subscription_card_subscription_description']").attr("placeholder", "Bayar pesanan dan berlangganan menggunakan kartu kredit anda melalui Xendit.\r\nBank yang tersedia: BCA, BRI"); }); ]]> diff --git a/Xendit/M2Invoice/etc/config.xml b/Xendit/M2Invoice/etc/config.xml index 2937b7f5..6ff01bba 100644 --- a/Xendit/M2Invoice/etc/config.xml +++ b/Xendit/M2Invoice/etc/config.xml @@ -6,6 +6,7 @@ test https://tpi-dev.xendit.co + https://tpi-ui-dev.xendit.co 1 Xendit\M2Invoice\Model\Payment\M2Invoice M2Invoice diff --git a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js index 58d20129..89eb2c9f 100644 --- a/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js +++ b/Xendit/M2Invoice/view/frontend/web/js/view/payment/method-renderer/cchosted.js @@ -66,8 +66,9 @@ define( }, afterPlaceOrder: function () { + var uiUrl = window.checkoutConfig.payment.m2invoice.ui_url; var xenditScript = document.createElement('script'); - xenditScript.src = 'https://tpi-ui-dev.xendit.co/js/xendit-hp.min.js'; + xenditScript.src = uiUrl + '/js/xendit-hp.min.js'; document.body.appendChild(xenditScript); $.ajax({ From 1d646db762d996f6cffdb2e2455089bb5b4f704d Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Tue, 15 Sep 2020 23:01:05 +0700 Subject: [PATCH 20/49] display subscription info on admin & frontend --- Xendit/M2Invoice/Block/CustomView.php | 27 ++++++++++++++++ .../adminhtml/layout/sales_order_view.xml | 14 ++++++++ .../templates/order/subscription_info.phtml | 22 +++++++++++++ .../view/frontend/layout/sales_order_view.xml | 16 ++++++++++ .../templates/order/subscription_info.phtml | 32 +++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100755 Xendit/M2Invoice/Block/CustomView.php create mode 100755 Xendit/M2Invoice/view/adminhtml/layout/sales_order_view.xml create mode 100644 Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml create mode 100755 Xendit/M2Invoice/view/frontend/layout/sales_order_view.xml create mode 100644 Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml diff --git a/Xendit/M2Invoice/Block/CustomView.php b/Xendit/M2Invoice/Block/CustomView.php new file mode 100755 index 00000000..b730774b --- /dev/null +++ b/Xendit/M2Invoice/Block/CustomView.php @@ -0,0 +1,27 @@ +dataHelper = $dataHelper; + + parent::__construct($context, $data); + } + + public function getSubscriptionConfig() + { + $data['card_subscription_interval'] = $this->dataHelper->getSubscriptionInterval(); + $data['card_subscription_interval_count'] = $this->dataHelper->getSubscriptionIntervalCount(); + + return $data; + } +} diff --git a/Xendit/M2Invoice/view/adminhtml/layout/sales_order_view.xml b/Xendit/M2Invoice/view/adminhtml/layout/sales_order_view.xml new file mode 100755 index 00000000..4b3bd2c6 --- /dev/null +++ b/Xendit/M2Invoice/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml b/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml new file mode 100644 index 00000000..45559128 --- /dev/null +++ b/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml @@ -0,0 +1,22 @@ +getSubscriptionConfig(); +if ($subscriptionData['card_subscription_interval']) { + $moreThan1 = ($subscriptionData['card_subscription_interval_count'] > 1 ? true : false); +?> +
+
+ Subscription Information +
+

Every

+
+ \ No newline at end of file diff --git a/Xendit/M2Invoice/view/frontend/layout/sales_order_view.xml b/Xendit/M2Invoice/view/frontend/layout/sales_order_view.xml new file mode 100755 index 00000000..531f6cd9 --- /dev/null +++ b/Xendit/M2Invoice/view/frontend/layout/sales_order_view.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml b/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml new file mode 100644 index 00000000..303d215b --- /dev/null +++ b/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml @@ -0,0 +1,32 @@ +getSubscriptionConfig(); +if ($subscriptionData['card_subscription_interval']) { + $moreThan1 = ($subscriptionData['card_subscription_interval_count'] > 1 ? true : false); +?> + + + \ No newline at end of file From 2de31f7d2f1fbc876192c8efbd0295137a9a7b58 Mon Sep 17 00:00:00 2001 From: Irene Gohtami Date: Wed, 16 Sep 2020 10:06:06 +0700 Subject: [PATCH 21/49] show subscription info on cc_subscription order --- Xendit/M2Invoice/Block/CustomView.php | 25 +++++++++++++++++-- .../templates/order/subscription_info.phtml | 4 +-- .../templates/order/subscription_info.phtml | 4 +-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Xendit/M2Invoice/Block/CustomView.php b/Xendit/M2Invoice/Block/CustomView.php index b730774b..f57a378d 100755 --- a/Xendit/M2Invoice/Block/CustomView.php +++ b/Xendit/M2Invoice/Block/CustomView.php @@ -1,24 +1,45 @@ registry = $registry; $this->dataHelper = $dataHelper; parent::__construct($context, $data); } + /** + * Retrieve current order model instance + * + * @return \Magento\Sales\Model\Order + */ + public function getOrder() + { + return $this->registry->registry('current_order'); + } + + public function getPaymentMethod() + { + return $this->getOrder()->getPayment()->getMethodInstance()->getCode(); + } + public function getSubscriptionConfig() { + $data = array(); $data['card_subscription_interval'] = $this->dataHelper->getSubscriptionInterval(); $data['card_subscription_interval_count'] = $this->dataHelper->getSubscriptionIntervalCount(); diff --git a/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml b/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml index 45559128..b6763b75 100644 --- a/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml +++ b/Xendit/M2Invoice/view/adminhtml/templates/order/subscription_info.phtml @@ -1,8 +1,8 @@ getSubscriptionConfig(); -if ($subscriptionData['card_subscription_interval']) { +if ($block->getPaymentMethod() === 'cc_subscription') { + $subscriptionData = $block->getSubscriptionConfig(); $moreThan1 = ($subscriptionData['card_subscription_interval_count'] > 1 ? true : false); ?>
diff --git a/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml b/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml index 303d215b..f8e8cfca 100644 --- a/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml +++ b/Xendit/M2Invoice/view/frontend/templates/order/subscription_info.phtml @@ -1,8 +1,8 @@ getSubscriptionConfig(); -if ($subscriptionData['card_subscription_interval']) { +if ($block->getPaymentMethod() === 'cc_subscription') { + $subscriptionData = $block->getSubscriptionConfig(); $moreThan1 = ($subscriptionData['card_subscription_interval_count'] > 1 ? true : false); ?>