Exemple #1
0
<?php

include dirname(__FILE__) . "/../common/header.php";
require dirname(__FILE__) . "/../../payzippy-sdk/ChargingRequest.php";
// Get an instance of ChargingRequest.
$pz_charging = new ChargingRequest();
// Set all the parameters that you want to send in the request.
// You can also overwrite the default parameters set in the Config.php file.
$pz_charging->set_terminal_id($_POST["terminal_id"])->set_merchant_transaction_id($_POST["merchant_transaction_id"])->set_udf1($_POST["udf1"])->set_udf2($_POST["udf2"])->set_udf3($_POST["udf3"])->set_udf4($_POST["udf4"])->set_udf5($_POST["udf5"])->set_ui_mode($_POST["ui_mode"])->set_buyer_email_address($_POST["buyer_email_address"])->set_buyer_phone_no($_POST["buyer_phone_no"])->set_buyer_unique_id($_POST["buyer_unique_id"])->set_shipping_address($_POST["shipping_address"])->set_shipping_city($_POST["shipping_city"])->set_shipping_state($_POST["shipping_state"])->set_shipping_zip($_POST["shipping_zip"])->set_shipping_country($_POST["shipping_country"])->set_billing_name($_POST["billing_name"])->set_shipping_address($_POST["shipping_address"])->set_billing_city($_POST["billing_city"])->set_billing_state($_POST["billing_state"])->set_billing_zip($_POST["billing_zip"])->set_billing_country($_POST["billing_country"])->set_transaction_type($_POST["transaction_type"])->set_transaction_amount($_POST["transaction_amount"])->set_payment_method($_POST["payment_method"])->set_emi_months($_POST["emi_months"])->set_currency($_POST["currency"])->set_bank_name($_POST["bank_name"])->set_min_sla($_POST["min_sla"])->set_is_user_logged_in($_POST["is_user_logged_in"])->set_address_count($_POST["address_count"])->set_sales_channel($_POST["sales_channel"])->set_item_total($_POST["item_total"])->set_sms_notify_number($_POST["sms_notify_number"])->set_source($_POST["source"])->set_product_info1($_POST["product_info1"])->set_product_info2($_POST["product_info2"])->set_product_info3($_POST["product_info3"])->set_hash_method($_POST["hash_method"]);
// Finally, call the charge function, to get the charging_object.
// It has the keys - "status", "error_message", "url", "params".
$charging_arr = $pz_charging->charge();
// If there was an error while getting the $charging_object, the value
// "error" will be set to "ERROR".
if ($charging_arr["status"] != "OK") {
    echo '<p>Error: ', $charging_arr["error_message"], "</p>";
    exit;
}
?>

<!--
For integration using IFRAME mode, create a new HTML IFRAME element
and set its "src" attribute to $charging_object["url"]
 -->
<h3>Integration using iframe</h3>
<iframe src="<?php 
echo $charging_arr["url"];
?>
" height="60%" width="100%"></iframe>

<?php 
Exemple #2
0
<?php

require dirname(__FILE__) . "/../../payzippy-sdk/ChargingRequest.php";
// Get an instance of ChargingRequest.
$pz_charging = new ChargingRequest();
// Set all the parameters that you want to send in the request.
// You can also overwrite the default parameters set in the Config.php file.
$pz_charging->set_buyer_email_address($_POST["buyer_email_address"])->set_merchant_transaction_id($_POST["merchant_transaction_id"])->set_transaction_amount($_POST["transaction_amount"])->set_payment_method($_POST["payment_method"])->set_bank_name($_POST["bank_name"])->set_ui_mode($_POST["ui_mode"]);
// Finally, call the charge function, to get the charging_object.
// It has the keys - "status", "error_message", "url", "params".
$charging_object = $pz_charging->charge();
// If there was an error while getting the $charging_object, the value
// "error" will be set to "ERROR".
if ($charging_object["status"] != "OK") {
    echo '<p>Error: ', $charging_object["error_message"], "</p>";
    exit;
}
?>

<html>
    <head>
        <title>Payzippy Integration Example</title>
        <link href="../css/bootstrap.css" rel="stylesheet" type="text/css">
        <style>
            .main-info {
                background-color: #fcf8e3;
                border: 2px solid #fbeed5;
                color: #c09853;
                padding: 25px;
                width: 670px;
                -moz-border-radius: 10px;
 /**
  * Validate the Charging request and return the HTML to display for the given order_id
  *
  * @param $order_id
  * @return string
  */
 function validate_and_charge($order_id)
 {
     $order = new WC_Order($order_id);
     // Callback url
     $redirect_url = get_site_url() . '?wc-api' . "=" . get_class($this);
     $payment_method = get_post_meta($order_id, '_pz_payment_method', true);
     // Append the payment attempts to Transaction ID
     $retries = get_post_meta($order_id, '_pz_attempts', true);
     if (strlen($retries) < 1) {
         $retries = 1;
     }
     update_post_meta($order->id, '_pz_attempts', $retries + 1);
     $merchant_transaction_id = $order_id . '_' . $retries;
     // Building the Charging Request object
     $pz_charging = new ChargingRequest($this->settings);
     $pz_charging->set_buyer_email_address($order->billing_email)->set_buyer_phone_no($order->billing_phone)->set_buyer_unique_id($order->customer_user)->set_billing_name($order->billing_first_name . " " . $order->billing_last_name)->set_billing_address($order->billing_address . " " . $order->billing_address_1 . " " . $order->billing_address_2)->set_billing_city($order->billing_city)->set_billing_state($order->billing_state)->set_billing_country($order->billing_country)->set_billing_zip($order->billing_postcode)->set_shipping_address($order->shipping_address . " " . $order->shipping_address_1 . " " . $order->shipping_address_2)->set_shipping_city($order->shipping_city)->set_shipping_state($order->shipping_state)->set_shipping_country($order->shipping_country)->set_shipping_zip($order->shipping_postcode)->set_merchant_transaction_id($merchant_transaction_id)->set_transaction_amount($order->order_total * 100)->set_payment_method($payment_method)->set_callback_url($redirect_url)->set_source("woocommerce-1.0.3");
     /* Set bank name and/or emi months
                 switch ($payment_method) {
                     case PZ_Constants::PAYMENT_MODE_NET:
                         $pz_charging->set_bank_name(get_post_meta($order_id, '_pz_bank_name', true))
                             ->set_ui_mode(PZ_Constants::UI_MODE_REDIRECT);
                         break;
     
                     case PZ_Constants::PAYMENT_MODE_EMI:
                         $pz_charging->set_bank_name(get_post_meta($order_id, '_pz_bank_name', true))
                             ->set_emi_months(get_post_meta($order_id, '_pz_emi_months', true));
                         break;
                 }
                 */
     // Get charging array
     $pz_charging_array = $pz_charging->charge();
     // Check if charging request was valid
     if ($pz_charging_array['status'] != 'OK') {
         return '<ul class="woocommerce-error">
                     <li>' . $pz_charging_array['error_message'] . '</li>
                 </ul>
                 <a href="' . get_permalink(get_option('woocommerce_checkout_page_id')) . '">
                 Go back to Checkout Page</a>';
     }
     // Return iframe or hidden HTML form.
     switch ($pz_charging->get_ui_mode()) {
         case PZ_Constants::UI_MODE_IFRAME:
             return $this->generate_payzippy_iframe($pz_charging_array);
         case PZ_Constants::UI_MODE_REDIRECT:
             return $this->generate_payzippy_form($pz_charging_array);
     }
 }