Forums / General Questions / sending attribute value to payment processor

sending attribute value to payment processor

Locked

Views: 2,948

Results 1 to 20 of 21
This thread is locked. New replies are disabled.
29 Jun 2009, 4:52 AM
#1
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

sending attribute value to payment processor

Hi guys,

there is probably a basic php solution for this but it's a little over my head atm (though I am trying to learn).

In my payment module there is a section where I can specify a reference number for the order. This is the default setting:

payment_reference => zen_create_random_value(16, 'digits');

We don't need a 16 digit random number. Something more specific will be more useful to us. I have tried the following and they both work:

  function before_process() {
  global $_POST, $response, $db, $order, $orders;

      $order->info['cc_number'] = $_POST['cc_number'];
      $order->info['cc_owner'] = $_POST['cc_owner'];

payment_reference => = $_POST['cc_owner'];
//(to put the credit card owner'
s name in the reference section)

payment_reference => = $_POST['cc_number'],
//(to put the credit card number in the reference section just for a test, I wouldn't save this info)

On the product page we have a required attribute that is automatically generated (an 8 digit internal reference number).

The text field with this number as the following id's:
The products_attributes_id is 304.
The options_id is 28.

The question is: How do we get the text value inputted for this attribute to show up here?

I would like to do something like this:

$order->info['attribute_28'] = $_POST['attribute_28'];

payment_reference => = $_POST['attribute_28'];

obviously it doesn't work as it is now. what do i need to do to allow it?

even pointing me towards another forum post in the right direction would be a great help.

thanks in advance,

Regards,
Shaztesting

P.S The module is directone: http://www.zen-cart.com/archived_contributions/payment/directone.zip

6 Aug 2009, 9:51 PM
#2
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

I would like to make an attribute text field into a php variable.

Ideally the value the customer places in that field should be able to be retrived later on in the checkout process.

How do i best do this?

The attribute on my product page has an input name and the form is submited via POST then shouldn't I be able to call it back later on with $_POST["input name"]?

For example this simple form works in a test environment.

<form action="index.php" method="post">
<input type="text" name="attribute" />
<input type="Submit" name="Submit">
</form>

index.php

<?php $attrib = $_POST["attribute"]; ?>
Your Attribute value is <?php echo $attrib; ?>

However when I input this into the store it no longer works.

I tested this by modifying the product page to include an additional field

<input type="text" name="attribute" />

and modifying the next stage in the process, the shopping cart 'tpl_shopping_cart_default.php' with

<?php $attrib = $_POST["attribute"]; ?>
Your Attribute value is <?php echo $attrib; ?>

What happens is the shopping cart page only shows 'Your Attribute value is' and not the variable.

  1. Why does this code work in a test environment and not in the store?

If we can get this to work then there will be one final hurdle. The attribute input name that Zen Cart uses is 'id[text_12]'
Whenever we need to retrieve the variable we couldn't use

<?php $attrib = $_POST["id[text_12]"]; ?>
Your Attribute value is <?php echo $attrib; ?>

since the square brackets aren't escaped. How do we do that? Can we use "" somehow to escape the next characters?
Anyway, I'm probably getting ahead of myself. At this stage I have to get text field -> php variable working in zencart.

As always, I appreciate any help anyone can prove on the matter.

If i'm going about this the wrong way then feel free to correct me,

Thanks in advance,
Shaztesting

10 Aug 2009, 1:20 AM
#3
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

shaztesting:

  1. Why does this code work in a test environment and not in the store?

I figured this part out. Although you are directed to the shopping cart checkout - the target of the POST is not. That's why I can't get that value on the third page (tpl_shopping_cart_default.php).

Is this possible using a $_SESSION variable? How would I do this without interfering with the store's existing sessions?

What about global $_POST; ?

I've looked into ways that others have retrieved attribute information and modified some of the Linkpoint code:

<?php
function before_process() {
    global $order, $db;
    $myorder = array();
	
	if (isset($order->products[$i]['attributes'])) {
			for ($j=0, $m=sizeof($order->products[$i]['attributes']); $j<$m; $j++) {
			  $myorder["items"][$i]['options' . $j]['name'] = $order->products[$i]['attributes'][$j]['option'];
			  $myorder["items"][$i]['options' . $j]['value'] = $order->products[$i]['attributes'][$j]['value'];
			}
		  }
	$attrib = $order->products[$i]['attributes'][$j]['value'];
	
}
?>
Your Attribute value is <?php echo $attrib;
?>

But obviously it doesn't work in this state. Could someone please let me know how i can use this to retrieve specific attribute values, perhaps using $i and $j?

Regards,
Shaztesting

10 Aug 2009, 1:45 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

shaztesting:

I would like to make an attribute text field into a php variable.

Ideally the value the customer places in that field should be able to be retrived later on in the checkout process.

Perhaps you can explain a lot more detail about what end result you're looking for, without even thinking about code?
including but not limited to:
Why are you doing this?
What data do you want where and for what purpose?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2009, 2:41 AM
#5
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

