Skip to content

Commit

Permalink
Merge pull request #10 from max2u/master
Browse files Browse the repository at this point in the history
Custom Card payment method title
  • Loading branch information
max2u committed Sep 29, 2020
2 parents efdf99e + 2cc2032 commit 735544f
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct()

// Define user set variables
$this->method_title = __('PointCheckout Card', 'woocommerce');
$this->title = 'Card';
$this->title = PointCheckout_Card_Config::getInstance()->getTitle() ;
$this->description = PointCheckout_Card_Config::getInstance()->getDescription();
$this->paymentService = PointCheckout_Card_Payment::getInstance();
$this->config = PointCheckout_Card_Config::getInstance();
Expand All @@ -44,20 +44,23 @@ function process_admin_options()

public function is_available()
{
if (!$this->config->isEnabled())
if (!$this->config->isEnabled()) {
return false;
}

$valid = true;
if ($this->config->isSpecificUserRoles()) {
$valid = false;
$user_id = WC()->customer->get_id();
$user = new WP_User($user_id);
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role)
foreach ($user->roles as $user_role) {
foreach ($this->config->getSpecificUserRoles() as $role) {
if ($role == $user_role) {
$valid = true;
}
}
}
}
}

Expand Down Expand Up @@ -159,6 +162,12 @@ function init_form_fields()
'0' => __('Disabled', 'pointcheckout_card'),
)
),
'title' => array(
'title' => __('Title', 'pointcheckout_card'),
'type' => 'text',
'description' => __('This is the payment method title the user sees during checkout.', 'pointcheckout_card'),
'default' => __('Card', 'pointcheckout_card')
),
'description' => array(
'title' => __('Description', 'pointcheckout_card'),
'type' => 'text',
Expand Down Expand Up @@ -237,9 +246,7 @@ function init_form_fields()
function getCountries()
{
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');

return $countries;
return $countries_obj->__get('countries');
}

function getRoles()
Expand Down
10 changes: 10 additions & 0 deletions pointcheckout_payment_card/includes/lib/class-pc-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class PointCheckout_Card_Config extends PointCheckout_Card_Parent
private $specific_uesr_roles;
private $new_order_status;
public $description;
public $title;


public function __construct()
{
Expand All @@ -33,6 +35,7 @@ public function __construct()
$this->specific_uesr_roles = $this->_getShoppingCartConfig('specific_user_roles');
$this->new_order_status = $this->_getShoppingCartConfig('new_order_status');
$this->description = $this->_getShoppingCartConfig('description');
$this->title = $this->_getShoppingCartConfig('title');
}

/**
Expand Down Expand Up @@ -165,4 +168,11 @@ public function getDescription()
{
return $this->description;
}

public function getTitle() {
if ( empty($this->title)) {
return "Card";
}
return $this->title;
}
}
7 changes: 2 additions & 5 deletions pointcheckout_payment_card/includes/lib/class-pc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function getOrderId()

public function getOrderById($orderId)
{
$order = wc_get_order($orderId);
return $order;
return wc_get_order($orderId);
}

public function getLoadedOrder()
Expand All @@ -56,12 +55,10 @@ public function getEmail()

public function getCustomerName()
{
$fullName = '';
$firstName = $this->order->billing_first_name;
$lastName = $this->order->billing_last_name;

$fullName = trim($firstName . ' ' . $lastName);
return $fullName;
return trim($firstName . ' ' . $lastName);
}

public function getCurrencyCode()
Expand Down
4 changes: 2 additions & 2 deletions pointcheckout_payment_card/includes/lib/class-pc-parent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class PointCheckout_Card_Parent extends WC_Payment_Gateway
{
public $id = 'pointcheckout_card';
public function __construct()
{
public function __construct() {
// NO INTITALIZATION REQuIRED
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,33 @@ public function getPaymentRequestParams()
$params['paymentMethods'] = ["CARD"];
$params['resultUrl'] = get_site_url() . "?wc-api=wc_gateway_pointcheckout_card_process_response";

// CUSTOMER
$customer = array();
$customer['id'] = $order->get_customer_id();
$customer['firstName'] = $order->get_billing_first_name();
$customer['lastName'] = $order->get_billing_last_name();
$customer['email'] = $order->get_billing_email();
$customer['phone'] = $order->get_billing_phone();

// BILLING ADDRESS
$billingAddress = array();
$billingAddress['name'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$billingAddress['address1'] = $order->get_billing_address_1();
$billingAddress['address2'] = $order->get_billing_address_2();
$billingAddress['city'] = $order->get_billing_city();
$billingAddress['state'] = $order->get_billing_state();
$billingAddress['country'] = $order->get_billing_country();
$customer['billingAddress'] = $billingAddress;

// SHIPPING ADDRESS
$shippingAddress = array();
$shippingAddress['name'] = $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name();
$shippingAddress['address1'] = $order->get_shipping_address_1();
$shippingAddress['address2'] = $order->get_shipping_address_2();
$shippingAddress['city'] = $order->get_shipping_city();
$shippingAddress['country'] = $order->get_shipping_country();

$customer['billingAddress'] = $billingAddress;
$shippingAddress['state'] = $order->get_shipping_state();
$customer['shippingAddress'] = $shippingAddress;
$customer['firstname'] = $order->get_billing_first_name();
$customer['lastname'] = $order->get_billing_last_name();
$customer['email'] = $order->get_billing_email();
$customer['phone'] = $order->get_billing_phone();

$params['customer'] = $customer;

Expand All @@ -104,7 +109,7 @@ public function getPaymentRequestForm()
}
$paymentRequestParams = $this->getPaymentRequestParams();
$response = $this->postCheckout($paymentRequestParams);
if (($response->success == 'true')) {
if ($response->success == 'true') {
$actionUrl = $response->result->redirectUrl;
WC()->session->set('checkoutId', $response->result->id);
} else {
Expand All @@ -115,12 +120,12 @@ public function getPaymentRequestForm()
$this->pcOrder->clearSessionCurrentOrder();
$form = '<form style="display:none" name="frm_pointcheckout_card_payment" id="frm_pointcheckout_card_payment" method="GET" action="' . $actionUrl . '">';
$form .= '<input type="submit">';
$formArray = array(

return array(
'form' => $form,
'response' => $response

);
return $formArray;
}

public function postCheckout($paymentRequestParams)
Expand All @@ -144,7 +149,7 @@ public function checkPaymentStatus()
if (!empty($order)) {


if ($response->success != true) {
if (!$response->success) {
$order->update_status('canceled');
$errorMsg = isset($response->error) ? $response->error : 'connecting to pointcheckout failed';
$note = __("[ERROR] order canceled :" . $errorMsg);
Expand All @@ -162,7 +167,7 @@ public function checkPaymentStatus()
$result = $response->result;


if ($response->success == true && $result->status != 'PAID') {
if ($response->success && $result->status != 'PAID') {

$order->update_status('canceled');
$note = __($this->getOrderHistoryMessage($result->id, 0, $result->status, $result->currency));
Expand Down
2 changes: 1 addition & 1 deletion pointcheckout_payment_card/includes/lib/class-pc-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getApiBaseUrl()
if ($this->pcConfig->isLiveMode()) {
return 'https://api.pointcheckout.com/mer/v1.2/checkouts/';
} elseif ($this->pcConfig->isStagingMode()) {
return 'https://api.test.pointcheckout.com/mer/v1.2/checkouts/';
return 'https://api.staging.pointcheckout.com/mer/v1.2/checkouts/';
} else {
return 'https://api.test.pointcheckout.com/mer/v1.2/checkouts/';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,23 @@ function process_admin_options()

public function is_available()
{
if (!$this->config->isEnabled())
if (!$this->config->isEnabled()) {
return false;
}

$valid = true;
if ($this->config->isSpecificUserRoles()) {
$valid = false;
$user_id = WC()->customer->get_id();
$user = new WP_User($user_id);
if (!empty($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $user_role)
foreach ($user->roles as $user_role) {
foreach ($this->config->getSpecificUserRoles() as $role) {
if ($role == $user_role) {
$valid = true;
}
}
}
}
}

Expand Down Expand Up @@ -238,9 +241,7 @@ function init_form_fields()
function getCountries()
{
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');

return $countries;
return $countries_obj->__get('countries');
}

function getRoles()
Expand Down
7 changes: 2 additions & 5 deletions pointcheckout_payment_rewards/includes/lib/class-pc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function getOrderId()

public function getOrderById($orderId)
{
$order = wc_get_order($orderId);
return $order;
return wc_get_order($orderId);
}

public function getLoadedOrder()
Expand All @@ -56,12 +55,10 @@ public function getEmail()

public function getCustomerName()
{
$fullName = '';
$firstName = $this->order->billing_first_name;
$lastName = $this->order->billing_last_name;

$fullName = trim($firstName . ' ' . $lastName);
return $fullName;
return trim($firstName . ' ' . $lastName);
}

public function getCurrencyCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class PointCheckout_Rewards_Parent extends WC_Payment_Gateway
public $id = 'pointcheckout_rewards';
public function __construct()
{
// NO INTITALIZATION REQuIRED
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,33 @@ public function getPaymentRequestParams()
$params['paymentMethods'] = ["POINTCHECKOUT"];
$params['resultUrl'] = get_site_url() . "?wc-api=wc_gateway_pointcheckout_rewards_process_response";

// CUSTOMER
$customer = array();
$customer['id'] = $order->get_customer_id();
$customer['firstName'] = $order->get_billing_first_name();
$customer['lastName'] = $order->get_billing_last_name();
$customer['email'] = $order->get_billing_email();
$customer['phone'] = $order->get_billing_phone();

// BILLING ADDRESS
$billingAddress = array();
$billingAddress['name'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$billingAddress['address1'] = $order->get_billing_address_1();
$billingAddress['address2'] = $order->get_billing_address_2();
$billingAddress['city'] = $order->get_billing_city();
$billingAddress['state'] = $order->get_billing_state();
$billingAddress['country'] = $order->get_billing_country();
$customer['billingAddress'] = $billingAddress;

// SHIPPING ADDRESS
$shippingAddress = array();
$shippingAddress['name'] = $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name();
$shippingAddress['address1'] = $order->get_shipping_address_1();
$shippingAddress['address2'] = $order->get_shipping_address_2();
$shippingAddress['city'] = $order->get_shipping_city();
$shippingAddress['country'] = $order->get_shipping_country();

$customer['billingAddress'] = $billingAddress;
$shippingAddress['state'] = $order->get_shipping_state();
$customer['shippingAddress'] = $shippingAddress;
$customer['firstname'] = $order->get_billing_first_name();
$customer['lastname'] = $order->get_billing_last_name();
$customer['email'] = $order->get_billing_email();
$customer['phone'] = $order->get_billing_phone();

$params['customer'] = $customer;

Expand All @@ -104,7 +109,7 @@ public function getPaymentRequestForm()
}
$paymentRequestParams = $this->getPaymentRequestParams();
$response = $this->postCheckout($paymentRequestParams);
if (($response->success == 'true')) {
if ($response->success == 'true') {
$actionUrl = $response->result->redirectUrl;
WC()->session->set('checkoutId', $response->result->id);
} else {
Expand All @@ -115,12 +120,12 @@ public function getPaymentRequestForm()
$this->pcOrder->clearSessionCurrentOrder();
$form = '<form style="display:none" name="frm_pointcheckout_payment" id="frm_pointcheckout_payment" method="GET" action="' . $actionUrl . '">';
$form .= '<input type="submit">';
$formArray = array(

return array(
'form' => $form,
'response' => $response

);
return $formArray;
}

public function postCheckout($paymentRequestParams)
Expand All @@ -144,7 +149,7 @@ public function checkPaymentStatus()
if (!empty($order)) {


if ($response->success != true) {
if (!$response->success) {
$order->update_status('canceled');
$errorMsg = isset($response->error) ? $response->error : 'connecting to pointcheckout failed';
$note = __("[ERROR] order canceled :" . $errorMsg);
Expand All @@ -162,7 +167,7 @@ public function checkPaymentStatus()
$result = $response->result;


if ($response->success == true && $result->status != 'PAID') {
if ($response->success && $result->status != 'PAID') {

$order->update_status('canceled');
$note = __($this->getOrderHistoryMessage($result->id, 0, $result->status, $result->currency));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getApiBaseUrl()
if ($this->pcConfig->isLiveMode()) {
return 'https://api.pointcheckout.com/mer/v1.2/checkouts/';
} elseif ($this->pcConfig->isStagingMode()) {
return 'https://api.test.pointcheckout.com/mer/v1.2/checkouts/';
return 'https://api.staging.pointcheckout.com/mer/v1.2/checkouts/';
} else {
return 'https://api.test.pointcheckout.com/mer/v1.2/checkouts/';
}
Expand Down

0 comments on commit 735544f

Please sign in to comment.