Skip to content

Commit

Permalink
Add customer identifier to checkout init request and Spanish language…
Browse files Browse the repository at this point in the history
… support (#24)
  • Loading branch information
onurpolattimur authored Dec 17, 2024
1 parent c485401 commit 42bbe0d
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 68 deletions.
63 changes: 46 additions & 17 deletions craftgate-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Accept debit/credit card payments easily and directly on your WordPress site using Craftgate.
* Author: Craftgate
* Author URI: https://craftgate.io/
* Version: 1.0.12
* Version: 1.0.13
* Requires at least: 4.4
* Tested up to: 6.0
* WC requires at least: 3.0.0
Expand Down Expand Up @@ -98,9 +98,8 @@ public function __construct()
// Inits admin field and settings.
$this->init_admin_settings_form_fields();
$this->init_settings();

$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
$this->title = !empty($this->get_option('title')) ? $this->get_option('title') : __('Pay with Debit/Credit Card', $this->text_domain);
$this->description = !empty($this->get_option('description')) ? $this->get_option('description') : __('You can pay with Debit and Credit Card', $this->text_domain);

// Inits api fields.
$this->init_craftgate_api();
Expand Down Expand Up @@ -151,11 +150,14 @@ public function init_craftgate_checkout_form($order_id = null)
$this->set_cookie_same_site();
$request = $this->build_init_checkout_form_request($order_id);
$response = $this->craftgate_api->init_checkout_form($request);

if (isset($response->pageUrl)) {
$language = $this->get_option("language");
$siteLanguage = explode('_', get_locale())[0];
$optionLanguage = $this->get_option("language");
$lang = !empty($optionLanguage) ? $optionLanguage : $siteLanguage;
$iframeOptions = $this->get_option("iframe_options");
echo '<div id="craftgate_payment_form"><iframe src="' . $response->pageUrl . '&iframe=true&lang=' . $language . '&' . $iframeOptions . '"></iframe></div>';
$iframeUrl = $response->pageUrl . '&iframe=true&' . $iframeOptions . '&lang=' . $lang;;

echo '<div id="craftgate_payment_form"><iframe src="' . $iframeUrl . '"></iframe></div>';
?>
<script>
window.addEventListener("message", function (event) {
Expand Down Expand Up @@ -457,7 +459,7 @@ private function build_items($order)
private function build_init_checkout_form_request($order_id)
{
$order = $this->retrieve_order($order_id);
$customer_id = $order->get_user()->ID;
$customer_id = $order->get_user() ? $order->get_user()->ID : null;
$items = $this->build_items($order);
$total_price = 0;
foreach ($items as $item) {
Expand All @@ -472,6 +474,7 @@ private function build_init_checkout_form_request($order_id)
'callbackUrl' => rtrim(get_bloginfo('url'), '/') . '/' . "?wc-api=craftgate_gateway_callback&order_id=" . $order_id,
'disableStoreCard' => $customer_id == null,
'items' => $items,
'additionalParams' => array()
);

$card_user_key = $this->retrieve_card_user_key($customer_id, $this->api_key);
Expand All @@ -480,13 +483,35 @@ private function build_init_checkout_form_request($order_id)
}

if ($order->get_billing_email() && strlen(trim($order->get_billing_email())) > 0) {
$init_checkout_form_request['additionalParams'] = array(
'buyerEmail' => $order->get_billing_email()
);
$init_checkout_form_request['additionalParams']['buyerEmail'] = $order->get_billing_email();
}

$customer_identifier = $this->retrieve_customer_identifier($order);
if ($customer_identifier != null) {
$init_checkout_form_request['additionalParams']['customerIdentifier'] = $customer_identifier;
}

return $init_checkout_form_request;
}

private function retrieve_customer_identifier($order)
{
$billing_phone = $order->get_billing_phone();
$billing_email = $order->get_billing_email();
$user = $order->get_user();
$user_email = $user ? $user->user_email : null;

if (!empty($billing_phone)) {
return $billing_phone;
} elseif (!empty($billing_email)) {
return $billing_email;
} elseif (!empty($user_email)) {
return $user_email;
}

return null;
}

/**
* Checks if TRY currency is processed.
*
Expand Down Expand Up @@ -575,7 +600,7 @@ public function admin_options()
</p>
<div class="inline error">
<p>
<strong><?php _e('Craftgate Payment Gateway is not available to use', $this->text_domain) ?></strong>: <?php _e('The only supported currency is TRY.', $this->text_domain) ?>
<strong><?php _e('Craftgate Payment Gateway is not available to use', $this->text_domain) ?></strong>: <?php _e('Currency is not supported.', $this->text_domain) ?>
</p>
</div>
<?php }
Expand All @@ -599,13 +624,15 @@ public function init_admin_settings_form_fields()
'type' => 'text',
'description' => __('This controls the title which the user sees during checkout.', $this->text_domain),
'desc_tip' => false,
'default' => __('Pay with Debit/Credit Card', $this->text_domain),
'placeholder' => __('Pay with Debit/Credit Card', $this->text_domain),
'default' => null,
),
'description' => array(
'title' => __('Description', $this->text_domain),
'type' => 'textarea',
'description' => __('This controls the description which the user sees during checkout.', $this->text_domain),
'default' => __('You can pay with Debit and Credit Card', $this->text_domain),
'placeholder' => __('You can pay with Debit and Credit Card', $this->text_domain),
'default' => null,
),
'live_api_key' => array(
'title' => __('Live API Key', $this->text_domain),
Expand Down Expand Up @@ -642,11 +669,13 @@ public function init_admin_settings_form_fields()
'title' => __('Language', $this->text_domain),
'type' => 'select',
'options' => array(
'tr' => 'Turkish',
'en' => 'English',
null => __('Site Language', $this->text_domain),
'tr' => __('Turkish', $this->text_domain),
'en' => __('English', $this->text_domain),
'es' => __('Spanish', $this->text_domain),
),
'description' => __('Change the language of payment form.', $this->text_domain),
'default' => 'tr',
'default' => null,
),
'iframe_options' => array(
'title' => __('Iframe Options', $this->text_domain),
Expand Down
Binary file added languages/craftgate-payment-gateway-es_ES.mo
Binary file not shown.
197 changes: 197 additions & 0 deletions languages/craftgate-payment-gateway-es_ES.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2024-12-12 15:59+0300\n"
"PO-Revision-Date: 2024-12-12 16:19+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.5\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: _;__;_e\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPath-1: includes\n"

#: craftgate-payment-gateway.php:95
msgid ""
"Accept debit/credit card payments easily and directly on your WordPress site "
"using Craftgate."
msgstr ""
"Acepte pagos con tarjeta de débito/crédito fácil y directamente en su sitio "
"WordPress utilizando Craftgate."

#: craftgate-payment-gateway.php:96 craftgate-payment-gateway.php:628
msgid "Pay with Debit/Credit Card"
msgstr "Pagar con tarjeta de débito/crédito"

#: craftgate-payment-gateway.php:174 craftgate-payment-gateway.php:178
#: craftgate-payment-gateway.php:312
msgid "An error occurred. Error Code: "
msgstr "Se ha producido un error. Código de error: "

#: craftgate-payment-gateway.php:358
msgid "Installment Fee"
msgstr "Cuota"

#: craftgate-payment-gateway.php:447
msgid "Shipping Total"
msgstr "Total envío"

#: craftgate-payment-gateway.php:544 craftgate-payment-gateway.php:557
msgid "Your payment could not be processed."
msgstr "Su pago no ha podido ser procesado."

#: craftgate-payment-gateway.php:600
msgid ""
"You can create your Craftgate Payment Gateway account <a href=\"https://"
"craftgate.io/\" target=\"_blank\"> here</a>."
msgstr ""
"Puede crear su cuenta de Craftgate Payment Gateway <a href=“https://"
"craftgate.io/“ target=“_blank”>aquí</a>."

#: craftgate-payment-gateway.php:604
msgid "Craftgate Payment Gateway is not available to use"
msgstr "Craftgate Payment Gateway no está disponible para su uso"

#: craftgate-payment-gateway.php:604
msgid "Currency is not supported."
msgstr "No se admiten divisas."

#: craftgate-payment-gateway.php:617
msgid "Enable/Disable"
msgstr "Activar/Desactivar"

#: craftgate-payment-gateway.php:619
msgid "Enable Craftgate"
msgstr "Activar Craftgate"

#: craftgate-payment-gateway.php:620
msgid "Enable or disable the gateway."
msgstr "Activa o desactiva la pasarela."

#: craftgate-payment-gateway.php:624
msgid "Title"
msgstr "Título"

#: craftgate-payment-gateway.php:626
msgid "This controls the title which the user sees during checkout."
msgstr "Esto controla el título que el usuario ve durante el pago."

#: craftgate-payment-gateway.php:631
msgid "Description"
msgstr "Descripción"

#: craftgate-payment-gateway.php:633
msgid "This controls the description which the user sees during checkout."
msgstr "Esto controla la descripción que el usuario ve durante el pago."

#: craftgate-payment-gateway.php:634
msgid "You can pay with Debit and Credit Card"
msgstr "Puede pagar con tarjeta de débito y crédito"

#: craftgate-payment-gateway.php:637
msgid "Live API Key"
msgstr "Clave API Live"

#: craftgate-payment-gateway.php:639
msgid "Enter your Live API Key."
msgstr "Introduzca su clave Live API."

#: craftgate-payment-gateway.php:643
msgid "Live Secret Key"
msgstr "Clave secreta en directo"

#: craftgate-payment-gateway.php:645
msgid "Enter your Live Secret Key."
msgstr "Introduzca su clave secreta Live."

#: craftgate-payment-gateway.php:649
msgid "Sandbox API Key"
msgstr "Clave API Sandbox"

#: craftgate-payment-gateway.php:651
msgid "Enter your Sandbox API Key."
msgstr "Introduzca su clave API del Sandbox."

#: craftgate-payment-gateway.php:655
msgid "Sandbox Secret Key"
msgstr "Clave secreta del Sandbox"

#: craftgate-payment-gateway.php:657
msgid "Enter your Sandbox Secret Key."
msgstr "Introduzca su Clave Secreta del Sandbox."

#: craftgate-payment-gateway.php:661
msgid "Sandbox Mode"
msgstr "Modo Sandbox"

#: craftgate-payment-gateway.php:663
msgid "Enable Sandbox Mode"
msgstr "Activar el modo Sandbox"

#: craftgate-payment-gateway.php:665
msgid "Enable test mode using sandbox API keys."
msgstr "Habilitar el modo de prueba utilizando claves API sandbox."

#: craftgate-payment-gateway.php:668
msgid "Language"
msgstr "Idioma"

#: craftgate-payment-gateway.php:671
msgid "Site Language"
msgstr "Idioma del sitio"

#: craftgate-payment-gateway.php:672
msgid "Turkish"
msgstr "Turco"

#: craftgate-payment-gateway.php:673
msgid "English"
msgstr "Inglés"

#: craftgate-payment-gateway.php:674
msgid "Spanish"
msgstr "Español"

#: craftgate-payment-gateway.php:676
msgid "Change the language of payment form."
msgstr "Cambiar el idioma del formulario de pago."

#: craftgate-payment-gateway.php:680
msgid "Iframe Options"
msgstr "Opciones de iframe"

#: craftgate-payment-gateway.php:682
msgid "Example: hideFooter=true&animatedCard=true"
msgstr "Ejemplo: hideFooter=true&animatedCard=true"

#: craftgate-payment-gateway.php:686
msgid "Webhook URL"
msgstr "URL del webhook"

#: craftgate-payment-gateway.php:690
msgid ""
"The URL that payment results will be sent to on the server-side. You should "
"enter this webhook address to Craftgate Merchant Panel to get webhook "
"request. You can see details <a href=\"https://developer.craftgate.io/"
"webhook\">here</a>."
msgstr ""
"The URL that payment results will be sent to on the server-side. You should "
"enter this webhook address to Craftgate Merchant Panel to get webhook "
"request. You can see details <a href=“https://developer.craftgate.io/"
"webhook”>here</a>."

#: craftgate-payment-gateway.php:766
msgid "Craftgate Payment URL"
msgstr "URL de pago Craftgate"

#: craftgate-payment-gateway.php:799
msgid "Settings"
msgstr "Ajustes"

#~ msgid "Gateway Testing"
#~ msgstr "Craftgate Test Modu"
Binary file modified languages/craftgate-payment-gateway-tr_TR.mo
Binary file not shown.
Loading

0 comments on commit 42bbe0d

Please sign in to comment.