Skip to content

Commit 1cec783

Browse files
authored
Merge pull request #88 from xendit/TPI-4983/TPI-5081/admin-settings
Migrate Kredivo to Invoice
2 parents 5356165 + 00ff24c commit 1cec783

File tree

27 files changed

+140
-1037
lines changed

27 files changed

+140
-1037
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 3.2.0 (2021-11-02)
4+
Improvements:
5+
- Migrate Kredivo to XenInvoice
6+
- Data housekeeping
7+
38
## 3.1.0 (2021-10-03)
49
Improvements:
510
- Add Shopeepay payment method

Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public function execute()
7979

8080
if ($method === 'cc_subscription') {
8181
$billingAddress = $orders[0]->getBillingAddress(); // billing address of 1st order
82-
$shippingAddress = $orders[0]->getShippingAddress(); // shipping address of 1st order
8382

8483
$requestData = [
8584
'payer_email' => $billingAddress->getEmail(),

Xendit/M2Invoice/Controller/Checkout/CardlessCreditMultishipping.php

-211
This file was deleted.

Xendit/M2Invoice/Controller/Checkout/Invoice.php

+29-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,28 @@ private function getApiRequestData($order)
6363
$orderId = $order->getRealOrderId();
6464
$preferredMethod = $this->getRequest()->getParam('preferred_method');
6565

66-
$billingaddress = $order->getBillingAddress();
66+
$shippingAddress = $order->getShippingAddress();
67+
$address = [
68+
'street_line1' => $shippingAddress->getData('street') ?: 'N/A',
69+
'city' => $shippingAddress->getData('city') ?: 'N/A',
70+
'state' => $shippingAddress->getData('region') ?: 'N/A',
71+
'postal_code' => $shippingAddress->getData('postcode') ?: 'N/A',
72+
'country' => $shippingAddress->getData('country_id') ?: 'ID'
73+
];
74+
75+
$orderItems = $order->getAllItems();
76+
$items = [];
77+
foreach ($orderItems as $orderItem) {
78+
$item = [];
79+
$product = $orderItem->getProduct();
80+
$item['reference_id'] = $product->getId();
81+
$item['name'] = $product->getName();
82+
$item['price'] = $product->getPrice();
83+
$item['type'] = 'PRODUCT';
84+
$item['url'] = $product->getProductUrl();
85+
$item['quantity'] = (int) $orderItem->getQtyOrdered();
86+
$items[] = (object) $item;
87+
}
6788

6889
$requestData = [
6990
'external_id' => $this->getDataHelper()->getExternalId($orderId),
@@ -78,10 +99,13 @@ private function getApiRequestData($order)
7899
'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(),
79100
'failure_redirect_url' => $this->getDataHelper()->getFailureUrl($orderId),
80101
'customer' => (object) [
81-
'given_names' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(),
82-
'email' => $order->getCustomerEmail(),
83-
'mobile_number' => $billingaddress->getTelephone()
84-
]
102+
'given_names' => $order->getCustomerFirstname() ?: 'N/A',
103+
'surname' => $order->getCustomerLastname() ?: 'N/A',
104+
'email' => $order->getCustomerEmail() ?: '[email protected]' ,
105+
'mobile_number' => $shippingAddress->getTelephone() ?: 'N/A',
106+
'addresses' => [(object) $address]
107+
],
108+
'items' => $items
85109
];
86110

87111
return $requestData;

Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php

+35-9
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public function execute()
2626
$transactionAmount = 0;
2727
$orderProcessed = false;
2828
$orders = [];
29+
$addresses = [];
30+
$items = [];
2931

30-
$orderIncrementIds = '';
32+
$orderIncrementIds = '';
3133

3234
$c = 0;
3335
foreach ($orderIds as $key => $value) {
@@ -53,11 +55,32 @@ public function execute()
5355
$order->save();
5456

5557
$transactionAmount += (int)$order->getTotalDue();
56-
$billingEmail = $order->getCustomerEmail();
57-
$billingFirstName = $order->getCustomerFirstname();
58-
$billingLastName = $order->getCustomerLastname();
59-
$billingaddress = $order->getBillingAddress();
58+
$billingEmail = $order->getCustomerEmail() ?: '[email protected]';
59+
$shippingAddress = $order->getShippingAddress();
6060
$currency = $order->getBaseCurrencyCode();
61+
62+
$address = [
63+
'street_line1' => $shippingAddress->getData('street') ?: 'N/A',
64+
'city' => $shippingAddress->getData('city') ?: 'N/A',
65+
'state' => $shippingAddress->getData('region') ?: 'N/A',
66+
'postal_code' => $shippingAddress->getData('postcode') ?: 'N/A',
67+
'country' => $shippingAddress->getData('country_id') ?: 'ID'
68+
];
69+
$addresses[] = (object) $address;
70+
71+
$orderItems = $order->getAllItems();
72+
foreach ($orderItems as $orderItem) {
73+
$item = [];
74+
$product = $orderItem->getProduct();
75+
$item['reference_id'] = $product->getId();
76+
$item['name'] = $product->getName();
77+
$item['price'] = $product->getPrice();
78+
$item['type'] = 'PRODUCT';
79+
$item['url'] = $product->getProductUrl();
80+
$item['quantity'] = (int) $orderItem->getQtyOrdered();
81+
$items[] = (object) $item;
82+
}
83+
6184
$c++;
6285
}
6386

@@ -83,10 +106,13 @@ public function execute()
83106
'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(true),
84107
'failure_redirect_url' => $this->getDataHelper()->getFailureUrl($orderIncrementIds, true),
85108
'customer' => (object) [
86-
'given_names' => $billingFirstName . ' ' . $billingLastName,
87-
'email' => $billingEmail,
88-
'mobile_number' => $billingaddress->getTelephone()
89-
]
109+
'given_names' => $order->getCustomerFirstname() ?: 'N/A',
110+
'surname' => $order->getCustomerLastname() ?: 'N/A',
111+
'email' => $billingEmail,
112+
'mobile_number' => $shippingAddress->getTelephone() ?: 'N/A',
113+
'addresses' => $addresses
114+
],
115+
'items' => $items
90116
];
91117

92118
$invoice = $this->createInvoice($requestData);

0 commit comments

Comments
 (0)