DrByte:

Why are you doing this?

I need to have a certain attribute value sent to my payment processor. This is an internal tracking number which we generate from our ERP system and we need this to be sent with successful payments so we can track orders by simply logging into the payment gateway's administration backend.

More details can be found here: http://www.zen-cart.com/forum/showthread.php?t=130824

DrByte:

What data do you want where and for what purpose?

It is an integer, up to 8 digits that is automatically prefilled for the customer. In the directone payment module we need to retrieve this number and include it in the array that is sent to the payment gateway.

If you need any more information please let me know,

Regards,
Shaztesting

10 Aug 2009, 2:47 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

So, the customer is keying this number in?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2009, 2:49 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

shaztesting:

More details can be found here: http://www.zen-cart.com/forum/showthread.php?t=130824
I've merged the 2 threads since they're the same topic.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2009, 2:57 AM
#8
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

DrByte:

So, the customer is keying this number in?

Not exactly, we are prefilling that in automatically but they pressing the 'add to cart' button.

So in their shopping cart they see their product as well as a few attributes, one of which we have generated for them.

10 Aug 2009, 3:04 AM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

shaztesting:

I've looked into ways that others have retrieved attribute information and modified some of the Linkpoint code:

<?php function before_process() { global $order, $db; $myorder = array(); if (isset($order->products[$i]['attributes'])) { for ($j=0, $m=sizeof($order->products[$i]['attributes']); $j<$m; $j++) { $myorder["items"][$i]['options' . $j]['name'] = $order->products[$i]['attributes'][$j]['option']; $myorder["items"][$i]['options' . $j]['value'] = $order->products[$i]['attributes'][$j]['value']; } } $attrib = $order->products[$i]['attributes'][$j]['value']; } ?>

Your Attribute value is <?php echo $attrib; ?>


I would suggest that that's the right snippet of code to work from, perhaps like this:
<?php function before_process() { global $order; $erpNumber = ''; if (isset($order->products[$i]['attributes'])) { for ($j = 0, $m = sizeof($order->products[$i]['attributes']); $j < $m; $j ++) { if ($order->products[$i]['attributes'][$j]['option_id'] == 28) { if ($order->products[$i]['attributes'][$j]['value_id'] == 77) { $erpNumber = $order->products[$i]['attributes'][$j]['value']; break; } } } } } ?>

Your Attribute value is <?php echo $erpNumber; ?>


That check is based on options_id 28 and values_id 77.  It's going to be much more complicated to go based on products_attributes_id.
Adjust the 77 according to your data.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2009, 3:06 AM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

shaztesting:

Not exactly, we are prefilling that in automatically but they pressing the 'add to cart' button.

So in their shopping cart they see their product as well as a few attributes, one of which we have generated for them.

Is your ERP system feeding other data as well? Or just this one number?
Can you tell me how/why that number is generated? ... because it might be a lot easier just to have the payment module query the ERP system for that same value, and skip the whole use of attributes ... unless you're using the attribute for a specific reason.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2009, 4:58 AM
#11
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

DrByte:

That check is based on options_id 28 and values_id 77. It's going to be much more complicated to go based on products_attributes_id.
Adjust the 77 according to your data.

Thanks DrByte, but I don't think I implemented it properly.

The markup for the form has the text field as follows:
<input type="text" name="id[txt_5]" size="32" maxlength="32" value="" id="attrib-5-0" />

Does '5-0' mean an options id of 5 and a value of 0? I looked at the products_attributes table and the 'options_id' field has '5' and 'options_values_id' has '0' (there was no value_id field).

I inputted those numbers into the snipped which i placed in the tpl_checkout_shipping_default.php page to test the echo and it didn't work.

So where did I go wrong?

10 Aug 2009, 5:22 AM
#12
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

DrByte:

Is your ERP system feeding other data as well? Or just this one number?

There are a number of text fields (attributes), all prefilled.

DrByte:

Can you tell me how/why that number is generated? ... because it might be a lot easier just to have the payment module query the ERP system for that same value, and skip the whole use of attributes ... unless you're using the attribute for a specific reason.

The ERP system is written in .NET and is integrated with an ASP.NET webpage on IIS webserver. Passing this lead id over URL seemed like the most logical choice, rather than trying to integrate php/mysql into the whole thing.

Just for a test I copied the <!-- Loop through all products /--> code from the tpl_shopping_cart_default.php page just to see if I could display a list of all the atributes, just like on the shopping cart page. That didn't work either. Are these related?

10 Aug 2009, 7:15 AM
#13
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

shaztesting:

Just for a test I copied the <!-- Loop through all products /--> code from the tpl_shopping_cart_default.php page just to see if I could display a list of all the atributes, just like on the shopping cart page. That didn't work either. Are these related?

Ok, i just realised that these pages don't have the same header.php files. After i copied the contents of the shopping cart's header.php I can display the list of attributes on any page.

Still no success in echoing just one of them so I'm guessing I just went off in a tangent...

10 Aug 2009, 11:31 AM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

shaztesting:

