SHOW:
|
|
- or go back to the newest paste.
| 1 | - | global $errors, $wpcoDb, $Product, $Order, $Item, $Country, $wpcoHtml; |
| 1 | + | global $errors, $wpcoDb, $Product, $Order, $Item, $Country, $wpcoHtml, $Discount; |
| 2 | require_once(dirname(__FILE__) . DS . 'includes' . DS . 'constants.php'); | |
| 3 | ||
| 4 | $order_id = $Order -> current_order_id(); | |
| 5 | $wpcoDb -> model = $Order -> model; | |
| 6 | $order = $wpcoDb -> find(array('id' => $order_id));
| |
| 7 | $wpcoDb -> model = $Item -> model; | |
| 8 | $items = $wpcoDb -> find_all(array('order_id' => $order_id));
| |
| 9 | $user = $this -> userdata($order -> user_id); | |
| 10 | $pmethod = "pp_pro"; | |
| 11 | ||
| 12 | $success = false; | |
| 13 | $errors = null; | |
| 14 | if (empty($_POST['creditCardNumber'])) { $errors['creditCardNumber'] = __('Please fill in a credit card number.', $this -> plugin_name); }
| |
| 15 | elseif (!is_numeric($_POST['creditCardNumber'])) { $errors['creditCardNumber'] = __('Only numbers are allowed in the credit card number.', $this -> plugin_name); }
| |
| 16 | if (empty($_POST['expDateMonth']) || empty($_POST['expDateYear'])) { $errors['expDate'] = __('Please choose an expiry date.', $this -> plugin_name); }
| |
| 17 | if (empty($_POST['cvv2Number'])) { $errors['cvv2Number'] = __('Please fill in a security code.', $this -> plugin_name); }
| |
| 18 | elseif (!is_numeric($_POST['cvv2Number'])) { $errors['cvv2Number'] = __('Only numbers are allowed for the security code.', $this -> plugin_name); }
| |
| 19 | ||
| 20 | if (empty($errors)) {
| |
| 21 | - | //$pp_pro = $this -> vendor('pp_pro', "gateways" . DS);
|
| 21 | + | |
| 22 | ||
| 23 | $api_username = $this -> get_option('pp_pro_api_username');
| |
| 24 | $api_password = $this -> get_option('pp_pro_api_password');
| |
| 25 | $api_signature = $this -> get_option('pp_pro_api_signature');
| |
| 26 | $api_endpoint = $this -> get_option('pp_pro_api_endpoint');
| |
| 27 | ||
| 28 | $email = urlencode($user -> user_email); | |
| 29 | $firstName = urlencode($order -> bill_fname); | |
| 30 | $lastName = urlencode($order -> bill_lname); | |
| 31 | $creditCardType = urlencode($_POST['creditCardType']); | |
| 32 | $creditCardNumber = urlencode($_POST['creditCardNumber']); | |
| 33 | $expDateMonth = urlencode($_POST['expDateMonth']); | |
| 34 | $expDateYear = urlencode($_POST['expDateYear']); | |
| 35 | $cvv2Number = urlencode($_POST['cvv2Number']); | |
| 36 | $address1 = urlencode($order -> bill_address); | |
| 37 | $address2 = urlencode($order -> bill_address2); | |
| 38 | $city = urlencode($order -> bill_city); | |
| 39 | $state = urlencode($order -> bill_state); | |
| 40 | $zip = urlencode($order -> bill_zipcode); | |
| 41 | $amount = urlencode($order -> total); | |
| 42 | $currencyCode = urlencode($this -> get_option('currency'));
| |
| 43 | $shiptophonenum = urlencode($order -> ship_phone); | |
| 44 | $SHIPTONAME = urlencode($order -> ship_fname . ' ' . $order -> ship_lname); | |
| 45 | $SHIPTOSTREET = urlencode($order -> ship_address); | |
| 46 | $SHIPTOSTREET2 = urlencode($order -> ship_address2); | |
| 47 | $shiptocity = urlencode($order -> ship_city); | |
| 48 | $shiptostate = urlencode($order -> ship_state); | |
| 49 | $shiptozip = urlencode($order -> ship_zipcode); | |
| 50 | $wpcoDb -> model = $Country -> model; | |
| 51 | $shiptocountry = $wpcoDb -> field('code', array('id' => $user -> ship_country));
| |
| 52 | $paymentAction = urlencode("Sale");
| |
| 53 | $IPADDRESS = urlencode($_SERVER['REMOTE_ADDR']); | |
| 54 | $nvpRecurring = ''; | |
| 55 | $methodToCall = 'DoDirectPayment'; | |
| 56 | ||
| 57 | $wpcoDb -> model = $Country -> model; | |
| 58 | $countrycode = $wpcoDb -> field('code', array('id' => $user -> bill_country));
| |
| 59 | - | $countrycode = $wpcoDb -> field('code', array('id' => $user -> bill_country));
|
| 59 | + | |
| 60 | if ($countrycode == "UK") { $countrycode = "GB"; }
| |
| 61 | if ($shiptocountry == "UK") { $shiptocountry = "GB"; }
| |
| 62 | ||
| 63 | $nvpstr = | |
| 64 | '&PAYMENTACTION=' . $paymentAction . | |
| 65 | '&CUSTOM=' . $shipmethod_name . | |
| 66 | '&IPADDRESS=' . $IPADDRESS . | |
| 67 | '&AMT=' . $amount . | |
| 68 | '&CREDITCARDTYPE=' . $creditCardType . | |
| 69 | '&ACCT=' . $creditCardNumber . | |
| 70 | '&EXPDATE=' . $expDateMonth . $expDateYear . | |
| 71 | '&CVV2=' . $cvv2Number . | |
| 72 | '&EMAIL=' . $email . | |
| 73 | '&FIRSTNAME=' . $firstName . | |
| 74 | '&LASTNAME=' . $lastName . | |
| 75 | '&STREET=' . $address1 . | |
| 76 | '&STREET2=' . $address2 . | |
| 77 | '&CITY=' . $city . | |
| 78 | '&STATE=' . $state . | |
| 79 | '&ZIP=' . $zip . | |
| 80 | '&COUNTRYCODE=' . $countrycode . | |
| 81 | '&CURRENCYCODE=' . $currencyCode . | |
| 82 | '&SHIPTOPHONENUM=' . $shiptophonenum . | |
| 83 | '&SHIPTONAME=' . $SHIPTONAME . | |
| 84 | '&SHIPTOSTREET=' . $SHIPTOSTREET . | |
| 85 | '&SHIPTOSTREET2=' . $SHIPTOSTREET2 . | |
| 86 | '&SHIPTOCITY=' . $shiptocity . | |
| 87 | '&SHIPTOSTATE=' . $shiptostate . | |
| 88 | '&SHIPTOZIP=' . $shiptozip . | |
| 89 | '&SHIPTOCOUNTRY=' . $shiptocountry; | |
| 90 | ||
| 91 | if ($Order -> do_shipping($order_id)) {
| |
| 92 | $shipmethod_name = $wpcoHtml -> shipmethod_name($order -> shipmethod_id); | |
| 93 | $nvpstr .= '&CUSTOM=' . urlencode($shipmethod_name); | |
| 94 | ||
| 95 | if (!empty($order -> cu_shipmethod)) {
| |
| 96 | $nvpstr .= urlencode(' - ' . html_entity_decode($order -> cu_shipmethod));
| |
| 97 | } | |
| 98 | } | |
| 99 | ||
| 100 | $subtotal = $Order -> total($order_id, false, false, true, true, false); | |
| 101 | $shipping = $Order -> shipping_total($subtotal, $order_id); | |
| 102 | $tax = $Order -> tax_total($order_id); | |
| 103 | ||
| 104 | $discount = $Discount -> total($order_id); | |
| 105 | - | $n = 0; |
| 105 | + | if ($this -> get_option('enablecoupons') == "Y" && $discount > 0) {
|
| 106 | - | $itemamt = 0; |
| 106 | + | |
| 107 | } else {
| |
| 108 | - | if (!empty($items)) {
|
| 108 | + | $n = 0; |
| 109 | - | foreach ($items as $item) {
|
| 109 | + | $itemamt = 0; |
| 110 | - | $itemamount = ($Product -> unit_price($item -> product -> id, $item -> count, $item -> id, false, true, false, false)); |
| 110 | + | |
| 111 | - | $nvpstr .= '&L_NAME' . $n . '=' . urlencode($item -> product -> title); |
| 111 | + | if (!empty($items)) {
|
| 112 | - | $nvpstr .= '&L_DESC' . $n . '=' . urlencode(substr(strip_tags($item -> product -> description), 0, 125)); |
| 112 | + | foreach ($items as $item) {
|
| 113 | - | $nvpstr .= '&L_AMT' . $n . '=' . urlencode(number_format($itemamount, 2, '.', '')); |
| 113 | + | $itemamount = ($Product -> unit_price($item -> product -> id, $item -> count, $item -> id, false, true, false, false)); |
| 114 | - | $nvpstr .= '&L_NUMBER' . $n . '=' . urlencode($item -> product -> code); |
| 114 | + | $nvpstr .= '&L_NAME' . $n . '=' . urlencode($item -> product -> title); |
| 115 | - | $nvpstr .= '&L_QTY' . $n . '=' . urlencode($item -> count); |
| 115 | + | $nvpstr .= '&L_DESC' . $n . '=' . urlencode(substr(strip_tags($item -> product -> description), 0, 125)); |
| 116 | $nvpstr .= '&L_AMT' . $n . '=' . urlencode(number_format($itemamount, 2, '.', '')); | |
| 117 | - | $n++; |
| 117 | + | $nvpstr .= '&L_NUMBER' . $n . '=' . urlencode($item -> product -> code); |
| 118 | - | $itemamt += ($itemamount * $item -> count); |
| 118 | + | $nvpstr .= '&L_QTY' . $n . '=' . urlencode($item -> count); |
| 119 | - | $itemamount = 0; |
| 119 | + | |
| 120 | $n++; | |
| 121 | $itemamt += ($itemamount * $item -> count); | |
| 122 | - | $nvpstr .= '&ITEMAMT=' . urlencode(number_format($itemamt, 2, '.', '')); |
| 122 | + | $itemamount = 0; |
| 123 | - | $nvpstr .= '&SHIPPINGAMT=' . urlencode(number_format($shipping, 2, '.', '')); |
| 123 | + | } |
| 124 | - | $nvpstr .= '&TAXAMT=' . urlencode(number_format($tax, 2, '.', '')); |
| 124 | + | |
| 125 | $nvpstr .= '&ITEMAMT=' . urlencode(number_format($itemamt, 2, '.', '')); | |
| 126 | $nvpstr .= '&SHIPPINGAMT=' . urlencode(number_format($shipping, 2, '.', '')); | |
| 127 | $nvpstr .= '&TAXAMT=' . urlencode(number_format($tax, 2, '.', '')); | |
| 128 | } | |
| 129 | } | |
| 130 | ||
| 131 | $nvpstr .= $nvpRecurring; | |
| 132 | ||
| 133 | $paypalPro = new wpcopp_pro($api_username, $api_password, $api_signature, '', '', false, false, '57.0', $api_endpoint); | |
| 134 | $resArray = $paypalPro -> hash_call($methodToCall, $nvpstr); | |
| 135 | $ack = strtoupper($resArray["ACK"]); | |
| 136 | - | ?> |
| 136 | + | |
| 137 | - | <!--[if IE]><meta http-equiv="refresh" content="0;URL=http://iheart-this.com/tryagain.html"><![endif]--> |
| 137 | + | |
| 138 | if($ack != "SUCCESS") {
| |
| 139 | - | <div style="position:relative; left:40%; margin:0 auto 0 auto; top:250px; font-family:Georgia, 'Times New Roman', Times, serif; font-size:45px; font-style:italic; color:#f5edd5;">OOPS!</div> |
| 139 | + | |
| 140 | - | <div style="position:relative; left:40%; margin:0 auto 0 auto; top:250px; font-family:Stratum1WebBold, sans-serif; size:20px; color:#f5edd5; letter-spacing:1px;"><?php _e('Unfortunately, there was an error processing your order.<br />
|
| 140 | + | $message = __('The transaction has been declined. Please try again.', $this -> plugin_name);
|
| 141 | - | We know it's a pain, but please try again...', $this -> plugin_name); ?><br /><input onClick="<?php echo $Javascript -> location($wpcoHtml -> bill_url()); ?>" class="SuccessBtnSmall" type="submit" style="padding:2px 15px 2px 15px; font-size:12px; font-family:Stratum1WebBold; font-weight:bold; margin:30px auto 0 auto; position:relative;" name="" value="TRY AGAIN" /> |
| 141 | + | |
| 142 | - | </div> |
| 142 | + | |
| 143 | $message = __('The transaction was successful.', $this -> plugin_name);
| |
| 144 | - | |
| 144 | + | $user_id = $user -> ID; |
| 145 | - | |
| 145 | + | |
| 146 | - | <?php |
| 146 | + | $this -> finalize_order($order_id, 'pp_pro', false, "Y"); |
| 147 | } | |
| 148 | ||
| 149 | $paypalPro -> message = $message; | |
| 150 | - | $user_id = $user -> ID; |
| 150 | + | |
| 151 | $title = __('Processing Order', $this -> plugin_name);
| |
| 152 | $this -> process_order($title, $order, $user, $pmethod); | |
| 153 | } | |
| 154 | - | $paypalPro -> done($success, $order_id); |
| 154 | + |