News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Add custom field to paypal (SOLVED... for now)

Started by john-doe, June 06, 2014, 18:31:02 PM

Previous topic - Next topic

john-doe

Greetings.

I have a custom field for sizes on my store.

The invoice has that custom size.

However, I need to send that detail to the paypal invoice but i don't know how to add that detail to the paypal invoice

I wish to add the size to the paypal balance / invoice (Attacment to the section included)
Thanks in advance

[attachment cleanup by admin]

alatak

Hello
In the paypal plugin, you have several options. If you use the PayPal product= Standard and Payment type="Shopping cart" the product details will be sent to Paypal

john-doe

Thanks for answering.

As a matter of fact i have the Shopping cart option you mention.
But my boss, who handles the paypal backend says that the product appears but not the product size.
I don't know how to send the custom field data to the paypal cart so i can see that information as well in the paypal's backend.

I'm quite in a loophole since my experience is limted to design and configure, but not reprogram the plugin.


alatak

Hello
QuoteBut my boss, who handles the paypal backend says that the product appears but not the product size.
Yes it is true. Only the product name is sent to paypal, and not the custom fields. I will check that.

john-doe

Quote from: alatak on June 10, 2014, 19:36:43 PM
Hello
QuoteBut my boss, who handles the paypal backend says that the product appears but not the product size.
Yes it is true. Only the product name is sent to paypal, and not the custom fields. I will check that.
Thanks i appreciate that since i don't know how to handle that and my boss is pressing me for that

john-doe

Alatak, Let me know what you find out. It could be a huge help to display the product details.

john-doe

#6
Hello alatak

Well i'm trying to help (despite the pressure of my superiors where i work); since my programming knowledge is quite limited i was checking the file on

/plugins/vmpayment/paypal/helpers

And i am not quite sure if this block of code has to do with the Order processing i need to set.
Paypalstd.php lines 279 to 295

function addPrices(&$post_variables) {

$paymentCurrency = CurrencyDisplay::getInstance($this->_method->payment_currency);

$i = 1;
// Product prices
if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
$i++;
}
}

With my limited knowledge i can deduce that here is where the product and the SKU are shown and sent to Paypal (buyer recipt and business receipt manifest) i want to try a standar adding of the custom field here to see if it works (on a localhost in my computer)

EDIT: to avoid bumping the message i see that definitively is the piece of code. However i'm looking the way to see where is in the variables captured (if they are sent) the custom field data.

i made a clone of this lines

if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}


Building the code like this with no success


function addPrices(&$post_variables) {

$paymentCurrency = CurrencyDisplay::getInstance($this->_method->payment_currency);

$i = 1;
// Product prices
if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
if ($product->product_custom_fields) {
$post_variables["custom_fields_" . $i] = $product->product_custom_fields;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
$i++;
}
}

john-doe

#7
I hate bumping messages but do you have any news about this issue?

EDITED: I'm getting close

i edited the piece of code and i had to decode the array. Good news is i found where is in the $product array the variables and extract it. The problem now resides in how to send them into the paypal details.


if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
$post_variables["custom_" . $i] = $product->customfields;

$i++;
echo json_encode($post_variables);
}

}

john-doe

Bumping with some advances:

Looking in the place of the prices at the position i initially marked (plugins/vmpayment/paypal/paypal/helpers/paypalstd line 279)

i managed to add to those variables the custom field and the tax amount (another of my boss' requests but since the same principle applies i made it)


function addPrices(&$post_variables) {

$paymentCurrency = CurrencyDisplay::getInstance($this->_method->payment_currency);

$i = 1;
// Product prices
if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
//Additional strings to add Custom and tax amount
$post_variables["custom_" . $i] = $this->getItemName($product->customfields);
$show_tax = $this->cart->pricesUnformatted[$key];
$post_variables["prodtax_" . $i] = $this->getTaxAmount($this->cart->pricesUnformatted[$key]);
$i++;
//End of additional lines//echo json_encode($show_tax);
}

}


I made a clone function in the paypal.php file of the same folder (at line 106) showing original function and clone

function getProductAmount ($productPricesUnformatted) {
if ($productPricesUnformatted['salesPriceWithDiscount']) {
return vmPSPlugin::getAmountValueInCurrency($productPricesUnformatted['salesPriceWithDiscount'], $this->_method->payment_currency);
} else {
return vmPSPlugin::getAmountValueInCurrency($productPricesUnformatted['salesPrice'], $this->_method->payment_currency);
}
}
//Additional for deploy tax amount
function getTaxAmount ($productPricesUnformatted) {
if ($productPricesUnformatted['salesPriceWithDiscount']) {
return vmPSPlugin::getAmountValueInCurrency($productPricesUnformatted['salesPriceWithDiscount'], $this->_method->payment_currency);
} else {
return vmPSPlugin::getAmountValueInCurrency($productPricesUnformatted['taxAmount'], $this->_method->payment_currency);
//echo json_encode($productPricesUnformatted);
}
}

//End of additional string


In a debug transaction i see in the array the additional values but the problem is making them appear at pay pal since noly appears the product, the price, quantity and amount of items.

Now the missing item is to know where is managed that data sending so it apppears at the paypal invoice / manifest.

If you have any ideas i'm open to them



[attachment cleanup by admin]

john-doe

OK looks like i'm getting more closer.

I made this edit setting the $post_variables as tax_.$1

function addPrices(&$post_variables) {

$paymentCurrency = CurrencyDisplay::getInstance($this->_method->payment_currency);

$i = 1;
// Product prices
if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
//Additional strings to add Custom and tax amount
$post_variables["custom_" . $i] = $this->getItemName($product->customfields);
$post_variables["tax_" . $i] = $this->getTaxAmount($this->cart->pricesUnformatted[$key]);
$i++;
//End of additional lines//echo json_encode($show_tax);
}

}


The taxes appear but they are added to the bill, so they are chareged DOUBLED!.

Seeing this i commented that line and proceeded to try to add the custom field following the Paypal's API syntax


// Product prices
if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
//Additional strings to add Custom and tax amount
$post_variables["on0_" . $i] = "";
$post_variables["os0_" . $i] = $this->getItemName($product->customfields);
//$show_tax = $this->cart->pricesUnformatted[$key];
//$post_variables["tax_" . $i] = $this->getTaxAmount($this->cart->pricesUnformatted[$key]);
$i++;
//End of additional lines
//echo json_encode($product->customfields);
}

}


But no success...
The tax fixing is the closest thing but i don't know whis is adding me it again.

john-doe

#10
SOLVED (or at least i found how)


// Product prices
if ($this->cart->products) {
foreach ($this->cart->products as $key => $product) {
$post_variables["item_name_" . $i] = $this->getItemName($product->product_name);
if ($product->product_sku) {
$post_variables["item_number_" . $i] = $product->product_sku;
}
$post_variables["amount_" . $i] = $this->getProductAmount($this->cart->pricesUnformatted[$key]);
$post_variables["quantity_" . $i] = $product->quantity;
//Additional strings to add Custom Field
$post_variables["on0_" . $i] = "Your Custom Field is:";
$post_variables["os0_" . $i] = $this->getItemName($product->customfields);
$i++;
}

}


Alatak, could you please verify this if you agree with the result
I'll keep posted if i see any news

[attachment cleanup by admin]