Skip to content

Commit

Permalink
Merge pull request #88 from xendit/TPI-4983/TPI-5081/admin-settings
Browse files Browse the repository at this point in the history
Migrate Kredivo to Invoice
  • Loading branch information
IreneGohtami authored Nov 3, 2021
2 parents 5356165 + 00ff24c commit 1cec783
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 1,037 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
211 changes: 0 additions & 211 deletions Xendit/M2Invoice/Controller/Checkout/CardlessCreditMultishipping.php

This file was deleted.

34 changes: 29 additions & 5 deletions Xendit/M2Invoice/Controller/Checkout/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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() ?: '[email protected]' ,
'mobile_number' => $shippingAddress->getTelephone() ?: 'N/A',
'addresses' => [(object) $address]
],
'items' => $items
];

return $requestData;
Expand Down
44 changes: 35 additions & 9 deletions Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public function execute()
$transactionAmount = 0;
$orderProcessed = false;
$orders = [];
$addresses = [];
$items = [];

$orderIncrementIds = '';
$orderIncrementIds = '';

$c = 0;
foreach ($orderIds as $key => $value) {
Expand All @@ -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() ?: '[email protected]';
$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++;
}

Expand All @@ -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);
Expand Down
Loading

0 comments on commit 1cec783

Please sign in to comment.