Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amex for CAD needs to be added, PFW-218 #1189

Merged
merged 7 commits into from
Aug 28, 2018
35 changes: 11 additions & 24 deletions classes/wc-gateway-paypal-pro-payflow-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,25 +479,9 @@ public function is_available() {
*/
function process_payment($order_id) {
$order = new WC_Order($order_id);
$card_number = isset($_POST['paypal_pro_payflow-card-number']) ? wc_clean($_POST['paypal_pro_payflow-card-number']) : '';
$card_cvc = isset($_POST['paypal_pro_payflow-card-cvc']) ? wc_clean($_POST['paypal_pro_payflow-card-cvc']) : '';
$card_exp_year = isset($_POST['paypal_pro_payflow_card_expiration_year']) ? wc_clean($_POST['paypal_pro_payflow_card_expiration_year']) : '';
$card_exp_month = isset($_POST['paypal_pro_payflow_card_expiration_month']) ? wc_clean($_POST['paypal_pro_payflow_card_expiration_month']) : '';
$card_number = str_replace(array(' ', '-'), '', $card_number);
$card_type = AngellEYE_Utility::card_type_from_account_number($card_number);
if ($card_type == 'amex' && (get_woocommerce_currency() != 'USD' && get_woocommerce_currency() != 'AUD')) {
throw new Exception(__('Your processor is unable to process the Card Type in the currency requested. Please try another card type', 'paypal-for-woocommerce'));
}
if (strlen($card_exp_year) == 4) {
$card_exp_year = $card_exp_year - 2000;
}

$card_exp_month = (int) $card_exp_month;
if ($card_exp_month < 10) {
$card_exp_month = '0' . $card_exp_month;
}
$card = $this->get_posted_card();
// Do payment with paypal
return $this->do_payment($order, $card_number, $card_exp_month . $card_exp_year, $card_cvc);
return $this->do_payment($order, $card->number, $card->exp_month . $card->exp_year, $card->cvc);
}

/**
Expand Down Expand Up @@ -1171,16 +1155,21 @@ public function angelleye_woocommerce_credit_card_form_start($current_id) {
}

public function get_posted_card() {
try {
$card_number = isset($_POST['paypal_pro_payflow-card-number']) ? wc_clean($_POST['paypal_pro_payflow-card-number']) : '';
$card_cvc = isset($_POST['paypal_pro_payflow-card-cvc']) ? wc_clean($_POST['paypal_pro_payflow-card-cvc']) : '';
$card_exp_year = isset($_POST['paypal_pro_payflow_card_expiration_year']) ? wc_clean($_POST['paypal_pro_payflow_card_expiration_year']) : '';
$card_exp_month = isset($_POST['paypal_pro_payflow_card_expiration_month']) ? wc_clean($_POST['paypal_pro_payflow_card_expiration_month']) : '';
$card_number = str_replace(array(' ', '-'), '', $card_number);
$card_type = AngellEYE_Utility::card_type_from_account_number($card_number);
if ($card_type == 'amex' && (get_woocommerce_currency() != 'USD' && get_woocommerce_currency() != 'AUD')) {
throw new Exception(__('Your processor is unable to process the Card Type in the currency requested. Please try another card type', 'paypal-for-woocommerce'));
if ($card_type == 'amex') {
if (WC()->countries->get_base_country() == 'CA' && get_woocommerce_currency() == 'USD' && apply_filters('angelleye_paypal_pro_payflow_amex_ca_usd', true, $this)) {
throw new Exception(__('Your processor is unable to process the Card Type in the currency requested. Please try another card type', 'paypal-for-woocommerce'));
}
if (get_woocommerce_currency() != 'USD' && get_woocommerce_currency() != 'AUD' && get_woocommerce_currency() != 'CAD') {
throw new Exception(__('Your processor is unable to process the Card Type in the currency requested. Please try another card type', 'paypal-for-woocommerce'));
}
}

if (strlen($card_exp_year) == 4) {
$card_exp_year = $card_exp_year - 2000;
}
Expand All @@ -1197,9 +1186,7 @@ public function get_posted_card() {
'start_month' => '',
'start_year' => ''
);
} catch (Exception $ex) {

}

}

public function add_payment_method() {
Expand Down