Jump to content

Pay With Amazon


unplugged_web

Recommended Posts

I'm working on adding Pay By Amazon to a site but have run into a problem. I think is quite easy to sort, but I'm not sure how. Each item has to have the prefix "PurchaseItems.PurchaseItem." and then an integer. How do I change that for each product so for the first product everything would be listed with the prefix PurchaseItems.PurchaseItem.1 the second would be PurchaseItems.PurchaseItem.2 etc?

The full code is:
<form action="https://payments.amazon.co.uk/cba/api/purchasecontract/" method="get"><input type="hidden" name="Action" value="SetPurchaseItems" /><input type="hidden" name="AWSAccessKeyId" value="SAMPLE" /><input type="hidden" name="PurchaseContractId" value="<?php echo $_GET['purchaseContractId']; ?>" /><?php foreach( $order_line as $key=>$value ) { ?><input type="hidden" name="PurchaseItems.PurchaseItem.1.FulfillmentNetwork" value="MERCHANT" /><input type="hidden" name="PurchaseItems.PurchaseItem.1.MerchantId" value="SAMPLE" /><input type="hidden" name="PurchaseItems.PurchaseItem.1.MerchantItemId" value="<?php echo $products_all[$value['product_id']]['id'] ?>" /><input type="hidden" name="PurchaseItems.PurchaseItem.1.Quantity" value="<?php echo $value['product_qty'] ?>" /><input type="hidden" name="PurchaseItems.PurchaseItem.1.Title" value="<?php echo htmldisplay( $products_all[$value['product_id']]['name'] ) ?>" /><?php if( count( $value['detail'] ) ) { ?><?php if( is_array( $product_detail ) ) { foreach( $product_detail as $key2=>$value2 ) { if( isset( $value['detail'][$key2] ) ) { ?><input type="hidden" name="PurchaseItems.PurchaseItem.1.Description" value="Option: <?php echo htmldisplay( $value2['name'] ) ?>" /><?php } } ?><input type="hidden" name="PurchaseItems.PurchaseItem.1.UnitPrice.Amount" value="<?php if( $value['price_total']<0.01 ) { echo "00.00"; } else { echo (number_format( $value['price_total']/$value['product_qty']*$companydetails['exchange'],2 )); } ?>" /><input type="hidden" name="PurchaseItems.PurchaseItem.1.UnitPrice.CurrencyCode" value="<?php echo htmldisplay( $companydetails['currency_iso']); ?>" /><input type="hidden" name="PurchaseItems.PurchaseItem.1.URL" value="product/<?php echo $products_all[$value['product_id']]['linkword'] ?>" /><?php } } } ?><input type="hidden" name="SignatureSignature" value="SAMPLE" /><input type="hidden" name="SignatureMethod" value="METHOD" /><input type="hidden" name="SignatureVersion" value="SIGNATUREVERSION" /><input type="hidden" name="Timestamp" value="TIMESTAMP" /><input type="hidden" name="Version" value="VERSION" /><input type="submit" class="input_button input_red" value="Complete order" /></form>
Link to comment
Share on other sites

You could have a counter variable. Here's the general structure:

<?php$counter = 1; // The first product is 1foreach($order_line as $key=>$value) {?><!-- The inputs look like this --><input type="hidden" name="PurchaseItems.PurchaseItem.<?php echo $counter; ?>.FulfillmentNetwork" value="MERCHANT" /><?php    $counter++; // Add 1 to the counter}?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...