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

Woocommerce - Globalpayments v1.4.0 #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions assets/frontend/js/globalpayments-googlepay.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@
},

/**
* Merchant display name
* Google Merchant Id
*/
getGoogleMerchantId: function () {
return this.gatewayOptions.google_merchant_id;
},

/**
* Google Merchant Display Name
*/
getGoogleMerchantName: function () {
return this.gatewayOptions.google_merchant_name;
},

/**
* Environment
*/
Expand Down Expand Up @@ -152,7 +159,8 @@
paymentDataRequest.allowedPaymentMethods = [ this.getCardPaymentMethod() ];
paymentDataRequest.transactionInfo = this.getGoogleTransactionInfo();
paymentDataRequest.merchantInfo = {
merchantId: this.getGoogleMerchantId()
merchantId: this.getGoogleMerchantId(),
merchantName: this.getGoogleMerchantName()
}

return paymentDataRequest;
Expand Down
13 changes: 12 additions & 1 deletion assets/frontend/js/globalpayments-secure-payment-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@
case 'INVALID_CARD_SECURITY_CODE':
this.showValidationError( 'card-cvv' );
break;
case 'INVALID_CARD_HOLDER_NAME':
case 'TOO_LONG_DATA':
this.showValidationError('card-holder-name');
break;
case 'MANDATORY_DATA_MISSING':
var n = reason.message.search( "card type" );
if ( n>=0 ) {
Expand Down Expand Up @@ -562,7 +566,7 @@
* @returns {object}
*/
getFieldConfiguration: function () {
return {
var fields = {
'card-number': {
placeholder: this.fieldOptions['card-number-field'].placeholder,
target: '#' + this.id + '-' + this.fieldOptions['card-number-field'].class
Expand All @@ -580,6 +584,13 @@
target: helper.getSubmitButtonTargetSelector( this.id )
}
};
if ( this.fieldOptions.hasOwnProperty( 'card-holder-name-field' ) ) {
fields["card-holder-name"] = {
placeholder: this.fieldOptions['card-holder-name-field'].placeholder,
target: '#' + this.id + '-' + this.fieldOptions['card-holder-name-field'].class
}
}
return fields;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"require": {
"globalpayments/php-sdk": "4.0.4",
"globalpayments/php-sdk": "4.0.5",
"psr/log": "^1.1"
},
"require-dev": {
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion globalpayments-gateway-provider-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: GlobalPayments WooCommerce
* Plugin URI: https://github.com/globalpayments/globalpayments-woocommerce
* Description: This extension allows WooCommerce to use the available Global Payments payment gateways. All card data is tokenized using the respective gateway's tokenization service.
* Version: 1.3.0
* Version: 1.4.0
* Requires PHP: 7.1
* WC tested up to: 6.6.0
* Author: Global Payments
Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Access to our Unified Payments requires sandbox credentials which you can retrie
4. Click ‘Create a New App’. An app is a set of credentials used to access the API and generate access tokens.

== Changelog ==

= 1.4.0 =
* Unified Payments - added Card Holder Name for Hosted Fields
* Add Merchant Name option for the Google Pay gateway

= 1.3.0 =
* Unified Payments - Added Admin Pay for Order (process payments over the phone)
* Added Admin option for Apple Pay button color
Expand Down
17 changes: 15 additions & 2 deletions src/Gateways/GooglePayGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class GooglePayGateway extends AbstractGateway {
*/
public $google_merchant_id;

/**
* Google Merchant Name
*
* @var string
*/
public $google_merchant_name;

/**
* Google pay button color
*
Expand Down Expand Up @@ -88,6 +95,7 @@ public function get_frontend_gateway_options() {
return array(
'env' => $this->gateway->is_production ? Environment::PRODUCTION : Environment::TEST,
'google_merchant_id' => $this->google_merchant_id,
'google_merchant_name' => $this->google_merchant_name,
'global_payments_merchant_id' => $this->global_payments_merchant_id,
'cc_types' => $this->cc_types,
'button_color' => $this->button_color,
Expand All @@ -108,9 +116,14 @@ public function get_gateway_form_fields() {
'custom_attributes' => array( 'required' => 'required' ),
),
'google_merchant_id' => array(
'title' => __( 'Google Merchant Id', 'globalpayments-gateway-provider-for-woocommerce' ),
'title' => __( 'Google Merchant ID', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'text',
'description' => __( 'Your Merchant ID provided by Google.', 'globalpayments-gateway-provider-for-woocommerce' ),
),
'google_merchant_name' => array(
'title' => __( 'Google Merchant Display Name', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'text',
'description' => __( 'Your MerchantID provided by Google.', 'globalpayments-gateway-provider-for-woocommerce' ),
'description' => __( 'Displayed to the customer in the Google Pay dialog.', 'globalpayments-gateway-provider-for-woocommerce' ),
),
'cc_types' => array(
'title' => __( 'Accepted Cards*', 'globalpayments-gateway-provider-for-woocommerce' ),
Expand Down
20 changes: 17 additions & 3 deletions src/Gateways/GpApiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ public function needs_setup() {

public function get_frontend_gateway_options() {
return array(
'accessToken' => $this->get_access_token(),
'apiVersion' => GpApiConnector::GP_API_VERSION,
'env' => $this->is_production ? parent::ENVIRONMENT_PRODUCTION : parent::ENVIRONMENT_SANDBOX,
'accessToken' => $this->get_access_token(),
'apiVersion' => GpApiConnector::GP_API_VERSION,
'env' => $this->is_production ? parent::ENVIRONMENT_PRODUCTION : parent::ENVIRONMENT_SANDBOX,
'requireCardHolderName' => true,
);
}

Expand Down Expand Up @@ -209,6 +210,19 @@ protected function get_access_token() {
return $response->token;
}

protected function secure_payment_fields() {
$fields = parent::secure_payment_fields();
$fields['card-holder-name-field'] = array(
'class' => 'card-holder-name',
'label' => esc_html__( 'Card Holder Name', 'globalpayments-gateway-provider-for-woocommerce' ),
'placeholder' => esc_html__( 'Jane Smith', 'globalpayments-gateway-provider-for-woocommerce' ),
'messages' => array(
'validation' => esc_html__( 'Please enter a valid Card Holder Name', 'globalpayments-gateway-provider-for-woocommerce' ),
),
);
return $fields;
}

protected function add_hooks() {
parent::add_hooks();

Expand Down
19 changes: 18 additions & 1 deletion src/Gateways/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public function __construct( $gateway_id, WC_Order $order = null, array $config
$this->data = $this->get_request_data();
}

/**
* Retrieve Card Holder Name either from Hosted Fields or Billing Address.
*
* @param $customer_name
*
* @return mixed
*/
private function get_card_holder_name( $customer_name ) {
if ( is_array( $this->data ) && isset( $this->data[$this->gateway_id] ) ) {
$data = json_decode( stripslashes( $this->data[$this->gateway_id]['token_response'] ) );
}
return $data->details->cardholderName ?? $customer_name;
}

public function get_default_args() {
return array(
RequestArg::SERVICES_CONFIG => $this->config,
Expand All @@ -61,7 +75,10 @@ public function get_default_args() {
'postalCode' => $this->order->get_billing_postcode(),
'country' => $this->order->get_billing_country(),
) : null,
RequestArg::CARD_HOLDER_NAME => null !== $this->order ? $this->order->get_formatted_billing_full_name() : null,
RequestArg::CARD_HOLDER_NAME =>
$this->get_card_holder_name(
null !== $this->order ? $this->order->get_formatted_billing_full_name() : null
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Plugin {
*
* @var string
*/
const VERSION = '1.3.0';
const VERSION = '1.4.0';

/**
* Init the package.
Expand Down