Skip to content

Commit

Permalink
Merge pull request #1189 from angelleye/PFW-218
Browse files Browse the repository at this point in the history
Amex for CAD needs to be added, PFW-218
  • Loading branch information
Andrew Angell committed Aug 28, 2018
2 parents 7ff06e4 + a40f956 commit aa2f2fd
Showing 1 changed file with 11 additions and 24 deletions.
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 @@ -1173,16 +1157,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 @@ -1199,9 +1188,7 @@ public function get_posted_card() {
'start_month' => '',
'start_year' => ''
);
} catch (Exception $ex) {

}

}

public function add_payment_method() {
Expand Down

0 comments on commit aa2f2fd

Please sign in to comment.