Skip to content

Commit

Permalink
Make data configurable which is sent to PayPal
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jul 12, 2017
1 parent d0dda4a commit 003cf09
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions lib/mshoplib/src/MShop/Service/Provider/Payment/PayPalExpress.php
Expand Up @@ -637,65 +637,74 @@ protected function getOrderDetails( \Aimeos\MShop\Order\Item\Base\Iface $orderBa
$deliveryPrices = [];
$values = $this->getAuthParameter();

try

if( $this->getConfigValue( 'paypalexpress.address', true ) )
{
$orderAddressDelivery = $orderBase->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT );

/* setting up the address details */
$values['NOSHIPPING'] = $this->getConfigValue( array( 'paypalexpress.NoShipping' ), 1 );
$values['ADDROVERRIDE'] = $this->getConfigValue( array( 'paypalexpress.AddrOverride' ), 0 );
$values['PAYMENTREQUEST_0_SHIPTONAME'] = $orderAddressDelivery->getFirstName() . ' ' . $orderAddressDelivery->getLastName();
$values['PAYMENTREQUEST_0_SHIPTOSTREET'] = $orderAddressDelivery->getAddress1() . ' ' . $orderAddressDelivery->getAddress2() . ' ' . $orderAddressDelivery->getAddress3();
$values['PAYMENTREQUEST_0_SHIPTOCITY'] = $orderAddressDelivery->getCity();
$values['PAYMENTREQUEST_0_SHIPTOSTATE'] = $orderAddressDelivery->getState();
$values['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $orderAddressDelivery->getCountryId();
$values['PAYMENTREQUEST_0_SHIPTOZIP'] = $orderAddressDelivery->getPostal();
try
{
$orderAddressDelivery = $orderBase->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT );

/* setting up the address details */
$values['NOSHIPPING'] = $this->getConfigValue( array( 'paypalexpress.NoShipping' ), 1 );
$values['ADDROVERRIDE'] = $this->getConfigValue( array( 'paypalexpress.AddrOverride' ), 0 );
$values['PAYMENTREQUEST_0_SHIPTONAME'] = $orderAddressDelivery->getFirstName() . ' ' . $orderAddressDelivery->getLastName();
$values['PAYMENTREQUEST_0_SHIPTOSTREET'] = $orderAddressDelivery->getAddress1() . ' ' . $orderAddressDelivery->getAddress2() . ' ' . $orderAddressDelivery->getAddress3();
$values['PAYMENTREQUEST_0_SHIPTOCITY'] = $orderAddressDelivery->getCity();
$values['PAYMENTREQUEST_0_SHIPTOSTATE'] = $orderAddressDelivery->getState();
$values['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $orderAddressDelivery->getCountryId();
$values['PAYMENTREQUEST_0_SHIPTOZIP'] = $orderAddressDelivery->getPostal();
}
catch( \Exception $e ) { ; } // If no address is available
}
catch( \Exception $e ) { ; } // If no address is available


$lastPos = 0;
foreach( $orderBase->getProducts() as $product )
if( $this->getConfigValue( 'paypalexpress.product', true ) )
{
$price = $product->getPrice();
$lastPos = $product->getPosition() - 1;
$lastPos = 0;
foreach( $orderBase->getProducts() as $product )
{
$price = $product->getPrice();
$lastPos = $product->getPosition() - 1;

$deliveryPrice = clone $price;
$deliveryPrices = $this->addPrice( $deliveryPrices, $deliveryPrice->setValue( '0.00' ), $product->getQuantity() );
$deliveryPrice = clone $price;
$deliveryPrices = $this->addPrice( $deliveryPrices, $deliveryPrice->setValue( '0.00' ), $product->getQuantity() );

$values['L_PAYMENTREQUEST_0_NUMBER' . $lastPos] = $product->getId();
$values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $product->getName();
$values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = $product->getQuantity();
$values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $this->getAmount( $price, false );
$values['L_PAYMENTREQUEST_0_NUMBER' . $lastPos] = $product->getId();
$values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $product->getName();
$values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = $product->getQuantity();
$values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $this->getAmount( $price, false );
}
}


$price = $orderBase->getService( 'payment' )->getPrice();
if( ( $paymentCosts = $this->getAmount( $price ) ) > '0.00' )
if( $this->getConfigValue( 'paypalexpress.service', true ) )
{
$lastPos++;
$values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $this->getContext()->getI18n()->dt( 'mshop', 'Payment costs' );
$values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = '1';
$values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $paymentCosts;
}
$price = $orderBase->getService( 'payment' )->getPrice();
if( ( $paymentCosts = $this->getAmount( $price ) ) > '0.00' )
{
$lastPos++;
$values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $this->getContext()->getI18n()->dt( 'mshop', 'Payment costs' );
$values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = '1';
$values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $paymentCosts;
}

try
{
$orderServiceDeliveryItem = $orderBase->getService( 'delivery' );
$price = $orderServiceDeliveryItem->getPrice();
$deliveryPrices = $this->addPrice( $deliveryPrices, $price );

try
{
$orderServiceDeliveryItem = $orderBase->getService( 'delivery' );
$price = $orderServiceDeliveryItem->getPrice();
$deliveryPrices = $this->addPrice( $deliveryPrices, $price );
foreach( $deliveryPrices as $priceItem ) {
$deliveryCosts += $this->getAmount( $priceItem );
}

foreach( $deliveryPrices as $priceItem ) {
$deliveryCosts += $this->getAmount( $priceItem );
$values['L_SHIPPINGOPTIONAMOUNT0'] = number_format( $deliveryCosts, 2, '.', '' );
$values['L_SHIPPINGOPTIONLABEL0'] = $orderServiceDeliveryItem->getCode();
$values['L_SHIPPINGOPTIONNAME0'] = $orderServiceDeliveryItem->getName();
$values['L_SHIPPINGOPTIONISDEFAULT0'] = 'true';
}

$values['L_SHIPPINGOPTIONAMOUNT0'] = number_format( $deliveryCosts, 2, '.', '' );
$values['L_SHIPPINGOPTIONLABEL0'] = $orderServiceDeliveryItem->getCode();
$values['L_SHIPPINGOPTIONNAME0'] = $orderServiceDeliveryItem->getName();
$values['L_SHIPPINGOPTIONISDEFAULT0'] = 'true';
catch( \Exception $e ) { ; } // If no delivery service is available
}
catch( \Exception $e ) { ; } // If no delivery service is available


$price = $orderBase->getPrice();
Expand Down

0 comments on commit 003cf09

Please sign in to comment.