コード例 #1
0
function cw_paypal_pro_payflow_request($params)
{
    global $REMOTE_ADDR;
    global $pp_final_action;
    extract($params);
    $is_extcard = false;
    $cardtype = 8;
    if (cw_payment_cc_is_visa($userinfo["card_number"])) {
        $cardtype = 0;
    } elseif (cw_payment_cc_is_mc($userinfo["card_number"])) {
        $cardtype = 1;
    } elseif (cw_payment_cc_is_dc($userinfo["card_number"])) {
        $cardtype = 2;
    } elseif (cw_payment_cc_is_amex($userinfo["card_number"])) {
        $cardtype = 3;
    } elseif (cw_payment_cc_is_diners($userinfo["card_number"])) {
        $cardtype = 4;
    } elseif (cw_payment_cc_is_jcb($userinfo["card_number"])) {
        $cardtype = 5;
    } elseif (cw_payment_cc_is_solo($userinfo["card_number"])) {
        $is_extcard = true;
        $cardtype = "S";
    } elseif (cw_payment_cc_is_switch($userinfo["card_number"])) {
        $is_extcard = true;
        $cardtype = 9;
    }
    $cart =& cw_session_register('cart');
    $secure_oid =& cw_session_register('secure_oid');
    $post = array("tender" => "C", "trxtype" => $pp_final_action == 'Sale' ? 'S' : 'A', "acct" => $userinfo["card_number"], "accttype" => $cardtype, "amt" => $cart['info']['total'], "street" => $userinfo['main_address']['address'] . ($userinfo['main_address']['address_2'] ? $userinfo['main_address']['address_2'] : ''), "city" => $userinfo['main_address']['city'], "state" => $userinfo['main_address']['state'], "country" => $userinfo['main_address']['country'], "zip" => $userinfo['main_address']['zipcode'], "buttonsource" => '', "clientip" => cw_get_valid_ip($REMOTE_ADDR), "currency" => true, "custom" => implode(',', $secure_oid), "cvv2" => $userinfo['card_cvv2'], "email" => $userinfo['email'], "expdate" => $userinfo['card_expire'], "invnum" => $doc_ids[0], "shiptostreet" => $userinfo['current_address']['address'] . ($userinfo['current_address']['address_2'] ? $userinfo['current_address']['address_2'] : ''), "shiptocity" => $userinfo['current_address']['city'], "shiptostate" => $userinfo['current_address']['state'], "shiptocountry" => $userinfo['current_address']['country'], "shiptozip" => $userinfo['current_address']['zipcode'], "firstname" => $userinfo['current_address']['firstname'], "lastname" => $userinfo['current_address']['lastname']);
    if ($is_extcard) {
        $post['cardissue'] = $userinfo['card_issue_no'];
        $post['cardstart'] = $userinfo["card_valid_from"];
    }
    //cw_log_add('payflow_pro', array('post'=>$post));
    $res = cw_paypal_pro_payflow_do($post);
    $err = cw_paypal_pro_payflow_prepare_errors($res);
    if ($err) {
        return $err;
    }
    $res = $res[2];
    $res['status'] = 'success';
    return $res;
}
コード例 #2
0
function cw_payment_paypalpro_run_processor($params, $return)
{
    if ($params['payment_data']['processor'] == 'paypal_pro') {
        extract($params);
        global $config, $current_location;
        $cart =& cw_session_register('cart');
        $secure_oid =& cw_session_register('secure_oid');
        $pp_total = sprintf("%0.2f", $cart['info']['total']);
        $pp_final_action = $config['paypal_pro']['use_preauth'] == 'Y' ? 'Authorization' : 'Sale';
        $pp_username = $config['paypal_pro']['api_access'];
        $pp_password = $config['paypal_pro']['api_password'];
        $pp_currency = $config['paypal_pro']['currency'];
        $pp_cert_file = $app_dir . '/' . $config['paypal_pro']['api_cert_path'];
        $pp_signature = $config['paypal_pro']['api_signature'];
        $notify_url = $current_location . '/payment/index.php?target=paypal_pro';
        $pp_use_cert = $config['paypal_pro']['auth_type'] == 'C';
        $pp_signature_txt = $pp_use_cert ? "" : "<Signature>" . $pp_signature . "</Signature>";
        if ($config['paypal_pro']['test_mode'] == "N") {
            $pp_url = $config['paypal_pro']['auth_type'] == 'C' ? "https://api.paypal.com:443/2.0/" : "https://api-3t.paypal.com:443/2.0/";
            $pp_customer_url = "https://www.paypal.com";
        } else {
            $pp_url = $config['paypal_pro']['auth_type'] == 'C' ? "https://api.sandbox.paypal.com:443/2.0/" : "https://api-aa.sandbox.paypal.com:443/2.0/";
            $pp_customer_url = "https://www.sandbox.paypal.com";
        }
        $avs_codes = array("A" => "Address Address only (no ZIP)", "B" => "International 'A'. Address only (no ZIP)", "C" => "International 'N'", "D" => "International 'X'. Address and Postal Code", "E" => "Not allowed for MOTO (Internet/Phone) transactions", "F" => "UK-specific X Address and Postal Code", "G" => "Global Unavailable", "I" => "International Unavailable", "N" => "None", "P" => "Postal Code only (no Address)", "R" => "Retry", "S" => "Service not Supported", "U" => "Unavailable", "W" => "Nine-digit ZIP code (no Address)", "X" => "Exact match. Address and five-digit ZIP code", "Y" => "Address and five-digit ZIP", "Z" => "Five-digit ZIP code (no Address)");
        $cvv_codes = array("M" => "Match", "N" => "No match", "P" => "Not Processed", "S" => "Service not Supported", "U" => "Unavailable", "X" => "No response");
        if (cw_payment_cc_is_visa($userinfo["card_number"])) {
            $pp_cardtype = "Visa";
        }
        if (cw_payment_cc_is_mc($userinfo["card_number"])) {
            $pp_cardtype = "MasterCard";
        }
        if (cw_payment_cc_is_dc($userinfo["card_number"])) {
            $pp_cardtype = "Discover";
        }
        if (cw_payment_cc_is_amex($userinfo["card_number"])) {
            $pp_cardtype = "Amex";
        }
        if (empty($pp_cardtype)) {
            $top_message = array("content" => cw_get_langvar_by_name("txt_paypal_us_wrong_cc_type"), "type" => "E");
            cw_header_location($current_location . "index.php?target=cart&mode=checkout");
        }
        $payer = $userinfo;
        foreach ($userinfo as $k => $v) {
            if (is_array($v)) {
                continue;
            }
            $payer[$k] = htmlspecialchars($v);
        }
        $payer['main_address']['state'] = $payer['main_address']['country'] == 'US' || $payer['main_address']['country'] == 'CA' || $payer['main_address']['state'] != "" ? $payer['main_address']['state'] : 'Other';
        $payer['current_address']['state'] = $payer['current_address']['country'] == 'US' || $payer['current_address']['country'] == 'CA' || $payer['current_address']['state'] != "" ? $payer['current_address']['state'] : 'Other';
        $payer_ipaddress = cw_get_valid_ip($REMOTE_ADDR);
        $skey = cw_call('cw_payment_start');
        $pp_exp_month = (int) substr($userinfo["card_expire"], 0, 2);
        $pp_exp_year = 2000 + substr($userinfo["card_expire"], 2, 2);
        $s_name = "";
        if (!empty($payer['current_address']['firstname'])) {
            $s_name = $payer['current_address']['firstname'];
        }
        if (!empty($payer['current_address']['lastname'])) {
            $s_name .= (empty($s_name) ? "" : " ") . $payer['current_address']['lastname'];
        }
        if (!empty($s_name)) {
            $s_name = substr($s_name, 0, 32);
        }
        if (empty($payer['main_address']['firstname'])) {
            $payer['main_address']['firstname'] = "Unknown";
        }
        if (empty($payer['main_address']['lastname'])) {
            $payer['main_address']['b_lastname'] = "Unknown";
        }
        $oid = implode(',', $secure_oid);
        $request = <<<EOT
<?xml version="1.0" encoding="{$pp_charset}"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI">
      <Credentials xmlns="urn:ebay:apis:eBLBaseComponents">
        <Username>{$pp_username}</Username>
        <ebl:Password xmlns:ebl="urn:ebay:apis:eBLBaseComponents">{$pp_password}</ebl:Password>
        {$pp_signature_txt}
      </Credentials>
    </RequesterCredentials>
  </soap:Header>
  <soap:Body>
    <DoDirectPaymentReq xmlns="urn:ebay:api:PayPalAPI">
      <DoDirectPaymentRequest>
        <Version xmlns="urn:ebay:apis:eBLBaseComponents">1.00</Version>
        <DoDirectPaymentRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">
          <PaymentAction>{$pp_final_action}</PaymentAction>
          <PaymentDetails>
            <OrderTotal currencyID="{$pp_currency}">{$pp_total}</OrderTotal>
            <ButtonSource>DP_US</ButtonSource>
            <NotifyURL>{$notify_url}</NotifyURL>
            <ShipToAddress>
              <Name>{$s_name}</Name>
              <Street1>{$payer['current_address']['adress']}</Street1>
              <Street2>{$payer['current_address']['address_2']}</Street2>
              <CityName>{$payer['current_address']['city']}</CityName>
              <StateOrProvince>{$payer['current_address']['state']}</StateOrProvince>
              <PostalCode>{$payer['current_address']['zipcode']}</PostalCode>
              <Country>{$payer['current_address']['country']}</Country>
            </ShipToAddress>
            <InvoiceID>{$skey}</InvoiceID>
            <Custom>{$oid}</Custom>
          </PaymentDetails>
          <CreditCard>
            <CreditCardType>{$pp_cardtype}</CreditCardType>
            <CreditCardNumber>{$payer['card_number']}</CreditCardNumber>
            <ExpMonth>{$pp_exp_month}</ExpMonth>
            <ExpYear>{$pp_exp_year}</ExpYear>
            <CardOwner>
              <PayerStatus>verified</PayerStatus>
              <Payer>{$payer['email']}</Payer>
              <PayerName>
                <FirstName>{$payer['main_address']['firstname']}</FirstName>
                <LastName>{$payer['main_address']['lastname']}</LastName>
              </PayerName>
              <PayerCountry>{$payer['main_address']['country']}</PayerCountry>
              <Address>
                <Street1>{$payer['main_address']['address']}</Street1>
                <Street2>{$payer['main_address']['address_2']}</Street2>
                <CityName>{$payer['main_address']['city']}</CityName>
                <StateOrProvince>{$payer['main_address']['state']}</StateOrProvince>
                <Country>{$payer['main_address']['country']}</Country>
                <PostalCode>{$payer['main_address']['zipcode']}</PostalCode>
              </Address>
            </CardOwner>
            <CVV2>{$payer['card_cvv2']}</CVV2>
          </CreditCard>
          <IPAddress>{$payer_ipaddress}</IPAddress>
        </DoDirectPaymentRequestDetails>
      </DoDirectPaymentRequest>
    </DoDirectPaymentReq>
  </soap:Body>
</soap:Envelope>
EOT;
        $result = cw_func_call('cw_paypal_express_request', array('request' => $request));
        if ($result['success']) {
            $return['code'] = 1;
            $bill_message = 'Accepted';
        } else {
            $bill_message = 'Declined';
            $return['code'] = 2;
        }
        $additional_fields = array();
        foreach (array('TransactionID') as $add_field) {
            if (isset($result[$add_field]) && strlen($result[$add_field]) > 0) {
                $additional_fields[] = ' ' . $add_field . ': ' . $result[$add_field];
            }
        }
        if (!empty($additional_fields)) {
            $bill_message .= ' (' . implode(', ', $additional_fields) . ')';
        }
        if (!empty($result['error'])) {
            $bill_message .= sprintf(" Error: %s (Code: %s, Severity: %s)", $result['error']['LongMessage'], $result['error']['ErrorCode'], $result['error']['Severity']);
        }
        $return["billmes"] = $bill_message;
        if (isset($result['AVSCode'])) {
            $return['avsmes'] = empty($avs_codes[$result['AVSCode']]) ? "Code: " . $result['AVSCode'] : $avs_codes[$result['AVSCode']];
        }
        if (isset($result['CVV2Code'])) {
            $return['cvvmes'] = empty($cvv_codes[$result['CVV2Code']]) ? "Code: " . $result['CVV2Code'] : $cvv_codes[$result['CVV2Code']];
        }
        if ($pp_final_action != 'Sale') {
            $return['is_preauth'] = true;
        }
        $return['extra_order_data'] = array("paypal_type" => "USDP", "paypal_txnid" => $result['TransactionID'], "capture_status" => $pp_final_action != 'Sale' ? 'A' : '', 'transaction_amount' => $pp_total);
    }
    return $return;
}
コード例 #3
0
function cw_payment_check_results($payment_data)
{
    $log_payment_failure = false;
    if (!empty($payment_data['sess_id'])) {
        if (cw_check_webinput() == "err") {
            $log_payment_failure = true;
            if ($payment_data['code'] == 1) {
                $__transaction_status = "successful";
                $payment_data['code'] = 3;
            } elseif ($payment_data['code'] == 3) {
                $__transaction_status = "queued";
            } else {
                $__transaction_status = "declined";
            }
            $payment_data['billmes'] = "Gateway reported of {$__transaction_status} transaction but it's response came from the IP that is not specified in the list of valid IPs: " . cw_get_valid_ip($_SERVER['REMOTE_ADDR']) . "\n-- response ----\n" . $payment_data['billmes'];
        }
        $sessurl = APP_SESSION_NAME . "=" . $payment_data['sess_id'] . "&";
        cw_session_id($payment_data['sess_id']);
    } else {
        $sessurl = '';
    }
    $cart =& cw_session_register('cart', array());
    $secure_oid =& cw_session_register("secure_oid");
    $bill_error = $reason = '';
    $fatal = false;
    if (!empty($payment_data)) {
        $saved_payment_data = $payment_data;
    } else {
        $saved_payment_data = false;
    }
    if (empty($secure_oid)) {
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
        $payment_data['billmes'] = "error: your order was lost";
        $reason = $payment_data['billmes'];
        $fatal = true;
    } elseif (empty($cart) && empty($payment_data['skey'])) {
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
        $payment_data['billmes'] = "Error: Your cart was lost";
        $reason = $payment_data['billmes'];
        $fatal = true;
    } elseif ($payment_data['code'] == 3) {
        $reason = $payment_data['billmes'];
    } elseif ($payment_data['code'] == 2) {
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
        $reason = $payment_data['billmes'];
    } elseif ($payment_data['code'] == 1) {
        if (isset($payment_return) && !empty($payment_return) && $payment_data['code'] != 2) {
            if (isset($payment_return['total'])) {
                $sum = 0;
                foreach ($secure_oid as $_oid) {
                    $o = cw_order_data($_oid);
                    $sum += $o['order']['total'];
                }
                if ($sum != doubleval($payment_return['total'])) {
                    $payment_data['code'] = 2;
                    $payment_data['billmes'] .= "; Payment amount mismatch.";
                }
            }
            if ($payment_data['code'] != 2 && isset($payment_return['currency']) && isset($payment_return['_currency']) && !empty($payment_return['_currency']) && $payment_return['currency'] != $payment_return['_currency']) {
                $payment_data['code'] = 2;
                $payment_data['billmes'] .= "; Payment amount mismatch.";
            }
        }
        if ($payment_data['code'] == 1) {
            $payment_data['billmes'] = "Approved: " . $payment_data['billmes'];
        } else {
            $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_error");
            $reason = $payment_data['billmes'];
            $payment_data['billmes'] = "Declined: " . $payment_data['billmes'];
        }
    } else {
        # unavailable
        $bill_error = cw_get_langvar_by_name("lbl_error_ccprocessor_unavailable");
        $payment_data['billmes'] = "Error: Payment gateway is unavailable";
    }
    if (!$fatal) {
        cw_load('doc');
        $status_after_capture = cw_call('cw_payment_doc_status_after_capture', array($payment_data));
        $order_status = $bill_error ? "F" : ($payment_data['code'] == 3 ? "Q" : $status_after_capture);
        if (in_array($order_status, array('P', 'Q', $status_after_capture)) && !empty($payment_data['is_preauth'])) {
            $order_status = 'A';
            // Authorized
        }
        if ($payment_data['code'] == 1 || $payment_data['code'] == 3) {
            if (empty($payment_data['skey'])) {
                $cart = array();
            }
        }
        $advinfo = array();
        $advinfo[] = "Reason: " . $payment_data['billmes'];
        if ($payment_data['avsmes']) {
            $advinfo[] = "AVS info: " . $payment_data['avsmes'];
        }
        if ($payment_data['cvvmes']) {
            $advinfo[] = "CVV info: " . $payment_data['cvvmes'];
        }
        if (isset($cmpi_result)) {
            $advinfo[] = "3-D Secure Transaction:";
            if (isset($cmpi_result['Enrolled'])) {
                $advinfo[] = "  TransactionId: " . $cmpi_result['TransactionId'];
                $advinfo[] = "  Enrolled: " . $cmpi_result['Enrolled'];
            } else {
                $advinfo[] = "  PAResStatus: " . $cmpi_result['PAResStatus'];
                $advinfo[] = "  PAResStatusDesc: " . $cmpi_result['PAResStatusDesc'];
                $advinfo[] = "  CAVV: " . $cmpi_result['Cavv'];
                $advinfo[] = "  SignatureVerification: " . $cmpi_result['SignatureVerification'];
                $advinfo[] = "  Xid: " . $cmpi_result['Xid'];
                $advinfo[] = "  EciFlag: " . $cmpi_result['EciFlag'];
            }
            if (!empty($cmpi_result['ErrorNo'])) {
                $advinfo[] = "  ErrorNo: " . $cmpi_result['ErrorNo'];
            }
            if (!empty($cmpi_result['ErrorDesc'])) {
                $advinfo[] = "  ErrorDesc: " . $cmpi_result['ErrorDesc'];
            }
        }
        cw_call('cw_doc_change_status', array($secure_oid, $order_status, join("\n", $advinfo)));
    }
    if (!empty($payment_data['extra_order_data'])) {
        foreach ($secure_oid as $oid) {
            cw_call('cw_doc_place_extras_data', array($oid, $payment_data['extra_order_data']));
        }
        unset($payment_data['extra_order_data']);
    }
    cw_session_unregister("secure_oid");
    cw_session_save();
    return array('bill_error' => $bill_error, 'sessurl' => $sessurl, 'reason' => $reason, 'doc_ids' => $secure_oid);
}