Thanks DrByte, but I don't think I implemented it properly.

I inputted those numbers into the snipped which i placed in the tpl_checkout_shipping_default.php page to test the echo and it didn't work.

So where did I go wrong?

The snippet of code I gave you should go in the payment module, not in a template file. It should be merged into any existing code in the before_process() function already in the file.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2009, 11:47 PM
#15
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

I did try that with no success so I then tried echoing it back on other pages to see if the right attribute we getting called in at all.

here is how i inserted it into the payment module:

function before_process() {
	  global $_POST, $response, $db, $order, $orders;


  $erpNumber = '';
  if (isset($order->products[$i]['attributes']))
  {
    for ($j = 0, $m = sizeof($order->products[$i]['attributes']); $j < $m; $j ++)
    {
      if ($order->products[$i]['attributes'][$j]['option_id'] == 28) {
        if ($order->products[$i]['attributes'][$j]['value_id'] == 0) {
          $erpNumber = $order->products[$i]['attributes'][$j]['value'];
          break;
        }
      }
    }
  }


	  if (MODULE_PAYMENT_DIRECTONE_STORE_CC_NUMBER == 'True') {
      $order->info['cc_number'] = $_POST['cc_number'];
      }
      $order->info['cc_expires'] = $_POST['cc_expires'];
      $order->info['cc_type'] = $_POST['cc_type'];
      $order->info['cc_owner'] = $_POST['cc_owner'];
      $order->info['cc_cvv'] = $_POST['cc_cvv'];
      

	  // DATA PREPARATION SECTION
      unset($submit_data);  // Cleans out any previous data stored in the variable

      // create a random order id
      $uid = $erpNumber; // Create a UID for the order to be sent as payment_reference 

	  // Populate an array that contains all of the data to be sent to DirectOne
	  $submit_data = array(
	  vendor_name => MODULE_PAYMENT_DIRECTONE_VENDOR_NAME, // Vendor Login ID
	  vendor_password => MODULE_PAYMENT_DIRECTONE_VENDOR_PASSWORD, // Vendor Password
	  card_number => $_POST['cc_number'],
	  card_type => 'AUTO',
	  card_expiry => $_POST['cc_expires'],
	  card_holder => $_POST['cc_owner'],
	  card_cvv => $_POST['cc_cvv'],
	  payment_amount => number_format($order->info['total'], 2, '.', '') * 100,
	  payment_reference => $uid);  // Unique Transaction ID

Anything wrong?

Was I using the right tables to collect the option_id and values_id numbers?

11 Aug 2009, 12:08 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

shaztesting:

I did try that with no success so I then tried echoing it back on other pages to see if the right attribute we getting called in at all.The code I gave you only works if the $order variable is set, and that only happens while in the midst of processing an order. That's why that code is useless in a template file for example, and is why I've largely ignored anything you've said about putting code in template files.
shaztesting:

if ($order->products[$i]['attributes'][$j]['option_id'] == 28) {
if ($order->products[$i]['attributes'][$j]['value_id'] == 0) {So, what was your reasoning behind choosing '0' ?
shaztesting:

Was I using the right tables to collect the option_id and values_id numbers?
I don't understand the question.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

11 Aug 2009, 12:12 AM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

Open phpMyAdmin and run the following query:```
select products_attributes_id, products_id, options_id, options_values_id from products_attributes where products_attributes_id = 308;

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

11 Aug 2009, 12:34 AM
#18
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

DrByte:

Open phpMyAdmin and run the following query:```
select products_attributes_id, products_id, options_id, options_values_id from products_attributes where products_attributes_id = 308;


That doesn't work becuase i don't have a 308 yet. But the attributes id of 304 is the one that I am after. 

When I run the query for 304 i get the following output:

product_attributes_id=304
products_id=13
options_id=28
option_values_id=0
11 Aug 2009, 12:41 AM
#19
shaztesting avatar

shaztesting

New Zenner

Join Date:
Jun 2009
Posts:
71
Plugin Contributions:
0

Re: sending attribute value to payment processor

DrByte:

So, what was your reasoning behind choosing '0' ?
I got that value from the products_attributes table where the 'options_id' field has '28' and 'options_values_id' has '0'

DrByte:

I don't understand the question.

I was just making sure that the products_attributes table was the right one to be querying

11 Aug 2009, 2:00 AM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: sending attribute value to payment processor

It seems I left out an important section :eek:

Try this:

function before_process() {
	  global $response, $db, $order, $orders;


  $erpNumber = '';

  reset($order->products);
  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
    if (isset($order->products[$i]['attributes']))
    {
      for ($j = 0, $m = sizeof($order->products[$i]['attributes']); $j < $m; $j ++)
      {
        if ($order->products[$i]['attributes'][$j]['option_id'] == 28) {
          if ($order->products[$i]['attributes'][$j]['value_id'] == 0) {
            $erpNumber = $order->products[$i]['attributes'][$j]['value'];
            break;
          }
        }
      }
    }
  }

Don't forget the added brace } near the end.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.