| Total Complexity | 73 |
| Total Lines | 862 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like PayPalExpress often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PayPalExpress, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class PayPalExpress |
||
| 22 | extends \Aimeos\MShop\Service\Provider\Payment\Base |
||
| 23 | implements \Aimeos\MShop\Service\Provider\Payment\Iface |
||
| 24 | { |
||
| 25 | private $apiendpoint; |
||
| 26 | |||
| 27 | private $beConfig = array( |
||
| 28 | 'paypalexpress.ApiUsername' => array( |
||
| 29 | 'code' => 'paypalexpress.ApiUsername', |
||
| 30 | 'internalcode' => 'paypalexpress.ApiUsername', |
||
| 31 | 'label' => 'Username', |
||
| 32 | 'type' => 'string', |
||
| 33 | 'internaltype' => 'string', |
||
| 34 | 'default' => '', |
||
| 35 | 'required' => true, |
||
| 36 | ), |
||
| 37 | 'paypalexpress.AccountEmail' => array( |
||
| 38 | 'code' => 'paypalexpress.AccountEmail', |
||
| 39 | 'internalcode' => 'paypalexpress.AccountEmail', |
||
| 40 | 'label' => 'Registered e-mail address of the shop owner in PayPal', |
||
| 41 | 'type' => 'string', |
||
| 42 | 'internaltype' => 'string', |
||
| 43 | 'default' => '', |
||
| 44 | 'required' => true, |
||
| 45 | ), |
||
| 46 | 'paypalexpress.ApiPassword' => array( |
||
| 47 | 'code' => 'paypalexpress.ApiPassword', |
||
| 48 | 'internalcode' => 'paypalexpress.ApiPassword', |
||
| 49 | 'label' => 'Password', |
||
| 50 | 'type' => 'string', |
||
| 51 | 'internaltype' => 'string', |
||
| 52 | 'default' => '', |
||
| 53 | 'required' => true, |
||
| 54 | ), |
||
| 55 | 'paypalexpress.ApiSignature' => array( |
||
| 56 | 'code' => 'paypalexpress.ApiSignature', |
||
| 57 | 'internalcode' => 'paypalexpress.ApiSignature', |
||
| 58 | 'label' => 'Signature', |
||
| 59 | 'type' => 'string', |
||
| 60 | 'internaltype' => 'string', |
||
| 61 | 'default' => '', |
||
| 62 | 'required' => true, |
||
| 63 | ), |
||
| 64 | 'paypalexpress.ApiEndpoint' => array( |
||
| 65 | 'code' => 'paypalexpress.ApiEndpoint', |
||
| 66 | 'internalcode' => 'paypalexpress.ApiEndpoint', |
||
| 67 | 'label' => 'APIEndpoint', |
||
| 68 | 'type' => 'string', |
||
| 69 | 'internaltype' => 'string', |
||
| 70 | 'default' => 'https://api-3t.paypal.com/nvp', |
||
| 71 | 'required' => false, |
||
| 72 | ), |
||
| 73 | 'paypalexpress.PaypalUrl' => array( |
||
| 74 | 'code' => 'paypalexpress.PaypalUrl', |
||
| 75 | 'internalcode' => 'paypalexpress.PaypalUrl', |
||
| 76 | 'label' => 'PaypalUrl', |
||
| 77 | 'type' => 'string', |
||
| 78 | 'internaltype' => 'string', |
||
| 79 | 'default' => 'https://www.paypal.com/webscr&cmd=_express-checkout&useraction=commit&token=%1$s', |
||
| 80 | 'required' => false, |
||
| 81 | ), |
||
| 82 | 'paypalexpress.PaymentAction' => array( |
||
| 83 | 'code' => 'paypalexpress.PaymentAction', |
||
| 84 | 'internalcode' => 'paypalexpress.PaymentAction', |
||
| 85 | 'label' => 'PaymentAction', |
||
| 86 | 'type' => 'string', |
||
| 87 | 'internaltype' => 'string', |
||
| 88 | 'default' => 'Sale', |
||
| 89 | 'required' => false, |
||
| 90 | ), |
||
| 91 | 'paypalexpress.LandingPage' => array( |
||
| 92 | 'code' => 'paypalexpress.LandingPage', |
||
| 93 | 'internalcode' => 'paypalexpress.LandingPage', |
||
| 94 | 'label' => 'Landing page', |
||
| 95 | 'type' => 'string', |
||
| 96 | 'internaltype' => 'string', |
||
| 97 | 'default' => 'Login', |
||
| 98 | 'required' => false, |
||
| 99 | ), |
||
| 100 | 'paypalexpress.FundingSource' => array( |
||
| 101 | 'code' => 'paypalexpress.FundingSource', |
||
| 102 | 'internalcode' => 'paypalexpress.FundingSource', |
||
| 103 | 'label' => 'Funding source', |
||
| 104 | 'type' => 'string', |
||
| 105 | 'internaltype' => 'string', |
||
| 106 | 'default' => 'CreditCard', |
||
| 107 | 'required' => false, |
||
| 108 | ), |
||
| 109 | 'paypalexpress.AddrOverride' => array( |
||
| 110 | 'code' => 'paypalexpress.AddrOverride', |
||
| 111 | 'internalcode' => 'paypalexpress.AddrOverride', |
||
| 112 | 'label' => 'Customer can change address', |
||
| 113 | 'type' => 'boolean', |
||
| 114 | 'internaltype' => 'integer', |
||
| 115 | 'default' => 0, |
||
| 116 | 'required' => false, |
||
| 117 | ), |
||
| 118 | 'paypalexpress.NoShipping' => array( |
||
| 119 | 'code' => 'paypalexpress.NoShipping', |
||
| 120 | 'internalcode' => 'paypalexpress.NoShipping', |
||
| 121 | 'label' => 'Don\'t display shipping address', |
||
| 122 | 'type' => 'boolean', |
||
| 123 | 'internaltype' => 'integer', |
||
| 124 | 'default' => 1, |
||
| 125 | 'required' => false, |
||
| 126 | ), |
||
| 127 | 'paypalexpress.address' => array( |
||
| 128 | 'code' => 'paypalexpress.address', |
||
| 129 | 'internalcode' => 'paypalexpress.address', |
||
| 130 | 'label' => 'Pass customer address to PayPal', |
||
| 131 | 'type' => 'boolean', |
||
| 132 | 'internaltype' => 'integer', |
||
| 133 | 'default' => 1, |
||
| 134 | 'required' => false, |
||
| 135 | ), |
||
| 136 | 'paypalexpress.product' => array( |
||
| 137 | 'code' => 'paypalexpress.product', |
||
| 138 | 'internalcode' => 'paypalexpress.product', |
||
| 139 | 'label' => 'Pass product details to PayPal', |
||
| 140 | 'type' => 'boolean', |
||
| 141 | 'internaltype' => 'integer', |
||
| 142 | 'default' => 1, |
||
| 143 | 'required' => false, |
||
| 144 | ), |
||
| 145 | 'paypalexpress.service' => array( |
||
| 146 | 'code' => 'paypalexpress.service', |
||
| 147 | 'internalcode' => 'paypalexpress.service', |
||
| 148 | 'label' => 'Pass delivery/payment details to PayPal', |
||
| 149 | 'type' => 'boolean', |
||
| 150 | 'internaltype' => 'integer', |
||
| 151 | 'default' => 1, |
||
| 152 | 'required' => false, |
||
| 153 | ), |
||
| 154 | 'paypalexpress.url-validate' => array( |
||
| 155 | 'code' => 'paypalexpress.url-validate', |
||
| 156 | 'internalcode' => 'paypalexpress.url-validate', |
||
| 157 | 'label' => 'Validation URL', |
||
| 158 | 'type' => 'string', |
||
| 159 | 'internaltype' => 'string', |
||
| 160 | 'default' => 'https://www.paypal.com/webscr&cmd=_notify-validate', |
||
| 161 | 'required' => false, |
||
| 162 | ), |
||
| 163 | 'paypalexpress.LocaleCode' => array( |
||
| 164 | 'code' => 'paypalexpress.LocaleCode', |
||
| 165 | 'internalcode' => 'paypalexpress.LocaleCode', |
||
| 166 | 'label' => 'Locale code', |
||
| 167 | 'type' => 'string', |
||
| 168 | 'internaltype' => 'string', |
||
| 169 | 'default' => '', |
||
| 170 | 'required' => false, |
||
| 171 | ), |
||
| 172 | ); |
||
| 173 | |||
| 174 | |||
| 175 | /** |
||
| 176 | * Initializes the provider object. |
||
| 177 | * |
||
| 178 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
| 179 | * @param \Aimeos\MShop\Service\Item\Iface $serviceItem Service item with configuration |
||
| 180 | * @throws \Aimeos\MShop\Service\Exception If one of the required configuration values isn't available |
||
| 181 | */ |
||
| 182 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Service\Item\Iface $serviceItem ) |
||
| 183 | { |
||
| 184 | parent::__construct( $context, $serviceItem ); |
||
| 185 | |||
| 186 | $default = 'https://api-3t.paypal.com/nvp'; |
||
| 187 | $this->apiendpoint = $this->getConfigValue( array( 'paypalexpress.ApiEndpoint' ), $default ); |
||
| 188 | } |
||
| 189 | |||
| 190 | |||
| 191 | /** |
||
| 192 | * Returns the configuration attribute definitions of the provider to generate a list of available fields and |
||
| 193 | * rules for the value of each field in the administration interface. |
||
| 194 | * |
||
| 195 | * @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface |
||
| 196 | */ |
||
| 197 | public function getConfigBE() : array |
||
| 198 | { |
||
| 199 | return $this->getConfigItems( $this->beConfig ); |
||
| 200 | } |
||
| 201 | |||
| 202 | |||
| 203 | /** |
||
| 204 | * Checks the backend configuration attributes for validity. |
||
| 205 | * |
||
| 206 | * @param array $attributes Attributes added by the shop owner in the administraton interface |
||
| 207 | * @return array An array with the attribute keys as key and an error message as values for all attributes that are |
||
| 208 | * known by the provider but aren't valid |
||
| 209 | */ |
||
| 210 | public function checkConfigBE( array $attributes ) : array |
||
| 211 | { |
||
| 212 | $errors = parent::checkConfigBE( $attributes ); |
||
| 213 | |||
| 214 | return array_merge( $errors, $this->checkConfig( $this->beConfig, $attributes ) ); |
||
| 215 | } |
||
| 216 | |||
| 217 | |||
| 218 | /** |
||
| 219 | * Tries to get an authorization or captures the money immediately for the given order if capturing the money |
||
| 220 | * separately isn't supported or not configured by the shop owner. |
||
| 221 | * |
||
| 222 | * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object |
||
| 223 | * @param array $params Request parameter if available |
||
| 224 | * @return \Aimeos\MShop\Common\Helper\Form\Iface|null Form object with URL, action and parameters to redirect to |
||
| 225 | * (e.g. to an external server of the payment provider or to a local success page) |
||
| 226 | */ |
||
| 227 | public function process( \Aimeos\MShop\Order\Item\Iface $order, array $params = [] ) : ?\Aimeos\MShop\Common\Helper\Form\Iface |
||
| 228 | { |
||
| 229 | $orderBaseItem = $this->getOrderBase( $order->getBaseId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL ); |
||
|
|
|||
| 230 | |||
| 231 | $values = $this->getOrderDetails( $orderBaseItem ); |
||
| 232 | $values['METHOD'] = 'SetExpressCheckout'; |
||
| 233 | $values['PAYMENTREQUEST_0_INVNUM'] = $order->getId(); |
||
| 234 | $values['RETURNURL'] = $this->getConfigValue( array( 'payment.url-success' ) ); |
||
| 235 | $values['CANCELURL'] = $this->getConfigValue( array( 'payment.url-cancel', 'payment.url-success' ) ); |
||
| 236 | $values['USERSELECTEDFUNDINGSOURCE'] = $this->getConfigValue( array( 'paypalexpress.FundingSource' ), 'CreditCard' ); |
||
| 237 | $values['LANDINGPAGE'] = $this->getConfigValue( array( 'paypalexpress.LandingPage' ), 'Login' ); |
||
| 238 | |||
| 239 | $urlQuery = http_build_query( $values, '', '&' ); |
||
| 240 | $response = $this->send( $this->apiendpoint, 'POST', $urlQuery ); |
||
| 241 | $rvals = $this->checkResponse( $order->getId(), $response, __METHOD__ ); |
||
| 242 | |||
| 243 | $default = 'https://www.paypal.com/webscr&cmd=_express-checkout&useraction=commit&token=%1$s'; |
||
| 244 | $paypalUrl = sprintf( $this->getConfigValue( array( 'paypalexpress.PaypalUrl' ), $default ), $rvals['TOKEN'] ); |
||
| 245 | |||
| 246 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
||
| 247 | $serviceItem = $this->getBasketService( $orderBaseItem, $type, $this->getServiceItem()->getCode() ); |
||
| 248 | $this->setAttributes( $serviceItem, ['TOKEN' => $rvals['TOKEN']], 'payment/paypal' ); |
||
| 249 | $this->saveOrderBase( $orderBaseItem ); |
||
| 250 | |||
| 251 | return new \Aimeos\MShop\Common\Helper\Form\Standard( $paypalUrl, 'POST', [] ); |
||
| 252 | } |
||
| 253 | |||
| 254 | |||
| 255 | /** |
||
| 256 | * Queries for status updates for the given order if supported. |
||
| 257 | * |
||
| 258 | * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object |
||
| 259 | * @return \Aimeos\MShop\Order\Item\Iface Updated order item object |
||
| 260 | */ |
||
| 261 | public function query( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface |
||
| 262 | { |
||
| 263 | if( ( $tid = $this->getOrderServiceItem( $order->getBaseId() )->getAttribute( 'TRANSACTIONID', 'payment/paypal' ) ) === null ) |
||
| 264 | { |
||
| 265 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Payment transaction ID for order ID "%1$s" not available' ); |
||
| 266 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $order->getId() ) ); |
||
| 267 | } |
||
| 268 | |||
| 269 | $values = $this->getAuthParameter(); |
||
| 270 | $values['METHOD'] = 'GetTransactionDetails'; |
||
| 271 | $values['TRANSACTIONID'] = $tid; |
||
| 272 | |||
| 273 | $urlQuery = http_build_query( $values, '', '&' ); |
||
| 274 | $response = $this->send( $this->apiendpoint, 'POST', $urlQuery ); |
||
| 275 | $rvals = $this->checkResponse( $order->getId(), $response, __METHOD__ ); |
||
| 276 | |||
| 277 | $this->setStatusPayment( $order, $rvals ); |
||
| 278 | return $this->saveOrder( $order ); |
||
| 279 | } |
||
| 280 | |||
| 281 | |||
| 282 | /** |
||
| 283 | * Captures the money later on request for the given order if supported. |
||
| 284 | * |
||
| 285 | * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object |
||
| 286 | * @return \Aimeos\MShop\Order\Item\Iface Updated order item object |
||
| 287 | */ |
||
| 288 | public function capture( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface |
||
| 289 | { |
||
| 290 | $baseItem = $this->getOrderBase( $order->getBaseId() ); |
||
| 291 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
||
| 292 | $serviceItem = $this->getBasketService( $baseItem, $type, $this->getServiceItem()->getCode() ); |
||
| 293 | |||
| 294 | if( ( $tid = $serviceItem->getAttribute( 'TRANSACTIONID', 'payment/paypal' ) ) === null ) |
||
| 295 | { |
||
| 296 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Payment transaction ID for order ID "%1$s" not available' ); |
||
| 297 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $order->getId() ) ); |
||
| 298 | } |
||
| 299 | |||
| 300 | $price = $baseItem->getPrice(); |
||
| 301 | |||
| 302 | $values = $this->getAuthParameter(); |
||
| 303 | $values['METHOD'] = 'DoCapture'; |
||
| 304 | $values['COMPLETETYPE'] = 'Complete'; |
||
| 305 | $values['AUTHORIZATIONID'] = $tid; |
||
| 306 | $values['INVNUM'] = $order->getId(); |
||
| 307 | $values['CURRENCYCODE'] = $price->getCurrencyId(); |
||
| 308 | $values['AMT'] = $this->getAmount( $price ); |
||
| 309 | |||
| 310 | $urlQuery = http_build_query( $values, '', '&' ); |
||
| 311 | $response = $this->send( $this->apiendpoint, 'POST', $urlQuery ); |
||
| 312 | $rvals = $this->checkResponse( $order->getId(), $response, __METHOD__ ); |
||
| 313 | |||
| 314 | $this->setStatusPayment( $order, $rvals ); |
||
| 315 | |||
| 316 | $attributes = []; |
||
| 317 | if( isset( $rvals['PARENTTRANSACTIONID'] ) ) { |
||
| 318 | $attributes['PARENTTRANSACTIONID'] = $rvals['PARENTTRANSACTIONID']; |
||
| 319 | } |
||
| 320 | |||
| 321 | //updates the transaction id |
||
| 322 | $attributes['TRANSACTIONID'] = $rvals['TRANSACTIONID']; |
||
| 323 | $this->setAttributes( $serviceItem, $attributes, 'payment/paypal' ); |
||
| 324 | |||
| 325 | $this->saveOrderBase( $baseItem ); |
||
| 326 | return $this->saveOrder( $order ); |
||
| 327 | } |
||
| 328 | |||
| 329 | |||
| 330 | /** |
||
| 331 | * Refunds the money for the given order if supported. |
||
| 332 | * |
||
| 333 | * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object |
||
| 334 | * @return \Aimeos\MShop\Order\Item\Iface Updated order item object |
||
| 335 | */ |
||
| 336 | public function refund( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface |
||
| 337 | { |
||
| 338 | $baseItem = $this->getOrderBase( $order->getBaseId() ); |
||
| 339 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
||
| 340 | $serviceItem = $this->getBasketService( $baseItem, $type, $this->getServiceItem()->getCode() ); |
||
| 341 | |||
| 342 | if( ( $tid = $serviceItem->getAttribute( 'TRANSACTIONID', 'payment/paypal' ) ) === null ) |
||
| 343 | { |
||
| 344 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Payment transaction ID for order ID "%1$s" not available' ); |
||
| 345 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $order->getId() ) ); |
||
| 346 | } |
||
| 347 | |||
| 348 | $values = $this->getAuthParameter(); |
||
| 349 | $values['METHOD'] = 'RefundTransaction'; |
||
| 350 | $values['REFUNDSOURCE'] = 'instant'; |
||
| 351 | $values['REFUNDTYPE'] = 'Full'; |
||
| 352 | $values['TRANSACTIONID'] = $tid; |
||
| 353 | $values['INVOICEID'] = $order->getId(); |
||
| 354 | |||
| 355 | $urlQuery = http_build_query( $values, '', '&' ); |
||
| 356 | $response = $this->send( $this->apiendpoint, 'POST', $urlQuery ); |
||
| 357 | $rvals = $this->checkResponse( $order->getId(), $response, __METHOD__ ); |
||
| 358 | |||
| 359 | $attributes = array( 'REFUNDTRANSACTIONID' => $rvals['REFUNDTRANSACTIONID'] ); |
||
| 360 | $this->setAttributes( $serviceItem, $attributes, 'payment/paypal' ); |
||
| 361 | $this->saveOrderBase( $baseItem ); |
||
| 362 | |||
| 363 | $order->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_REFUND ); |
||
| 364 | return $this->saveOrder( $order ); |
||
| 365 | } |
||
| 366 | |||
| 367 | |||
| 368 | /** |
||
| 369 | * Cancels the authorization for the given order if supported. |
||
| 370 | * |
||
| 371 | * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object |
||
| 372 | * @return \Aimeos\MShop\Order\Item\Iface Updated order item object |
||
| 373 | */ |
||
| 374 | public function cancel( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface |
||
| 375 | { |
||
| 376 | if( ( $tid = $this->getOrderServiceItem( $order->getBaseId() )->getAttribute( 'TRANSACTIONID', 'payment/paypal' ) ) === null ) |
||
| 377 | { |
||
| 378 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Payment transaction ID for order ID "%1$s" not available' ); |
||
| 379 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $order->getId() ) ); |
||
| 380 | } |
||
| 381 | |||
| 382 | $values = $this->getAuthParameter(); |
||
| 383 | $values['METHOD'] = 'DoVoid'; |
||
| 384 | $values['AUTHORIZATIONID'] = $tid; |
||
| 385 | |||
| 386 | $urlQuery = http_build_query( $values, '', '&' ); |
||
| 387 | $response = $this->send( $this->apiendpoint, 'POST', $urlQuery ); |
||
| 388 | $this->checkResponse( $order->getId(), $response, __METHOD__ ); |
||
| 389 | |||
| 390 | $order->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_CANCELED ); |
||
| 391 | return $this->saveOrder( $order ); |
||
| 392 | } |
||
| 393 | |||
| 394 | |||
| 395 | /** |
||
| 396 | * Updates the order status sent by payment gateway notifications |
||
| 397 | * |
||
| 398 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||
| 399 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
||
| 400 | * @return \Psr\Http\Message\ResponseInterface Response object |
||
| 401 | */ |
||
| 402 | public function updatePush( \Psr\Http\Message\ServerRequestInterface $request, |
||
| 403 | \Psr\Http\Message\ResponseInterface $response ) : \Psr\Http\Message\ResponseInterface |
||
| 404 | { |
||
| 405 | $params = $request->getQueryParams(); |
||
| 406 | |||
| 407 | if( !isset( $params['txn_id'] ) ) { //tid from ipn |
||
| 408 | return $response->withStatus( 400, 'PayPal Express: Parameter "txn_id" is missing' ); |
||
| 409 | } |
||
| 410 | |||
| 411 | $urlQuery = http_build_query( $params, '', '&' ); |
||
| 412 | |||
| 413 | //validation |
||
| 414 | $result = $this->send( $this->getConfigValue( array( 'paypalexpress.url-validate' ) ), 'POST', $urlQuery ); |
||
| 415 | |||
| 416 | if( $result !== 'VERIFIED' ) { |
||
| 417 | return $response->withStatus( 400, sprintf( 'PayPal Express: Invalid request "%1$s"', $urlQuery ) ); |
||
| 418 | } |
||
| 419 | |||
| 420 | |||
| 421 | $order = $this->getOrder( $params['invoice'] ); |
||
| 422 | $baseItem = $this->getOrderBase( $order->getBaseId() ); |
||
| 423 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
||
| 424 | $serviceItem = $this->getBasketService( $baseItem, $type, $this->getServiceItem()->getCode() ); |
||
| 425 | |||
| 426 | $this->checkIPN( $baseItem, $params ); |
||
| 427 | |||
| 428 | $status = array( 'PAYMENTSTATUS' => $params['payment_status'] ); |
||
| 429 | |||
| 430 | if( isset( $params['pending_reason'] ) ) { |
||
| 431 | $status['PENDINGREASON'] = $params['pending_reason']; |
||
| 432 | } |
||
| 433 | |||
| 434 | $this->setAttributes( $serviceItem, array( $params['txn_id'] => $params['payment_status'] ), 'payment/paypal/txn' ); |
||
| 435 | $this->setAttributes( $serviceItem, array( 'TRANSACTIONID' => $params['txn_id'] ), 'payment/paypal' ); |
||
| 436 | $this->saveOrderBase( $baseItem ); |
||
| 437 | |||
| 438 | $this->setStatusPayment( $order, $status ); |
||
| 439 | $this->saveOrder( $order ); |
||
| 440 | |||
| 441 | return $response->withStatus( 200 ); |
||
| 442 | } |
||
| 443 | |||
| 444 | |||
| 445 | /** |
||
| 446 | * Updates the orders for whose status updates have been received by the confirmation page |
||
| 447 | * |
||
| 448 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object with parameters and request body |
||
| 449 | * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item that should be updated |
||
| 450 | * @return \Aimeos\MShop\Order\Item\Iface Updated order item |
||
| 451 | * @throws \Aimeos\MShop\Service\Exception If updating the orders failed |
||
| 452 | */ |
||
| 453 | public function updateSync( \Psr\Http\Message\ServerRequestInterface $request, |
||
| 454 | \Aimeos\MShop\Order\Item\Iface $orderItem ) : \Aimeos\MShop\Order\Item\Iface |
||
| 455 | { |
||
| 456 | $params = (array) $request->getAttributes() + (array) $request->getParsedBody() + (array) $request->getQueryParams(); |
||
| 457 | |||
| 458 | if( !isset( $params['token'] ) ) |
||
| 459 | { |
||
| 460 | $msg = sprintf( $this->context()->getI18n()->dt( 'mshop', 'Required parameter "%1$s" is missing' ), 'token' ); |
||
| 461 | throw new \Aimeos\MShop\Service\Exception( $msg ); |
||
| 462 | } |
||
| 463 | |||
| 464 | if( !isset( $params['PayerID'] ) ) |
||
| 465 | { |
||
| 466 | $msg = sprintf( $this->context()->getI18n()->dt( 'mshop', 'Required parameter "%1$s" is missing' ), 'PayerID' ); |
||
| 467 | throw new \Aimeos\MShop\Service\Exception( $msg ); |
||
| 468 | } |
||
| 469 | |||
| 470 | $baseItem = $this->getOrderBase( $orderItem->getBaseId() ); |
||
| 471 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
||
| 472 | $serviceItem = $this->getBasketService( $baseItem, $type, $this->getServiceItem()->getCode() ); |
||
| 473 | |||
| 474 | $price = $baseItem->getPrice(); |
||
| 475 | |||
| 476 | $values = $this->getAuthParameter(); |
||
| 477 | $values['METHOD'] = 'DoExpressCheckoutPayment'; |
||
| 478 | $values['TOKEN'] = $params['token']; |
||
| 479 | $values['PAYERID'] = $params['PayerID']; |
||
| 480 | $values['PAYMENTACTION'] = $this->getConfigValue( array( 'paypalexpress.PaymentAction' ), 'Sale' ); |
||
| 481 | $values['CURRENCYCODE'] = $price->getCurrencyId(); |
||
| 482 | $values['AMT'] = $this->getAmount( $price ); |
||
| 483 | |||
| 484 | $urlQuery = http_build_query( $values, '', '&' ); |
||
| 485 | $response = $this->send( $this->apiendpoint, 'POST', $urlQuery ); |
||
| 486 | $rvals = $this->checkResponse( $orderItem->getId(), $response, __METHOD__ ); |
||
| 487 | |||
| 488 | $attributes = array( 'PAYERID' => $params['PayerID'] ); |
||
| 489 | |||
| 490 | if( isset( $rvals['TRANSACTIONID'] ) ) |
||
| 491 | { |
||
| 492 | $attributes['TRANSACTIONID'] = $rvals['TRANSACTIONID']; |
||
| 493 | $this->setAttributes( $serviceItem, array( $rvals['TRANSACTIONID'] => $rvals['PAYMENTSTATUS'] ), 'payment/paypal/txn' ); |
||
| 494 | } |
||
| 495 | |||
| 496 | $this->setAttributes( $serviceItem, $attributes, 'payment/paypal' ); |
||
| 497 | $this->saveOrderBase( $baseItem ); |
||
| 498 | |||
| 499 | $this->setStatusPayment( $orderItem, $rvals ); |
||
| 500 | return $this->saveOrder( $orderItem ); |
||
| 501 | } |
||
| 502 | |||
| 503 | |||
| 504 | /** |
||
| 505 | * Checks what features the payment provider implements. |
||
| 506 | * |
||
| 507 | * @param int $what Constant from abstract class |
||
| 508 | * @return bool True if feature is available in the payment provider, false if not |
||
| 509 | */ |
||
| 510 | public function isImplemented( int $what ) : bool |
||
| 511 | { |
||
| 512 | switch( $what ) |
||
| 513 | { |
||
| 514 | case \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_CAPTURE: |
||
| 515 | case \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_QUERY: |
||
| 516 | case \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_CANCEL: |
||
| 517 | case \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_REFUND: |
||
| 518 | return true; |
||
| 519 | } |
||
| 520 | |||
| 521 | return false; |
||
| 522 | } |
||
| 523 | |||
| 524 | |||
| 525 | /** |
||
| 526 | * Checks the response from the payment server. |
||
| 527 | * |
||
| 528 | * @param string $orderid Order item ID |
||
| 529 | * @param string $response Response from the payment provider |
||
| 530 | * @param string $method Name of the calling method |
||
| 531 | * @return array Associative list of key/value pairs containing the response parameters |
||
| 532 | * @throws \Aimeos\MShop\Service\Exception If request was not successful and an error was returned |
||
| 533 | */ |
||
| 534 | protected function checkResponse( string $orderid, string $response, string $method ) : array |
||
| 535 | { |
||
| 536 | $rvals = []; |
||
| 537 | parse_str( $response, $rvals ); |
||
| 538 | |||
| 539 | if( $rvals['ACK'] !== 'Success' ) |
||
| 540 | { |
||
| 541 | $msg = 'PayPal Express: method = ' . $method . ', order ID = ' . $orderid . ', response = ' . print_r( $rvals, true ); |
||
| 542 | $this->context()->getLogger()->log( $msg, \Aimeos\MW\Logger\Base::WARN, 'core/service/paypalexpress' ); |
||
| 543 | |||
| 544 | if( $rvals['ACK'] !== 'SuccessWithWarning' ) |
||
| 545 | { |
||
| 546 | $short = ( isset( $rvals['L_SHORTMESSAGE0'] ) ? $rvals['L_SHORTMESSAGE0'] : '<none>' ); |
||
| 547 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Request for order ID "%1$s" failed with "%2$s"' ); |
||
| 548 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $orderid, $short ) ); |
||
| 549 | } |
||
| 550 | } |
||
| 551 | |||
| 552 | return $rvals; |
||
| 553 | } |
||
| 554 | |||
| 555 | |||
| 556 | /** |
||
| 557 | * Checks if IPN message from paypal is valid. |
||
| 558 | * |
||
| 559 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Order base item |
||
| 560 | * @param array $params List of parameters |
||
| 561 | * @return \Aimeos\MShop\Service\Provider\Payment\Iface Same object for fluent interface |
||
| 562 | */ |
||
| 563 | protected function checkIPN( \Aimeos\MShop\Order\Item\Base\Iface $basket, |
||
| 564 | array $params ) : \Aimeos\MShop\Service\Provider\Payment\Iface |
||
| 565 | { |
||
| 566 | $attrManager = \Aimeos\MShop::create( $this->context(), 'order/base/service/attribute' ); |
||
| 567 | |||
| 568 | if( $this->getConfigValue( array( 'paypalexpress.AccountEmail' ) ) !== $params['receiver_email'] ) |
||
| 569 | { |
||
| 570 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Wrong receiver email "%1$s"' ); |
||
| 571 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $params['receiver_email'] ) ); |
||
| 572 | } |
||
| 573 | |||
| 574 | $price = $basket->getPrice(); |
||
| 575 | |||
| 576 | if( $this->getAmount( $price ) != $params['payment_amount'] ) |
||
| 577 | { |
||
| 578 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Wrong payment amount "%1$s" for order ID "%2$s"' ); |
||
| 579 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $params['payment_amount'], $params['invoice'] ) ); |
||
| 580 | } |
||
| 581 | |||
| 582 | $search = $attrManager->filter(); |
||
| 583 | $expr = array( |
||
| 584 | $search->compare( '==', 'order.base.service.attribute.code', $params['txn_id'] ), |
||
| 585 | $search->compare( '==', 'order.base.service.attribute.value', $params['payment_status'] ), |
||
| 586 | ); |
||
| 587 | |||
| 588 | $search->setConditions( $search->and( $expr ) ); |
||
| 589 | |||
| 590 | if( !$attrManager->search( $search )->isEmpty() ) |
||
| 591 | { |
||
| 592 | $msg = $this->context()->getI18n()->dt( 'mshop', 'PayPal Express: Duplicate transaction with ID "%1$s" and status "%2$s"' ); |
||
| 593 | throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $params['txn_id'], $params['txn_status'] ) ); |
||
| 594 | } |
||
| 595 | |||
| 596 | return $this; |
||
| 597 | } |
||
| 598 | |||
| 599 | |||
| 600 | /** |
||
| 601 | * Maps the PayPal status to the appropriate payment status and sets it in the order object. |
||
| 602 | * |
||
| 603 | * @param \Aimeos\MShop\Order\Item\Iface $invoice Order invoice object |
||
| 604 | * @param array $response Associative list of key/value pairs containing the PayPal response |
||
| 605 | * @return \Aimeos\MShop\Order\Item\Iface Updated order item object |
||
| 606 | */ |
||
| 607 | protected function setStatusPayment( \Aimeos\MShop\Order\Item\Iface $invoice, array $response ) : \Aimeos\MShop\Order\Item\Iface |
||
| 608 | { |
||
| 609 | if( !isset( $response['PAYMENTSTATUS'] ) ) { |
||
| 610 | return $invoice; |
||
| 611 | } |
||
| 612 | |||
| 613 | switch( $response['PAYMENTSTATUS'] ) |
||
| 614 | { |
||
| 615 | case 'Pending': |
||
| 616 | if( isset( $response['PENDINGREASON'] ) ) |
||
| 617 | { |
||
| 618 | if( $response['PENDINGREASON'] === 'authorization' ) |
||
| 619 | { |
||
| 620 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED ); |
||
| 621 | break; |
||
| 622 | } |
||
| 623 | |||
| 624 | $str = 'PayPal Express: order ID = ' . $invoice->getId() . ', PENDINGREASON = ' . $response['PENDINGREASON']; |
||
| 625 | $this->context()->getLogger()->log( $str, \Aimeos\MW\Logger\Base::INFO, 'core/service/paypalexpress' ); |
||
| 626 | } |
||
| 627 | |||
| 628 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_PENDING ); |
||
| 629 | break; |
||
| 630 | |||
| 631 | case 'In-Progress': |
||
| 632 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_PENDING ); |
||
| 633 | break; |
||
| 634 | |||
| 635 | case 'Completed': |
||
| 636 | case 'Processed': |
||
| 637 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED ); |
||
| 638 | break; |
||
| 639 | |||
| 640 | case 'Failed': |
||
| 641 | case 'Denied': |
||
| 642 | case 'Expired': |
||
| 643 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_REFUSED ); |
||
| 644 | break; |
||
| 645 | |||
| 646 | case 'Refunded': |
||
| 647 | case 'Partially-Refunded': |
||
| 648 | case 'Reversed': |
||
| 649 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_REFUND ); |
||
| 650 | break; |
||
| 651 | |||
| 652 | case 'Canceled-Reversal': |
||
| 653 | case 'Voided': |
||
| 654 | $invoice->setStatusPayment( \Aimeos\MShop\Order\Item\Base::PAY_CANCELED ); |
||
| 655 | break; |
||
| 656 | |||
| 657 | default: |
||
| 658 | $str = 'PayPal Express: order ID = ' . $invoice->getId() . ', response = ' . print_r( $response, true ); |
||
| 659 | $this->context()->getLogger()->log( $str, \Aimeos\MW\Logger\Base::INFO, 'core/service/paypalexpress' ); |
||
| 660 | } |
||
| 661 | |||
| 662 | return $invoice; |
||
| 663 | } |
||
| 664 | |||
| 665 | |||
| 666 | /** |
||
| 667 | * Returns an list of order data required by PayPal. |
||
| 668 | * |
||
| 669 | * @param \Aimeos\MShop\Order\Item\Base\Iface $orderBase Order base item |
||
| 670 | * @return array Associative list of key/value pairs with order data required by PayPal |
||
| 671 | */ |
||
| 672 | protected function getOrderDetails( \Aimeos\MShop\Order\Item\Base\Iface $orderBase ) : array |
||
| 673 | { |
||
| 674 | $lastPos = 0; |
||
| 675 | $deliveryPrices = []; |
||
| 676 | $values = $this->getAuthParameter(); |
||
| 677 | |||
| 678 | |||
| 679 | if( $this->getConfigValue( 'paypalexpress.address', true ) ) |
||
| 680 | { |
||
| 681 | if( ( $addresses = $orderBase->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY ) ) === [] ) { |
||
| 682 | $addresses = $orderBase->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
||
| 683 | } |
||
| 684 | |||
| 685 | if( $address = current( $addresses ) ) |
||
| 686 | { |
||
| 687 | /* setting up the address details */ |
||
| 688 | $values['NOSHIPPING'] = $this->getConfigValue( array( 'paypalexpress.NoShipping' ), 1 ); |
||
| 689 | $values['ADDROVERRIDE'] = $this->getConfigValue( array( 'paypalexpress.AddrOverride' ), 0 ); |
||
| 690 | $values['PAYMENTREQUEST_0_SHIPTONAME'] = $address->getFirstName() . ' ' . $address->getLastName(); |
||
| 691 | $values['PAYMENTREQUEST_0_SHIPTOSTREET'] = $address->getAddress1() . ' ' . $address->getAddress2() . ' ' . $address->getAddress3(); |
||
| 692 | $values['PAYMENTREQUEST_0_SHIPTOCITY'] = $address->getCity(); |
||
| 693 | $values['PAYMENTREQUEST_0_SHIPTOSTATE'] = $address->getState(); |
||
| 694 | $values['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $address->getCountryId(); |
||
| 695 | $values['PAYMENTREQUEST_0_SHIPTOZIP'] = $address->getPostal(); |
||
| 696 | } |
||
| 697 | } |
||
| 698 | |||
| 699 | $itemDeliveryCosts = 0; |
||
| 700 | if( $this->getConfigValue( 'paypalexpress.product', true ) ) |
||
| 701 | { |
||
| 702 | foreach( $orderBase->getProducts() as $product ) |
||
| 703 | { |
||
| 704 | $price = $product->getPrice(); |
||
| 705 | $lastPos = $product->getPosition(); |
||
| 706 | |||
| 707 | $deliveryPrice = clone $price; |
||
| 708 | $deliveryPrices = $this->addPrice( $deliveryPrices, $deliveryPrice->setValue( '0.00' ), $product->getQuantity() ); |
||
| 709 | |||
| 710 | $values['L_PAYMENTREQUEST_0_NUMBER' . $lastPos] = $product->getId(); |
||
| 711 | $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $product->getName(); |
||
| 712 | $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = $product->getQuantity(); |
||
| 713 | $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $this->getAmount( $price, false ); |
||
| 714 | } |
||
| 715 | |||
| 716 | foreach( $deliveryPrices as $priceItem ) { |
||
| 717 | $itemDeliveryCosts += $this->getAmount( $priceItem, true, true, 2 ); |
||
| 718 | } |
||
| 719 | } |
||
| 720 | |||
| 721 | |||
| 722 | if( $this->getConfigValue( 'paypalexpress.service', true ) ) |
||
| 723 | { |
||
| 724 | foreach( $orderBase->getService( 'payment' ) as $service ) |
||
| 725 | { |
||
| 726 | $price = $service->getPrice(); |
||
| 727 | |||
| 728 | if( ( $paymentCosts = $this->getAmount( $price ) ) > '0.00' ) |
||
| 729 | { |
||
| 730 | $lastPos++; |
||
| 731 | $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $this->context()->getI18n()->dt( 'mshop', 'Payment costs' ); |
||
| 732 | $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = '1'; |
||
| 733 | $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $paymentCosts; |
||
| 734 | } |
||
| 735 | } |
||
| 736 | |||
| 737 | try |
||
| 738 | { |
||
| 739 | $lastPos = 0; |
||
| 740 | foreach( $orderBase->getService( 'delivery' ) as $service ) |
||
| 741 | { |
||
| 742 | $deliveryPrices = $this->addPrice( $deliveryPrices, $service->getPrice() ); |
||
| 743 | |||
| 744 | $values['L_SHIPPINGOPTIONAMOUNT' . $lastPos] = number_format( $service->getPrice()->getCosts() + $itemDeliveryCosts, 2, '.', '' ); |
||
| 745 | $values['L_SHIPPINGOPTIONLABEL' . $lastPos] = $service->getCode(); |
||
| 746 | $values['L_SHIPPINGOPTIONNAME' . $lastPos] = $service->getName(); |
||
| 747 | $values['L_SHIPPINGOPTIONISDEFAULT' . $lastPos] = 'true'; |
||
| 748 | |||
| 749 | $lastPos++; |
||
| 750 | } |
||
| 751 | } |
||
| 752 | catch( \Exception $e ) { ; } // If no delivery service is available |
||
| 753 | } |
||
| 754 | |||
| 755 | |||
| 756 | $deliveryCosts = 0; |
||
| 757 | $price = $orderBase->getPrice(); |
||
| 758 | $amount = $this->getAmount( $price ); |
||
| 759 | |||
| 760 | foreach( $deliveryPrices as $priceItem ) { |
||
| 761 | $deliveryCosts += $this->getAmount( $priceItem, true, true, $price->getPrecision() + 2 ); |
||
| 762 | } |
||
| 763 | |||
| 764 | $values['MAXAMT'] = $amount + 1 / pow( 10, $price->getPrecision() ); // possible rounding error |
||
| 765 | $values['PAYMENTREQUEST_0_AMT'] = $amount; |
||
| 766 | $values['PAYMENTREQUEST_0_ITEMAMT'] = number_format( $amount - $deliveryCosts, $price->getPrecision(), '.', '' ); |
||
| 767 | $values['PAYMENTREQUEST_0_SHIPPINGAMT'] = number_format( $deliveryCosts, $price->getPrecision(), '.', '' ); |
||
| 768 | $values['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00'; |
||
| 769 | $values['PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED'] = 'false'; |
||
| 770 | $values['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00'; |
||
| 771 | $values['PAYMENTREQUEST_0_CURRENCYCODE'] = $orderBase->getPrice()->getCurrencyId(); |
||
| 772 | $values['PAYMENTREQUEST_0_PAYMENTACTION'] = $this->getConfigValue( array( 'paypalexpress.PaymentAction' ), 'sale' ); |
||
| 773 | |||
| 774 | if( $localecode = $this->getConfigValue( 'paypalexpress.LocaleCode', null ) ) { |
||
| 775 | $values['LOCALECODE'] = $localecode; |
||
| 776 | } |
||
| 777 | |||
| 778 | return $values; |
||
| 779 | } |
||
| 780 | |||
| 781 | |||
| 782 | /** |
||
| 783 | * Returns the data required for authorization against the PayPal server. |
||
| 784 | * |
||
| 785 | * @return array Associative list of key/value pairs containing the autorization parameters |
||
| 786 | */ |
||
| 787 | protected function getAuthParameter() : array |
||
| 788 | { |
||
| 789 | return array( |
||
| 790 | 'VERSION' => '204.0', |
||
| 791 | 'SIGNATURE' => $this->getConfigValue( array( 'paypalexpress.ApiSignature' ) ), |
||
| 792 | 'USER' => $this->getConfigValue( array( 'paypalexpress.ApiUsername' ) ), |
||
| 793 | 'PWD' => $this->getConfigValue( array( 'paypalexpress.ApiPassword' ) ), |
||
| 794 | ); |
||
| 795 | } |
||
| 796 | |||
| 797 | |||
| 798 | /** |
||
| 799 | * Returns order service item for specified base ID. |
||
| 800 | * |
||
| 801 | * @param string $baseid Base ID of the order |
||
| 802 | * @return \Aimeos\MShop\Order\Item\Base\Service\Iface Order service item |
||
| 803 | */ |
||
| 804 | protected function getOrderServiceItem( string $baseid ) : \Aimeos\MShop\Order\Item\Base\Service\Iface |
||
| 805 | { |
||
| 806 | $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT; |
||
| 807 | $basket = $this->getOrderBase( $baseid, \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ); |
||
| 808 | |||
| 809 | return $this->getBasketService( $basket, $type, $this->getServiceItem()->getCode() ); |
||
| 810 | } |
||
| 811 | |||
| 812 | |||
| 813 | /** |
||
| 814 | * Adds the costs to the price item with the corresponding tax rate |
||
| 815 | * |
||
| 816 | * @param \Aimeos\MShop\Price\Item\Iface[] $prices Associative list of tax rates as key and price items as value |
||
| 817 | * @param \Aimeos\MShop\Price\Item\Iface $price Price item that should be added |
||
| 818 | * @param int $quantity Product quantity |
||
| 819 | * @return \Aimeos\MShop\Price\Item\Iface[] Updated list of price items |
||
| 820 | */ |
||
| 821 | protected function addPrice( array $prices, \Aimeos\MShop\Price\Item\Iface $price, int $quantity = 1 ) : array |
||
| 822 | { |
||
| 823 | $taxrate = $price->getTaxRate(); |
||
| 824 | |||
| 825 | if( !isset( $prices[$taxrate] ) ) |
||
| 826 | { |
||
| 827 | $prices[$taxrate] = \Aimeos\MShop::create( $this->context(), 'price' )->create(); |
||
| 828 | $prices[$taxrate]->setTaxRate( $taxrate ); |
||
| 829 | } |
||
| 830 | |||
| 831 | $prices[$taxrate]->addItem( $price, $quantity ); |
||
| 832 | |||
| 833 | return $prices; |
||
| 834 | } |
||
| 835 | |||
| 836 | |||
| 837 | /** |
||
| 838 | * Sends request parameters to the providers interface. |
||
| 839 | * |
||
| 840 | * @param string $target Receivers address e.g. url. |
||
| 841 | * @param string $method Initial method (e.g. post or get) |
||
| 842 | * @param string $payload Update information whose format depends on the payment provider |
||
| 843 | * @return string response body of a http request |
||
| 844 | */ |
||
| 845 | public function send( string $target, string $method, string $payload ) : string |
||
| 883 | } |
||
| 884 | } |
||
| 885 |