Zen Cart Logo
Forums / Addon Payment Modules / custom payment module help with coupons

custom payment module help with coupons

Views: 908

Results 1 to 3 of 3
17 May 2011, 5:55 PM
#1
jouba avatar

jouba

New Zenner

Join Date:
Jan 2009
Posts:
7
Plugin Contributions:
0

custom payment module help with coupons

Hi everybody, i'm posting here that seems the most appropriate thread to me... hopefully!
I'd like some help for this issue.
I'm implementing a credit card module which redirects the user on a bank website using the curl_setopt() function, so i have this code:

$data="id=$id&password=$password&action=$action&amt=$amt&currencycode=$currencycode&langid=$langid&responseurl=$responseurl&errorurl=$errorurl&trackid=$trackid&udf1=$udf1";
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,bank link xxxx');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
$token=explode(":",$buffer);
$tid=$token[0];

my payment URL will be something like:
$this->form_action_url = 'bank link xxx/payment.jsp?PaymentID='.$tid;

Now, if i add the "curl" code in the class constructor the module is working perfectly but the amount sent to the bank page is not correct in case of coupons, because the array $order has not been processed for taxes and coupons yet. But if i add the "curl code" into the "process_button" function (where the array order is already updated) i cannot find a way to change the "form action" so i cannot set the proper payment id.
Do you guys could please help me to have this sorted because i can't find a solution!! thanx a lot everyone :)

18 May 2011, 12:06 PM
#2
jouba avatar

jouba

New Zenner

Join Date:
Jan 2009
Posts:
7
Plugin Contributions:
0

Re: custom payment module help with coupons

hi again! if nobody can help I was thinking maybe someone knows about a payment module where is used the curl_opt? I can study the code by myself if you can suggest me an existing module with the same logic...
thanks again

20 May 2011, 3:37 PM
#3
jouba avatar

jouba

New Zenner

Join Date:
Jan 2009
Posts:
7
Plugin Contributions:
0

Re: custom payment module help with coupons

well, dunno if anyone else one day could be need of it, but i solved it this way (guess it's working because the coupon's validity is properly checked on phase 2, so this code won't check the coupon but just take it off from the total)

// into constructor
if (($order->info['coupon_code'] != '') or ($_POST['dc_redeem_code'] != '')) $discount = calculateCoupon($order->info['coupon_code'], $order->info['total'], $_POST['dc_redeem_code']);
else $discount =0;
// the amount to pass into the form action
$importo= ($order->info['total']) - $discount;
// the function
function calculateCoupon($cupon,$tot, $code) {
if ($cupon != '') $cup = $cupon; else $cup = $code;
$sql_c='select * from coupons where coupon_code like "'.$cup.'" limit 0,1';
$query_c=@mysql_query($sql_c);
$row=@mysql_fetch_array($query_c);
if ($row['coupon_type'] == 'F') $discount= $row['coupon_amount'];
else $discount= $tot * $row['coupon_amount'] / 100;
return $discount;
}