I'm looking to add a discount code to this Paypal button but don't know how to go about doing it.
Can anyone help or suggest how too, I just need it so a customer can enter a the code and receive 10% off the price
The code is below for the button
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>Please click on the link to pay</p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?php echo C_OUR_EMAIL; ?>" />
<input type="hidden" name="first_name" value="<?php echo strfordisp($ofirstname); ?>" />
<input type="hidden" name="last_name" value="<?php echo strfordisp($olastname); ?>" />
<input type="hidden" name="address1" value="<?php echo strfordisp($theorder["oaddress"]); ?>" />
<input type="hidden" name="address2" value="<?php echo strfordisp($theorder["oaddress2"]); ?>" />
<input type="hidden" name="address3" value="<?php echo strfordisp($theorder["oaddress3"]); ?>" />
<input type="hidden" name="city" value="<?php echo strfordisp($theorder["otown"]); ?>">
<input type="hidden" name="zip" value="<?php echo strfordisp($theorder["opostcode"]); ?>" />
<?php $orderdets = mysql_query("select * from c4d_orderitems where orderid='" . $_SESSION["db_order"] . "' and confirm");
$iloop = 1;
while ($orderrow = mysql_fetch_array($orderdets))
{
$itemdesc = $orderrow["itemtypedesc"];
$itemdesc .= " to " . $orderrow["dpostcode"];
$itemprice = $orderrow["cost"] + $orderrow["surcharge"] + $orderrow["insurancecost"];
?>
<input type='hidden' name="item_name_<?php echo $iloop; ?>" value='<?php echo strfordisp($itemdesc); ?>' />
<input type='hidden' name="item_number_<?php echo $iloop; ?>" value='<?php echo $orderrow["itemtype"]; ?>' />
<input type='hidden' name="amount_<?php echo $iloop; ?>" value='<?php
// pctrends
if ((strtoupper($ofirstname)=="PCTRENDSTEST") || (strtoupper($olastname)=="PCTRENDSTEST") || (substr($_SERVER['REMOTE_ADDR'],0,11)=="82.152.55.1"))
echo("0.01");
else echo $itemprice;
?>' />
<input type='hidden' name="quantity_<?php echo $iloop; ?>" value='1' />
<?
$iloop++;
}
?>
<input type="hidden" name="return" value="<?php echo C_SITE_ROOT; ?>stage7.php" />
<input type="hidden" name="cancel-return" value="<?php echo C_SITE_ROOT; ?>order-cancel.php" />
<input type="hidden" name="notify_url" value="<?php echo C_SITE_ROOT; ?>paypal.php" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="invoice" value="<?php echo $_SESSION["db_order"]; ?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="no-shipping" value="1" />
<input type="hidden" name="button_subtype" value="products" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" />
<input type="hidden" name="country" value="GB" />
<p class='fmenu'><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p>
</form>
You must check for the discount-code validity (with AJAX) and make the appropriate calculations to apply the discount to the amount variable (with JavaScript) before to send the payment notification.
The user writes the discount-code insiede the custom variable where you can store whatever you want for your own tracking purposes.
// Check here on keypress with JS and AJAX for discount code validity
<input type="text" name="custom" value="" />
If the discount-code is verified, apply the discount to the amount variable. Something like this:
// Javascript and jQuery
if(verified == true) {
var discounted = $("[name='amount']").val() - ($("[name='amount']").val()/100)*10);
$("[name='amount']").val(discounted);
}
else {
alert("Discount code not found");
}
Then when you send the payment and get the information from paypal (the IPN response) process it like so:
$discountCode = $_POST["custom"];
// ... Discount-code validity check ...
$discountedAmount = $originalAmount - (($originalAmount/100)*10);
// And then check if the paid amount corresponds to the due amount
if($discountedAmount == $_POST["amount"])
Related
I have a PayPal payment gateway like this,
<form action="https://secure.paypal.com/uk/cgi-bin/webscr" method="post" name="paypal" id="paypal">
<!-- Prepopulate the PayPal checkout page with customer details, -->
<input type="hidden" name="first_name" value="<?php echo Firstname?>">
<input type="hidden" name="last_name" value="<?php echo Lastname?>">
<input type="hidden" name="email" value="<?php echo Email?>">
<input type="hidden" name="address1" value="<?php echo Address?>">
<input type="hidden" name="address2" value="<?php echo Address2?>">
<input type="hidden" name="city" value="<?php echo City?>">
<input type="hidden" name="zip" value="<?php echo Postcode?>">
<input type="hidden" name="day_phone_a" value="">
<input type="hidden" name="day_phone_b" value="<?php echo Mobile?>">
<!-- We don't need to use _ext-enter anymore to prepopulate pages -->
<!-- cmd = _xclick will automatically pre populate pages -->
<!-- More information: https://www.x.com/docs/DOC-1332 -->
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="paypal#email.com" />
<input type="hidden" name="cbt" value="Return to Your Business Name" />
<input type="hidden" name="currency_code" value="GBP" />
<!-- Allow the customer to enter the desired quantity -->
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="Name of Item" />
<!-- Custom value you want to send and process back in the IPN -->
<input type="hidden" name="custom" value="<?php echo session_id().?>" />
<input type="hidden" name="shipping" value="<?php echo $shipping_price; ?>" />
<input type="hidden" name="invoice" value="<?php echo $invoice_id ?>" />
<input type="hidden" name="amount" value="<?php echo $total_order_price; ?>" />
<input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/thankyou"/>
<input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/cancelled" />
<!-- Where to send the PayPal IPN to. -->
<input type="hidden" name="notify_url" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/process" />
</form>
Can I upgrade this to PSD2?
https://www.paypal.com/uk/webapps/mpp/psd2-new
If so, how do I integrate it?
This is my first time integrating the Paypal Payment in a project and it is in CI. So the thing is everything is working perfectly except that the Notify Url was supposed to make me able to change the payment status from 'Pending' to 'Success' but it isn't in my case. I have the code below and i really have tried many things but still don't know where i am slipping off.
<form id="paypal-pre" action="<?php echo base_url('auth/process'); ?>" method="post">
<input type="hidden" name="user_id" value="<?php echo $_POST['register_user_id']; ?>">
<input type="hidden" name="first_name" value="<?php echo $_POST['customer_first_name']; ?>">
<input type="hidden" name="last_name" value="<?php echo $_POST['customer_last_name']; ?>">
<input type="hidden" name="addr1" value="<?php echo $_POST['customer_address1']; ?>">
<input type="hidden" name="addr2" value="<?php echo $_POST['customer_address2']; ?>">
<input type="hidden" name="city" value="<?php echo $_POST['customer_city']; ?>">
<input type="hidden" name="county" value="<?php echo $_POST['customer_county']; ?>">
<input type="hidden" name="postcode" value="<?php echo $_POST['customer_postcode']; ?>">
<input type="hidden" name="amount" value="<?php echo $_POST['payment_total']; ?>">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
Above is the billing info collection form.
function process(){
$arr['user'] = array(
'p_user_id' => $this->input->post('user_id'),
'p_billing_firstname' => $this->input->post('first_name'),
'p_billing_lastname' => $this->input->post('last_name'),
'p_billing_address1' => $this->input->post('addr1'),
'p_billing_address2' => $this->input->post('addr2'),
'p_billing_city' => $this->input->post('city'),
'p_billing_county' => $this->input->post('county'),
'p_billing_postcode' => $this->input->post('postcode'),
'p_status' => 'processing',
'p_amount' => $this->input->post('amount'),
);
$arr['pay'] = array(
'p_amount' => $this->input->post('payment_total'),
);
$this->load->model('demo_auth_model');
$this->demo_auth_model->process($arr);
$this->load->view('paypal',$arr);}
function notify() {
if($this->input->post('custom') != ''){
$id = $this->input->post('custom');
$amt = $_POST['amount'];
$sql = "UPDATE users_payments SET p_status='success' WHERE p_id='$id'";
$this->db->query($sql);
return;
}
}
The Process and notify controller function
<?php $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$paypal_id = '******#yahoo.com';
$amount = $_POST['amount'];
$id = mysql_insert_id();?>
<form id="paypal" action="<?= $paypal_url; ?>" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="amount" value="<?php echo $amount; ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php echo 'Business Register'; ?>">
<input type="hidden" name="custom" value="<?php echo $id; ?>" />
<input type='hidden' name='notify_url' value='<?php echo base_url('auth/notify'); ?>'>
<input type='hidden' name='cancel_return' value='<?php echo base_url('auth/cancel'); ?>'>
<input type='hidden' name='return' value='<?php echo base_url();?>'>
</form><script type="text/javascript">
document.getElementById('paypal').submit();
</script>
The main paypal form which is submitted automatically after saving the billing information.
public function process($arr) {
$this->db->set($arr['user']);
$this->db->insert('user_payments');
return;
}
Process Model from demo_auth_model
Any help would be really appreciated.
P.S. All database infos are correct
well for codeigniter i prefer this library
http://tutsnare.com/integrate-paypal-using-ci-merchant-in-codeigniter/
https://github.com/expressodev/ci-merchant
for 2 Reasons
1. Auto redirect to our website
2. Take all data in session to our website
Try it and enjoy
I'm currently using a PayPal form to checkout from a website. On shippable items, everything is working fine. The issue I am running into, is the website also offers non-shippable services (downloadable content, streaming videos online). I'm retrieving the correct responses from PayPal when a purchase is successful, only if they pay shipping costs calculated for a non-shippable service. Here is an excerpt from my code:
<form id="paypal-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display: none;">
<?php foreach($checkout as $key => $value): ?>
<input name="item_name_<?php echo $key + 1; ?>" value="<?php echo $value['name']; ?>" type="hidden">
<input name="amount_<?php echo $key + 1; ?>" value="<?php echo $value['amount']; ?>" type="hidden">
<input name="quantity_<?php echo $key + 1; ?>" value="<?php echo $value['quantity']; ?>" type="hidden">
<input name="item_number_<?php echo $key + 1; ?>" value="<?php echo $value['number']; ?>" type="hidden">
<?php endforeach; ?>
<input name="no_shipping" value="2" type="hidden">
<input name="return" value="WEB_SITE/thank-you.html" type="hidden">
<input name="notify_url" value="WEB_SITE/process.html" type="hidden">
<input name="cancel_return" value="WEB_SITE/shopping-cart.html" type="hidden">
<input name="business" value="EMAIL" type="hidden">
<input name="currency_code" value="USD" type="hidden">
<input name="cmd" value="_cart" type="hidden">
<input name="upload" value="1" type="hidden">
<input name="rm" value="2" type="hidden">
<input name="charset" value="utf-8" type="hidden">
</form>
I'm not finding support for the task I'm looking for on this forum or PayPal's. Is what I'm asking for possible?
Okay, after further research and trying new things I found a method that works. Simply using the field "shipping_(n)" and setting the value to "0" overrides the shipping calculation and marks it as $0.00. Thanks everyone for trying. Here is my corrected code:
<form id="paypal-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display: none;">
<?php foreach($checkout as $key => $value): ?>
<input name="item_name_<?php echo $key + 1; ?>" value="<?php echo $value['name']; ?>" type="hidden">
<input name="amount_<?php echo $key + 1; ?>" value="<?php echo $value['amount']; ?>" type="hidden">
<input name="quantity_<?php echo $key + 1; ?>" value="<?php echo $value['quantity']; ?>" type="hidden">
<input name="item_number_<?php echo $key + 1; ?>" value="<?php echo $value['number']; ?>" type="hidden">
<?php if(strpos($value['number'], 'PROGRAMS') !== FALSE): ?>
<input name="shipping_<?php echo $key + 1; ?>" value="0" type="hidden">
<?php endif; ?>
<?php endforeach; ?>
<input name="no_shipping" value="2" type="hidden">
<input name="return" value="WEB_SITE/thank-you.html" type="hidden">
<input name="notify_url" value="WEB_SITE/process.html" type="hidden">
<input name="cancel_return" value="WEB_SITE/shopping-cart.html" type="hidden">
<input name="business" value="EMAIL" type="hidden">
<input name="currency_code" value="USD" type="hidden">
<input name="cmd" value="_cart" type="hidden">
<input name="upload" value="1" type="hidden">
<input name="rm" value="2" type="hidden">
<input name="charset" value="utf-8" type="hidden">
</form>
I have no any idea about it. I serched my sites but i can't find solutions.
My requirement is that, my query fetches bank account number from database,
For example, there r one record given by my query then i want to send money to this bank account.
what should i do??? Which api use for me??
My code is given below:
$queryOperator = "SELECT * FROM operatortransaction AS ot LEFT JOIN paymenttransaction AS pt ON
ot.OperatorID != pt.OperatorID WHERE ot.IsPaymentRequest = 1 AND ot.Amount != pt.Amount ";
$arrOperator = $obj->select($queryOperator);
$count = 0;
if(!empty($dataOperator))
{
foreach($arrOperator as $operator)
{
if($arrOperator[$count]['Amount'] >= $arrOperator[$count]['RequestAmount'])
{
$queryDetail = "SELECT * FROM operatorprofile WHERE UserID = '$arrOperator[$count]['OperatorID']' ";
$Data = $obj->select($queryDetail);
// i want to put api code here......//
}
}
}
Thanks.
Hi you can try to use PayPal Xclick
<form action="https://secure.paypal.com/uk/cgi-bin/webscr" method="post" name="paypal" id="paypal">
<!-- Pre Populate the Paypal Checkout Page With Customer Details, -->
<input type="hidden" name="first_name" value="<?php echo Firstname?>">
<input type="hidden" name="last_name" value="<?php echo Lastname?>">
<input type="hidden" name="email" value="<?php echo Email?>">
<input type="hidden" name="address1" value="<?php echo Address?>">
<input type="hidden" name="address2" value="<?php echo Address2?>">
<input type="hidden" name="city" value="<?php echo City?>">
<input type="hidden" name="zip" value="<?php echo Postcode?>">
<input type="hidden" name="day_phone_a" value="">
<input type="hidden" name="day_phone_b" value="<?php echo Mobile?>">
<!-- We dont need to use _ext-enter anymore to prepopulate pages -->
<!-- cmd = _xclick will automatically pre populate pages -->
<!-- More Info: https://www.x.com/docs/DOC-1332 -->
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="paypal#email.com" />
<input type="hidden" name="cbt" value="Return to Your Business Name" />
<input type="hidden" name="currency_code" value="GBP" />
<!-- Allow customer to enter desired quantity -->
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="Name of Item" />
<!-- Custom Value You want to send and process back in the IPN -->
<input type="hidden" name="custom" value="<?php echo session_id().?>" />
<input type="hidden" name="shipping" value="<?php echo $shipping_price; ?>" />
<input type="hidden" name="invoice" value="<?php echo $invoice_id ?>" />
<input type="hidden" name="amount" value="<?php echo $total_order_price; ?>" />
<input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/thankyou"/>
<input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/cancelled" />
<!-- Where to send the paypal IPN to. -->
<input type="hidden" name="notify_url" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/process" />
NOTICE
Do remember to make a very strong VALIDATION!!!
On my local machine, when I submit this form, and I do have items inside the $_SESSION['cart'], the sandbox does recognize the items inside it. But when I tried it on a live server, and I submitted the form while there's an item inside $_SESSION['cart'], the sandbox says my cart is empty... Why is that?
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" <?php if(empty($_SESSION['cart'])){echo "onsubmit=\"return false;\"";} ?>>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?=$ppemail['email']?>" />
<?php
$i = 1;
foreach($_SESSION['cart'] as $id => $qty):
$product = $myCart->getProduct($id);
?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['ProductName']; ?>">
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['ProductID']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['ProductOverridePrice']; ?>">
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $qty; ?>">
<?php
$i++;
endforeach;
?>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="shipping_1" value="<?php echo $shipping; ?>">
<input type="hidden" name="return" value="<?php echo $the_class->settings[0]['DomainName'];?>shopping-cart-details.php">
<input type="hidden" name="cancel_return" value="<?php echo $the_class->settings[0]['DomainName'];?>">
<input type="hidden" name="notify_url" value="<?php echo $the_class->settings[0]['DomainName'];?>classes/paypal.php">
<input type="image" src="images/continue-btn.png" name="pay now" value="pay" />
</form>
i found the bug...the table that was at the live server....i meant, one of the field names was small caps..errr