@@ -32,8 +32,6 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
32
32
$ data = $ object ->getData ();
33
33
34
34
$ billingAddress = $ object ->getBillingAddress ();
35
- $ shippingAddress = $ object ->getShippingAddress ();
36
- $ shippingMethods = $ shippingAddress ->getShippingRatesCollection ();
37
35
38
36
$ taxTotal = 0 ;
39
37
@@ -46,22 +44,14 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
46
44
47
45
$ params ['items ' ] = array ();
48
46
49
- //not sure what should go to priority, I guess it will say something in the description if it is Express
50
- foreach ($ shippingMethods as $ method ) {
51
- $ params ['courier ' ] = array (
52
- 'name ' => substr ($ method ->getMethodTitle () . " " . $ method ->getCarrierTitle (), 0 , 128 ),
53
- 'priority ' => "STANDARD " ,
54
- );
55
- }
56
-
57
47
foreach ($ object ->getAllVisibleItems () as $ item ) {
58
48
/** @var Mage_Sales_Model_Order_Item $orderItem */
59
49
$ params ['items ' ][] = array (
60
50
'name ' => (string )$ item ->getName (),
61
51
'sku ' => $ this ->_truncateString ( (string )$ item ->getSku () ),
62
52
'quantity ' => (int )$ item ->getQty (),
63
53
'price ' => array (
64
- 'amount ' => round ((float )$ item ->getPriceInclTax (), $ precision ),
54
+ 'amount ' => number_format ((float )$ item ->getPriceInclTax (), $ precision, ' . ' , '' ),
65
55
'currency ' => (string )Mage::app ()->getStore ()->getCurrentCurrencyCode ()
66
56
)
67
57
);
@@ -80,7 +70,7 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
80
70
$ params ['discounts ' ][] = array (
81
71
'displayName ' => substr ( $ discount_name . ' - ' . (string )$ item ->getName (), 0 , 128 ),
82
72
'amount ' => array (
83
- 'amount ' => round ((float )$ item ->getDiscountAmount (), $ precision ),
73
+ 'amount ' => number_format ((float )$ item ->getDiscountAmount (), $ precision, ' . ' , '' ),
84
74
'currency ' => (string )Mage::app ()->getStore ()->getCurrentCurrencyCode ()
85
75
),
86
76
);
@@ -90,41 +80,13 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
90
80
$ taxTotal += $ item ->getTaxAmount ();
91
81
}
92
82
93
- if ($ shippingAddress ->getShippingInclTax ()) {
94
- $ params ['shippingAmount ' ] = array (
95
- 'amount ' => round ((float )$ shippingAddress ->getShippingInclTax (), $ precision ), // with tax
96
- 'currency ' => (string )Mage::app ()->getStore ()->getCurrentCurrencyCode ()
97
- );
98
- }
99
-
100
- // $taxAmount = $shippingAddress->getData('tax_amount');
101
83
if ( isset ($ taxTotal ) && round ((float )$ taxTotal , $ precision ) > 0 ) {
102
84
$ params ['taxAmount ' ] = array (
103
- 'amount ' => isset ( $ taxTotal ) ? round (( float )$ taxTotal , $ precision) : 0 ,
85
+ 'amount ' => number_format (( float )$ taxTotal , $ precision, ' . ' , '' ) ,
104
86
'currency ' => (string )Mage::app ()->getStore ()->getCurrentCurrencyCode ()
105
87
);
106
88
}
107
89
108
- // $params['orderDetail']['subTotal'] = array(
109
- // 'amount' => round((float)$data['subtotal'], $precision),
110
- // 'currency' => (string)Mage::app()->getStore()->getCurrentCurrencyCode(),
111
- // );
112
- if ( !empty ( $ shippingAddress ) ) {
113
- if ( !empty ( $ shippingAddress ->getStreet1 () ) ) {
114
- $ params ['shipping ' ] = array (
115
- 'name ' => (string )$ shippingAddress ->getFirstname () . ' ' . $ shippingAddress ->getLastname (),
116
- 'line1 ' => (string )$ shippingAddress ->getStreet1 (),
117
- 'line2 ' => (string )$ shippingAddress ->getStreet2 (),
118
- 'suburb ' => (string )$ shippingAddress ->getCity (),
119
- 'postcode ' => (string )$ shippingAddress ->getPostcode (),
120
- 'state ' => (string )$ shippingAddress ->getRegion (),
121
- 'phoneNumber ' => (string )$ shippingAddress ->getTelephone (),
122
- // 'countryCode' => 'AU',
123
- 'countryCode ' => (string )$ shippingAddress ->getCountry (),
124
- );
125
- }
126
- }
127
-
128
90
$ params ['billing ' ] = array (
129
91
'name ' => (string )$ billingAddress ->getFirstname () . ' ' . $ billingAddress ->getLastname (),
130
92
'line1 ' => (string )$ billingAddress ->getStreet1 (),
@@ -133,12 +95,46 @@ public function buildOrderTokenRequest($object, $override = array(), $afterPayPa
133
95
'postcode ' => (string )$ billingAddress ->getPostcode (),
134
96
'state ' => (string )$ billingAddress ->getRegion (),
135
97
'phoneNumber ' => (string )$ billingAddress ->getTelephone (),
136
- // 'countryCode' => 'AU',
137
98
'countryCode ' => (string )$ billingAddress ->getCountry (),
138
99
);
139
100
101
+ if (!$ object ->isVirtual ())
102
+ {
103
+ $ shippingAddress = $ object ->getShippingAddress ();
104
+ $ shippingMethods = $ shippingAddress ->getShippingRatesCollection ();
105
+
106
+ foreach ($ shippingMethods as $ method ) {
107
+ $ params ['courier ' ] = array (
108
+ 'name ' => substr ($ method ->getMethodTitle () . " " . $ method ->getCarrierTitle (), 0 , 128 ),
109
+ 'priority ' => "STANDARD " ,
110
+ );
111
+ }
112
+
113
+ if ($ shippingAddress ->getShippingInclTax ()) {
114
+ $ params ['shippingAmount ' ] = array (
115
+ 'amount ' => number_format ((float )$ shippingAddress ->getShippingInclTax (), $ precision , '. ' , '' ), // with tax
116
+ 'currency ' => (string )Mage::app ()->getStore ()->getCurrentCurrencyCode ()
117
+ );
118
+ }
119
+
120
+ if ( !empty ( $ shippingAddress ) ) {
121
+ if ( !empty ( $ shippingAddress ->getStreet1 () ) ) {
122
+ $ params ['shipping ' ] = array (
123
+ 'name ' => (string )$ shippingAddress ->getFirstname () . ' ' . $ shippingAddress ->getLastname (),
124
+ 'line1 ' => (string )$ shippingAddress ->getStreet1 (),
125
+ 'line2 ' => (string )$ shippingAddress ->getStreet2 (),
126
+ 'suburb ' => (string )$ shippingAddress ->getCity (),
127
+ 'postcode ' => (string )$ shippingAddress ->getPostcode (),
128
+ 'state ' => (string )$ shippingAddress ->getRegion (),
129
+ 'phoneNumber ' => (string )$ shippingAddress ->getTelephone (),
130
+ 'countryCode ' => (string )$ shippingAddress ->getCountry (),
131
+ );
132
+ }
133
+ }
134
+ }
135
+
140
136
$ params ['totalAmount ' ] = array (
141
- 'amount ' => round ((float )$ object ->getGrandTotal (), $ precision ),
137
+ 'amount ' => number_format ((float )$ object ->getGrandTotal (), $ precision, ' . ' , '' ),
142
138
'currency ' => (string )Mage::app ()->getStore ()->getCurrentCurrencyCode (),
143
139
);
144
140
@@ -175,7 +171,7 @@ public function buildDirectCaptureRequest($orderToken, $merchantOrderId)
175
171
public function buildRefundRequest ($ amount , $ payment )
176
172
{
177
173
$ params ['amount ' ] = array (
178
- 'amount ' => abs ( round ( $ amount , 2 ) ), // Afterpay API Ver 1 requires a positive amount
174
+ 'amount ' => number_format ( $ amount , 2 , ' . ' , '' ),
179
175
'currency ' => $ payment ->getOrder ()->getOrderCurrencyCode (),
180
176
);
181
177
@@ -228,7 +224,7 @@ private function _validateData( $object ) {
228
224
229
225
if (!$ object ->isVirtual ()) {
230
226
$ shippingAddress = $ object ->getShippingAddress ();
231
-
227
+
232
228
$ shipping_postcode = $ shippingAddress ->getPostcode ();
233
229
$ shipping_telephone = $ shippingAddress ->getTelephone ();
234
230
$ shipping_city = $ shippingAddress ->getCity ();
0 commit comments