From 14794cd2c9ac2aea9400b2558d6da11b7e05dec6 Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Thu, 31 Aug 2017 11:51:01 -0500 Subject: [PATCH 01/30] Update README.md --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 89dc2be..e19c6b1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ -# Culqi Prestashop 1.7 (v3.0.4) +# Culqi JS Prestashop 1.7 (v3.0.4) -![configuracion inicial](/docs/config.png) -* Es necesario indicar el campo telefono como requerido ya que por defecto no esta configurado.* -> Integración del formulario de Culqi - -![form](/docs/form.png) From 77deca3c71ddef7a827ea3c99661c221b32fb492 Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Thu, 31 Aug 2017 12:15:34 -0500 Subject: [PATCH 02/30] Update culqi.php --- culqi.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/culqi.php b/culqi.php index e6884bf..215db67 100644 --- a/culqi.php +++ b/culqi.php @@ -26,9 +26,9 @@ public function __construct() { $this->name = 'culqi'; $this->tab = 'payments_gateways'; - $this->version = '3.0.3'; + $this->version = '3.0.4'; $this->controllers = array('chargeajax','postpayment'); - $this->author = 'Team Culqi (Willy Aguirre, Brayan Cruces, Lizz Ruelas)'; + $this->author = 'Team Culqi (Willy Aguirre, Brayan Cruces, Liz Ruelas)'; $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->bootstrap = true; $this->display = 'view'; From b71aae2097ab895c10899827c7555197dcd6b3b5 Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Thu, 31 Aug 2017 13:43:37 -0500 Subject: [PATCH 03/30] update linea 55 --- views/templates/hook/payment.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 42fdc55..aa9a24b 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -52,7 +52,7 @@
- + From 004ed3f7f4f86276294dd58f13def71892351d93 Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Thu, 31 Aug 2017 16:43:15 -0500 Subject: [PATCH 04/30] Responsive --- views/templates/hook/payment.tpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index aa9a24b..5ec64d5 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -12,25 +12,25 @@
-
-
+
+
Correo Electronico
-
Numero Tarjeta
+
Número Tarjeta
-
+
Mes expiración
-
+
Año expiración
@@ -46,7 +46,7 @@

-
+

From fc951e88bc2b85ad595b952f95dc0ef3163044e5 Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Thu, 31 Aug 2017 16:44:28 -0500 Subject: [PATCH 05/30] Update culqi.php --- culqi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culqi.php b/culqi.php index 215db67..365e70b 100644 --- a/culqi.php +++ b/culqi.php @@ -148,7 +148,7 @@ public function hookPaymentOptions($params) ); $newOption->setModuleName($this->name) - ->setCallToActionText($this->trans('Pagar con Tarjeta de credito o debito', array(), 'culqi')) + ->setCallToActionText($this->trans('Pagar con Tarjeta', array(), 'culqi')) ->setAction($this->context->link->getModuleLink($this->name, 'postpayment', array(), true)) ->setAdditionalInformation($this->context->smarty->fetch('module:culqi/views/templates/hook/payment.tpl')) ->setLogo(Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/views/img/logo_cards.png'));; From 9ed772a4096ec2a17589209e34ad20442e33e0ef Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Tue, 5 Sep 2017 19:00:01 -0500 Subject: [PATCH 06/30] =?UTF-8?q?Integraci=C3=B3n=20de=20Modulo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e19c6b1..596f910 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,75 @@ -# Culqi JS Prestashop 1.7 (v3.0.4) +# Culqi JS - Prestashop 1.7 + +### Pasos para la Integración del Modulo de Culqi + +#### 1. Registrarse en Culqi `` : + +Asi podras tener acceso al ambiente de pruebas de Culqi `` : +donde encontraras tus llaves `` : + +`Llave publica: pk_test_xxxxxxxxxxxxxx` + +`Llave privada: sk_test_xxxxxxxxxxxxxx` + +#### 2. Descargar el Plugin de Culqi 3.0.4 + +`` : + +![Imgur](https://i.imgur.com/sWLEajr.png) + +#### 3. Subir el Modulo de Culqi en tu administrador de Prestashop 1.7 + +##### 3.1 +![Imgur](https://i.imgur.com/zcE8bUp.png) + +##### 3.2 +![Imgur](https://i.imgur.com/S0nIcXt.png) + +#### 4. Configurar el Modulo de Culqi en tu administrador de Prestashop 1.7 + +##### 4.1 +![Imgur](https://i.imgur.com/vdwhGv3.png) + +##### 4.2 +![Imgur](https://i.imgur.com/dTwx3Pw.png) +> Aqui van tus llaves que mencionabamos en el paso 1 ( Registrarse en Culqi ). + +### Finalmente debes tener a Culqi como pasarela de pago de esta manera: + +![Imgur](https://i.imgur.com/Zu66mdM.png) + +> Debes usar las tarjetas de prueba que Culqi te ofrece para hacer las pruebas necesarias + +`` : + +### Pase a producción: + +#### 1. Cumplir con los requisitos tecnicos + +`` : < https://culqi.com/docs/#/desarrollo/produccion/> + +#### 2. Activar comercio desde tu panel de integración de Culqi + +![Imgur](https://i.imgur.com/wVOz6cc.png) + +> Si tienes mas dudas con respecto al procesos de "Activación de comercio" escribenos a unete@culqi.com + +Cuando te envien los accesos a tu panel de producción de Culqi debes reemplazar +tus llaves de pruebas por tus llaves de producción como en el paso 4.2 + +`Llave publica: pk_live_xxxxxxxxxxxxxx` + +`Llave privada: sk_live_xxxxxxxxxxxxxx` + +> Donde podras comenzar a usar tarjetas reales. + + +### Si tienes dudas de Integración escribenos a integrate@culqi.com + +### Si tienes dudas comerciales escribenos a unete@culqi.com + + + + From 9b8646d03b02001f0bb955920a1d120efff2cd33 Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Wed, 20 Sep 2017 17:46:48 -0500 Subject: [PATCH 07/30] update_lizruelas --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 596f910..d106efc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Culqi JS - Prestashop 1.7 +# Culqi JS v2 - Prestashop 1.7 ### Pasos para la Integración del Modulo de Culqi From 4e5dad136a1c8d65789f6391869c9713c030067b Mon Sep 17 00:00:00 2001 From: Liz Ruelas Date: Thu, 21 Sep 2017 15:52:35 -0500 Subject: [PATCH 08/30] update_tildes_final --- README.md | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d106efc..649023c 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # Culqi JS v2 - Prestashop 1.7 -### Pasos para la Integración del Modulo de Culqi +### Pasos para la integración del Módulo de Culqi #### 1. Registrarse en Culqi `` : -Asi podras tener acceso al ambiente de pruebas de Culqi `` : -donde encontraras tus llaves `` : +Así podrás tener acceso al ambiente de pruebas de Culqi `` : +donde encontrarás tus llaves `` : `Llave publica: pk_test_xxxxxxxxxxxxxx` `Llave privada: sk_test_xxxxxxxxxxxxxx` -#### 2. Descargar el Plugin de Culqi 3.0.4 +#### 2. Descargar el Módulo de Culqi 3.0.4 `` : ![Imgur](https://i.imgur.com/sWLEajr.png) -#### 3. Subir el Modulo de Culqi en tu administrador de Prestashop 1.7 +#### 3. Subir el Módulo de Culqi en tu administrador de Prestashop 1.7 ##### 3.1 ![Imgur](https://i.imgur.com/zcE8bUp.png) @@ -25,14 +25,14 @@ donde encontraras tus llaves `` : Aqui van tus llaves que mencionabamos en el paso 1 ( Registrarse en Culqi ). +> Aquí van tus llaves que mencionamos en el paso 1 ( Registrarse en Culqi ). ### Finalmente debes tener a Culqi como pasarela de pago de esta manera: @@ -44,7 +44,7 @@ donde encontraras tus llaves `` : ` : < https://culqi.com/docs/#/desarrollo/produccion/> @@ -52,7 +52,7 @@ donde encontraras tus llaves `` : Si tienes mas dudas con respecto al procesos de "Activación de comercio" escribenos a unete@culqi.com +> Si tienes más dudas con respecto al proceso de "Activación de comercio" escríbenos a unete@culqi.com Cuando te envien los accesos a tu panel de producción de Culqi debes reemplazar tus llaves de pruebas por tus llaves de producción como en el paso 4.2 @@ -61,15 +61,9 @@ tus llaves de pruebas por tus llaves de producción como en el paso 4.2 `Llave privada: sk_live_xxxxxxxxxxxxxx` -> Donde podras comenzar a usar tarjetas reales. - - -### Si tienes dudas de Integración escribenos a integrate@culqi.com - -### Si tienes dudas comerciales escribenos a unete@culqi.com - - - +> En el ambiente de producción podrás comenzar a usar tarjetas reales. +### Si tienes dudas de Integración escríbenos a integrate@culqi.com +### Si tienes dudas comerciales escríbenos a unete@culqi.com From 2e29111da01f7d8d0049a9e303b5e6f48891a1d4 Mon Sep 17 00:00:00 2001 From: Nilton Date: Tue, 16 Jun 2020 20:44:05 -0500 Subject: [PATCH 09/30] avoid multiple charge --- views/templates/hook/payment.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 5ec64d5..b2a90fc 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -95,6 +95,8 @@ $(document).ready(function() { Culqi.init(); $('#payment-confirmation > .ps-shown-by-js > button').click(function(e) { + + $('#payment-confirmation > .ps-shown-by-js > button').prop("disabled",true); var myPaymentMethodSelected = $('.payment-options').find("input[data-module-name='culqi']").is(':checked'); if(myPaymentMethodSelected) { From 94c93de8a9cc151fb191b71d268b29badce0f26e Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 19 Jul 2020 20:58:00 -0500 Subject: [PATCH 10/30] Correcion de codigo --- controllers/front/chargeajax.php | 11 +- culqi-efectivo-example | 1 + culqi.php | 5 +- views/templates/hook/payment.tpl | 182 +++++++++++++++++++------------ 4 files changed, 127 insertions(+), 72 deletions(-) create mode 160000 culqi-efectivo-example diff --git a/controllers/front/chargeajax.php b/controllers/front/chargeajax.php index 4cb55b2..655b022 100644 --- a/controllers/front/chargeajax.php +++ b/controllers/front/chargeajax.php @@ -12,7 +12,16 @@ public function initContent() public function displayAjax() { $result = $this->module->charge(Tools::getValue("token_id"), Tools::getValue("installments")); - die(Tools::jsonEncode($result)); + //die(Tools::jsonEncode($result)); + + + + //header_remove(); + //header('Content-Type: application/json'); + echo json_encode($result); + exit(); + + } } diff --git a/culqi-efectivo-example b/culqi-efectivo-example new file mode 160000 index 0000000..cb029b9 --- /dev/null +++ b/culqi-efectivo-example @@ -0,0 +1 @@ +Subproject commit cb029b9a2f0b7130f756e12e49f5ae44dea70c1a diff --git a/culqi.php b/culqi.php index 365e70b..35eca37 100644 --- a/culqi.php +++ b/culqi.php @@ -111,7 +111,7 @@ public function charge($token_id, $installments) "country_code" => "PE", "first_name" => $this->context->customer->firstname, "last_name" => $this->context->customer->lastname, - "phone_number" => $this->getPhone($userAddress) + "phone_number" => $this->getPhone($userAddress) ?: 999999999, ), "capture" => true, "currency_code" => $this->context->currency->iso_code, @@ -149,7 +149,7 @@ public function hookPaymentOptions($params) $newOption->setModuleName($this->name) ->setCallToActionText($this->trans('Pagar con Tarjeta', array(), 'culqi')) - ->setAction($this->context->link->getModuleLink($this->name, 'postpayment', array(), true)) + //->setAction($this->context->link->getModuleLink($this->name, 'postpayment', array(), true)) ->setAdditionalInformation($this->context->smarty->fetch('module:culqi/views/templates/hook/payment.tpl')) ->setLogo(Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/views/img/logo_cards.png'));; @@ -183,6 +183,7 @@ public function getCulqiInfoCheckout(){ $cart = $this->context->cart; return array( "module_dir" => $this->_path, + 'id_cart' => $cart->id, "descripcion" => "Orden de compra ".$cart->id, "orden" => $cart->id, "total" => $cart->getOrderTotal(true, Cart::BOTH), diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 5ec64d5..231cc8d 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -1,64 +1,20 @@
- -
-
-
- -
-
Correo Electronico
- -
-
-
Número Tarjeta
- -
- -
-
-
-
Mes expiración
- -
-
-
Año expiración
- -
-
-
-
-
CVV
- -
- - -

- -

-
-
- -
-
+
+
+
+
- - + + {literal} {/literal} - - - From f778a0529358ba12e1ad7d03629ea8ac7d76a1c3 Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 19 Jul 2020 21:40:01 -0500 Subject: [PATCH 11/30] Adicicon de order CUlqi --- culqi-efectivo-example | 1 - culqi.php | 41 +++- .../culqi-php/examples/01-create-token.php | 31 +++ .../culqi-php/examples/02-create-charge.php | 31 +++ .../culqi-php/examples/03-create-plan.php | 32 +++ .../examples/04-create-subscription.php | 28 +++ .../culqi-php/examples/05-create-refund.php | 28 +++ .../culqi-php/examples/06-create-customer.php | 33 +++ .../culqi-php/examples/07-create-card.php | 27 +++ .../culqi-php/examples/08-create-order.php | 37 ++++ libraries/culqi-php/index.php | 1 - libraries/culqi-php/lib/Culqi/Cards.php | 110 +++++----- libraries/culqi-php/lib/Culqi/Charges.php | 119 +++++------ libraries/culqi-php/lib/Culqi/Client.php | 110 +++++----- libraries/culqi-php/lib/Culqi/Culqi.php | 107 +++++----- libraries/culqi-php/lib/Culqi/Customers.php | 110 +++++----- .../culqi-php/lib/Culqi/Error/Errors.php | 134 ++++++------- libraries/culqi-php/lib/Culqi/Error/index.php | 1 - libraries/culqi-php/lib/Culqi/Events.php | 64 +++--- libraries/culqi-php/lib/Culqi/Iins.php | 64 +++--- libraries/culqi-php/lib/Culqi/Lang/index.php | 1 - .../culqi-php/lib/Culqi/Lang/messages/en.php | 4 +- .../culqi-php/lib/Culqi/Lang/messages/es.php | 4 +- .../lib/Culqi/Lang/messages/index.php | 1 - libraries/culqi-php/lib/Culqi/Orders.php | 70 +++++++ libraries/culqi-php/lib/Culqi/Plans.php | 101 ++++++---- libraries/culqi-php/lib/Culqi/Refunds.php | 92 +++++---- libraries/culqi-php/lib/Culqi/Resource.php | 40 ++-- .../culqi-php/lib/Culqi/Subscriptions.php | 110 +++++----- libraries/culqi-php/lib/Culqi/Tokens.php | 92 +++++---- libraries/culqi-php/lib/Culqi/Transfers.php | 64 +++--- libraries/culqi-php/lib/Culqi/index.php | 1 - libraries/culqi-php/lib/culqi.php | 64 +++--- libraries/culqi-php/lib/index.php | 1 - libraries/culqi-php/tests/CaptureTest.php | 61 ++++++ libraries/culqi-php/tests/DeleteTest.php | 105 ++++++++++ libraries/culqi-php/tests/ListTest.php | 88 ++++++++ libraries/culqi-php/tests/Test.php | 189 ++++++++++++++++++ libraries/culqi-php/tests/TestAutoLoad.php | 4 + libraries/culqi-php/tests/TestPatch.php | 29 +++ views/templates/hook/payment.tpl | 6 +- 41 files changed, 1555 insertions(+), 681 deletions(-) delete mode 160000 culqi-efectivo-example create mode 100644 libraries/culqi-php/examples/01-create-token.php create mode 100644 libraries/culqi-php/examples/02-create-charge.php create mode 100644 libraries/culqi-php/examples/03-create-plan.php create mode 100644 libraries/culqi-php/examples/04-create-subscription.php create mode 100644 libraries/culqi-php/examples/05-create-refund.php create mode 100644 libraries/culqi-php/examples/06-create-customer.php create mode 100644 libraries/culqi-php/examples/07-create-card.php create mode 100644 libraries/culqi-php/examples/08-create-order.php delete mode 100644 libraries/culqi-php/index.php delete mode 100644 libraries/culqi-php/lib/Culqi/Error/index.php delete mode 100644 libraries/culqi-php/lib/Culqi/Lang/index.php delete mode 100644 libraries/culqi-php/lib/Culqi/Lang/messages/index.php create mode 100644 libraries/culqi-php/lib/Culqi/Orders.php delete mode 100644 libraries/culqi-php/lib/Culqi/index.php delete mode 100644 libraries/culqi-php/lib/index.php create mode 100644 libraries/culqi-php/tests/CaptureTest.php create mode 100644 libraries/culqi-php/tests/DeleteTest.php create mode 100644 libraries/culqi-php/tests/ListTest.php create mode 100644 libraries/culqi-php/tests/Test.php create mode 100644 libraries/culqi-php/tests/TestAutoLoad.php create mode 100644 libraries/culqi-php/tests/TestPatch.php diff --git a/culqi-efectivo-example b/culqi-efectivo-example deleted file mode 160000 index cb029b9..0000000 --- a/culqi-efectivo-example +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cb029b9a2f0b7130f756e12e49f5ae44dea70c1a diff --git a/culqi.php b/culqi.php index 35eca37..7677234 100644 --- a/culqi.php +++ b/culqi.php @@ -89,10 +89,40 @@ public function errorPayment($mensaje) $smarty->assign('culqi_error_pago', $mensaje); } + /* Se crea un Cargo con la nueva api v3 de Culqi PHP */ + public function orderCulqi() + { + try { + $cart = $this->context->cart; + $userAddress = new Address((int)$cart->id_address_invoice); + + $culqi = new Culqi\Culqi(array('api_key' => Configuration::get('CULQI_LLAVE_SECRETA'))); + $orderCulqi = $culqi->Orders->create( + array( + "amount" => $this->removeComma($cart->getOrderTotal(true, Cart::BOTH)), + "currency_code" => $this->context->currency->iso_code, + "description" => "Orden de compra ".$cart->id, + "order_number" => "#id-".rand(1,9999), + "client_details" => array( + "first_name" => $this->context->customer->firstname, + "last_name" => $this->context->customer->lastname, + "phone_number" => $this->getPhone($userAddress) ?: 999999999, + "email" => $this->context->customer->email, + ), + "expiration_date" => time() + 24*60*60, // Orden con un dia de validez + "confirm" => false + ) + ); + return $orderCulqi; + } catch(Exception $e){ + return $e->getMessage(); + } + + } + /* Se crea un Cargo con la nueva api v2 de Culqi PHP */ public function charge($token_id, $installments) { - try { $cart = $this->context->cart; @@ -180,12 +210,15 @@ public function checkCurrency($cart) } public function getCulqiInfoCheckout(){ - $cart = $this->context->cart; - return array( + $cart = $this->context->cart; + + $orderCulqi = $this->orderCulqi(); + + return array( "module_dir" => $this->_path, - 'id_cart' => $cart->id, "descripcion" => "Orden de compra ".$cart->id, "orden" => $cart->id, + 'order_culqi' => $orderCulqi, "total" => $cart->getOrderTotal(true, Cart::BOTH), "llave_publica" => Configuration::get('CULQI_LLAVE_PUBLICA'), "currency" => $this->context->currency->iso_code diff --git a/libraries/culqi-php/examples/01-create-token.php b/libraries/culqi-php/examples/01-create-token.php new file mode 100644 index 0000000..0b925d6 --- /dev/null +++ b/libraries/culqi-php/examples/01-create-token.php @@ -0,0 +1,31 @@ + $PUBLIC_KEY)); + + // Creando Cargo a una tarjeta + $token = $culqi->Tokens->create( + array( + "card_number" => "4111111111111111", + "cvv" => "123", + "email" => "wmuro".uniqid()."@me.com", //email must not repeated + "expiration_month" => 9, + "expiration_year" => 2020, + "fingerprint" => uniqid() + ) + ); + // Respuesta + echo json_encode("Token: ".$token->id); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/02-create-charge.php b/libraries/culqi-php/examples/02-create-charge.php new file mode 100644 index 0000000..af04e87 --- /dev/null +++ b/libraries/culqi-php/examples/02-create-charge.php @@ -0,0 +1,31 @@ + $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $charge = $culqi->Charges->create( + array( + "amount" => 1000, + "currency_code" => "PEN", + "email" => "test3122@culqi.com", + "source_id" => $_POST['token'] + ) + ); + // Respuesta + echo json_encode($charge); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/03-create-plan.php b/libraries/culqi-php/examples/03-create-plan.php new file mode 100644 index 0000000..c66d718 --- /dev/null +++ b/libraries/culqi-php/examples/03-create-plan.php @@ -0,0 +1,32 @@ + $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $plan = $culqi->Plans->create( + array( + "amount" => 10000, + "currency_code" => "PEN", + "interval" => "months", + "interval_count" => 1, + "limit" => 12, + "name" => "Plan de Prueba ".uniqid(), + "trial_days" => 15 + ) + ); + // Respuesta + echo json_encode($plan); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/04-create-subscription.php b/libraries/culqi-php/examples/04-create-subscription.php new file mode 100644 index 0000000..477da09 --- /dev/null +++ b/libraries/culqi-php/examples/04-create-subscription.php @@ -0,0 +1,28 @@ +| $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $subscription = $culqi->Subscriptions->create( + array( + "card_id"=> "{card_id}", + "plan_id" => "{plan_id}" + ) + ); + + // Respuesta + echo json_encode($subscription); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/05-create-refund.php b/libraries/culqi-php/examples/05-create-refund.php new file mode 100644 index 0000000..32cfed7 --- /dev/null +++ b/libraries/culqi-php/examples/05-create-refund.php @@ -0,0 +1,28 @@ + $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $refund = $culqi->Refunds->create( + array( + "amount" => 500, + "charge_id" => "{charge_id}", + "reason" => "bought an incorrect product" + ) + ); + // Respuesta + echo json_encode($refund); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/06-create-customer.php b/libraries/culqi-php/examples/06-create-customer.php new file mode 100644 index 0000000..29beb1e --- /dev/null +++ b/libraries/culqi-php/examples/06-create-customer.php @@ -0,0 +1,33 @@ + $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $customer = $culqi->Customers->create( + array( + "address" => "av lima 123", + "address_city" => "lima", + "country_code" => "PE", + "email" => "www@".uniqid()."me.com", + "first_name" => "Will", + "last_name" => "Muro", + "metadata" => array("test"=>"test"), + "phone_number" => 899898999 + ) + ); + // Respuesta + echo json_encode($customer); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/07-create-card.php b/libraries/culqi-php/examples/07-create-card.php new file mode 100644 index 0000000..8a19b89 --- /dev/null +++ b/libraries/culqi-php/examples/07-create-card.php @@ -0,0 +1,27 @@ + $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $card = $culqi->Cards->create( + array( + "customer_id" => "{customer_id}", + "token_id" => "{token_id}" + ) + ); + // Respuesta + echo json_encode($card); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/examples/08-create-order.php b/libraries/culqi-php/examples/08-create-order.php new file mode 100644 index 0000000..f1a9e2a --- /dev/null +++ b/libraries/culqi-php/examples/08-create-order.php @@ -0,0 +1,37 @@ + $SECRET_KEY)); + + // Creando Cargo a una tarjeta + $order = $culqi->Orders->create( + array( + "amount" => 1000, + "currency_code" => "PEN", + "description" => 'Venta de prueba', + "order_number" => 'pedido-9999', + "client_details" => array( + "first_name"=> "Brayan", + "last_name" => "Cruces", + "email" => "micorreo@gmail.com", + "phone_number" => "51945145222" + ), + "expiration_date" => time() + 24*60*60, // Orden con un dia de validez + "metadata" => array("dni" => "71702935") + ) + ); + // Respuesta + echo json_encode($order); + +} catch (Exception $e) { + echo json_encode($e->getMessage()); +} diff --git a/libraries/culqi-php/index.php b/libraries/culqi-php/index.php deleted file mode 100644 index 8142269..0000000 --- a/libraries/culqi-php/index.php +++ /dev/null @@ -1 +0,0 @@ -request("GET", self::URL_CARDS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Card response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_CARDS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return delete a Card response. - */ - public function delete($id = NULL) { - return $this->request("DELETE", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key); - } - - /** - * @param string|null $id - * - * @return get a Card. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_CARDS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Card response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_CARDS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return delete a Card response. + */ + public function delete($id = NULL) { + return $this->request("DELETE", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return get a Card. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Card response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Charges.php b/libraries/culqi-php/lib/Culqi/Charges.php index c5286ce..ba028e0 100644 --- a/libraries/culqi-php/lib/Culqi/Charges.php +++ b/libraries/culqi-php/lib/Culqi/Charges.php @@ -1,59 +1,60 @@ -request("GET", self::URL_CHARGES, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Charge response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_CHARGES, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Charge. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_CHARGES . $id . "/", $api_key = $this->culqi->api_key); - } - - /** - * @param string|null $id - * - * @return delete a Charge response. - */ - public function delete($id = NULL) { - return $this->request("DELETE", self::URL_CHARGES . $id . "/", $api_key = $this->culqi->api_key); - } - - /** - * @param string|null $id - * - * @return get a capture of Charge. - */ - public function getCapture($id = NULL) { - return $this->request("POST", self::URL_CHARGES . $id . "/capture/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_CHARGES, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Charge response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_CHARGES, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Charge. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_CHARGES . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return get a capture of Charge. + */ + public function capture($id = NULL) { + return $this->request("POST", self::URL_CHARGES . $id . "/capture/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Charge response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_CHARGES . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Client.php b/libraries/culqi-php/lib/Culqi/Client.php index 678882e..69095d2 100644 --- a/libraries/culqi-php/lib/Culqi/Client.php +++ b/libraries/culqi-php/lib/Culqi/Client.php @@ -1,59 +1,51 @@ - "Bearer ".$api_key, "Content-Type" => "application/json", "Accept" => "application/json"); - - $options = array( - 'timeout' => 120 - ); - - if($method == "GET") { - $url_params = is_array($data) ? '?' . http_build_query($data) : ''; - $response = \Requests::get(Culqi::BASE_URL. $url . $url_params, $headers, $options); - } else if($method == "POST") { - $response = \Requests::post(Culqi::BASE_URL . $url, $headers, json_encode($data), $options); - } else if($method == "PATCH") { - $response = \Requests::patch(Culqi::BASE_URL . $url, $headers, json_encode($data), $options); - } else if($method == "DELETE") { - $response = \Requests::delete(Culqi::BASE_URL, $options); - } - } catch (\Exception $e) { - throw new Errors\UnableToConnect(); - } - if ($response->status_code >= 200 && $response->status_code <= 206) { - if ($method == "DELETE") { - return $response->status_code == 204 || $response->status_code == 200; - } - return json_decode($response->body); - } - if ($response->status_code == 400) { - throw new Errors\UnhandledError($response->body, $response->status_code); - } - if ($response->status_code == 401) { - throw new Errors\AuthenticationError(); - } - if ($response->status_code == 404) { - throw new Errors\NotFound(); - } - if ($response->status_code == 403) { - throw new Errors\InvalidApiKey(); - } - if ($response->status_code == 405) { - throw new Errors\MethodNotAllowed(); - } - throw new Errors\UnhandledError($response->body, $response->status_code); - } -} + "Bearer ".$api_key, "Content-Type" => "application/json", "Accept" => "application/json"); + $options = array( + 'timeout' => 120 + ); + if($method == "GET") { + $response = \Requests::get(Culqi::BASE_URL. $url . $url_params, $headers, $options); + } else if($method == "POST") { + $response = \Requests::post(Culqi::BASE_URL . $url, $headers, json_encode($data), $options); + } else if($method == "PATCH") { + $response = \Requests::patch(Culqi::BASE_URL . $url, $headers, json_encode($data), $options); + } else if($method == "DELETE") { + $response = \Requests::delete(Culqi::BASE_URL. $url . $url_params, $headers, $options); + } + } catch (\Exception $e) { + throw new Errors\UnableToConnect(); + } + if ($response->status_code >= 200 && $response->status_code <= 206) { + return json_decode($response->body); + } + if ($response->status_code == 400) { + throw new Errors\UnhandledError($response->body, $response->status_code); + } + if ($response->status_code == 401) { + throw new Errors\AuthenticationError(); + } + if ($response->status_code == 404) { + throw new Errors\NotFound(); + } + if ($response->status_code == 403) { + throw new Errors\InvalidApiKey(); + } + if ($response->status_code == 405) { + throw new Errors\MethodNotAllowed(); + } + throw new Errors\UnhandledError($response->body, $response->status_code); + } +} diff --git a/libraries/culqi-php/lib/Culqi/Culqi.php b/libraries/culqi-php/lib/Culqi/Culqi.php index 9b60463..dd9449d 100644 --- a/libraries/culqi-php/lib/Culqi/Culqi.php +++ b/libraries/culqi-php/lib/Culqi/Culqi.php @@ -1,57 +1,50 @@ - "{api_key}") - * - */ - public function __construct($options) - { - $this->api_key = $options["api_key"]; - if (!$this->api_key) { - throw new Errors\InvalidApiKey(); - } - - $this->Tokens = new Tokens($this); - $this->Charges = new Charges($this); - $this->Subscriptions = new Subscriptions($this); - $this->Refunds = new Refunds($this); - $this->Plans = new Plans($this); - $this->Transfer = new Transfers($this); - $this->Iins = new Iins($this); - $this->Cards = new Cards($this); - $this->Events = new Events($this); - $this->Customers = new Customers($this); - - } - -} + "{api_key}") + * + */ + public function __construct($options) + { + $this->api_key = $options["api_key"]; + if (!$this->api_key) { + throw new Errors\InvalidApiKey(); + } + $this->Tokens = new Tokens($this); + $this->Charges = new Charges($this); + $this->Subscriptions = new Subscriptions($this); + $this->Refunds = new Refunds($this); + $this->Plans = new Plans($this); + $this->Transfers = new Transfers($this); + $this->Iins = new Iins($this); + $this->Cards = new Cards($this); + $this->Events = new Events($this); + $this->Customers = new Customers($this); + $this->Orders = new Orders($this); + } +} diff --git a/libraries/culqi-php/lib/Culqi/Customers.php b/libraries/culqi-php/lib/Culqi/Customers.php index 7653abb..846b445 100644 --- a/libraries/culqi-php/lib/Culqi/Customers.php +++ b/libraries/culqi-php/lib/Culqi/Customers.php @@ -1,50 +1,60 @@ -request("GET", self::URL_CUSTOMERS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Customer response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_CUSTOMERS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return delete a Customer response. - */ - public function delete($id = NULL) { - return $this->request("DELETE", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key); - } - - /** - * @param string|null $id - * - * @return get a Customer. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key, $options); - } - -} +request("GET", self::URL_CUSTOMERS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Customer response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_CUSTOMERS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return delete a Customer response. + */ + public function delete($id = NULL) { + return $this->request("DELETE", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return get a Customer. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Charge response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Error/Errors.php b/libraries/culqi-php/lib/Culqi/Error/Errors.php index 079d5ee..47372a3 100644 --- a/libraries/culqi-php/lib/Culqi/Error/Errors.php +++ b/libraries/culqi-php/lib/Culqi/Error/Errors.php @@ -1,67 +1,67 @@ -request("GET", self::URL_EVENTS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Event. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_EVENTS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_EVENTS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Event. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_EVENTS . $id . "/", $api_key = $this->culqi->api_key); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Iins.php b/libraries/culqi-php/lib/Culqi/Iins.php index 338a338..245a15a 100644 --- a/libraries/culqi-php/lib/Culqi/Iins.php +++ b/libraries/culqi-php/lib/Culqi/Iins.php @@ -1,32 +1,32 @@ -request("GET", self::URL_IINS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Iin. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_IINS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_IINS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Iin. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_IINS . $id . "/", $api_key = $this->culqi->api_key); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Lang/index.php b/libraries/culqi-php/lib/Culqi/Lang/index.php deleted file mode 100644 index 8142269..0000000 --- a/libraries/culqi-php/lib/Culqi/Lang/index.php +++ /dev/null @@ -1 +0,0 @@ -request("GET", self::URL_ORDERS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Order + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_ORDERS, $api_key = $this->culqi->api_key, $options); + } + + + /** + * @param array|null $options + * + * @return confirm Order + */ + public function confirm($id = NULL) { + return $this->request("POST", self::URL_ORDERS . $id . "/confirm/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return get a Order + */ + public function get($id) { + return $this->request("GET", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return delete a Order + */ + public function delete($id) { + return $this->request("DELETE", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Order + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Plans.php b/libraries/culqi-php/lib/Culqi/Plans.php index 93deff1..226f85a 100644 --- a/libraries/culqi-php/lib/Culqi/Plans.php +++ b/libraries/culqi-php/lib/Culqi/Plans.php @@ -1,41 +1,60 @@ -request("GET", self::URL_PLANS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Plan response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_PLANS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Plan. - */ - public function get($id) { - return $this->request("GET", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_PLANS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Plan response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_PLANS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Plan. + */ + public function get($id) { + return $this->request("GET", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return delete a Plan. + */ + public function delete($id) { + return $this->request("DELETE", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Plan response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Refunds.php b/libraries/culqi-php/lib/Culqi/Refunds.php index 40846e0..51b3ad2 100644 --- a/libraries/culqi-php/lib/Culqi/Refunds.php +++ b/libraries/culqi-php/lib/Culqi/Refunds.php @@ -1,41 +1,51 @@ -request("GET", self::URL_REFUNDS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Refund response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_REFUNDS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Refund. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_REFUNDS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_REFUNDS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Refund response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_REFUNDS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Refund. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_REFUNDS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Refund response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_REFUNDS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Resource.php b/libraries/culqi-php/lib/Culqi/Resource.php index 033479d..4be1fbc 100644 --- a/libraries/culqi-php/lib/Culqi/Resource.php +++ b/libraries/culqi-php/lib/Culqi/Resource.php @@ -1,20 +1,20 @@ -culqi = $culqi; - } - -} +culqi = $culqi; + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Subscriptions.php b/libraries/culqi-php/lib/Culqi/Subscriptions.php index 5311734..547e437 100644 --- a/libraries/culqi-php/lib/Culqi/Subscriptions.php +++ b/libraries/culqi-php/lib/Culqi/Subscriptions.php @@ -1,50 +1,60 @@ -request("GET", self::URL_SUBSCRIPTIONS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Subscription response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_SUBSCRIPTIONS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return delete a Subscription response. - */ - public function delete($id = NULL) { - return $this->request("DELETE", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key); - } - - /** - * @param string|null $id - * - * @return get a Subscription. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key, $options); - } - -} +request("GET", self::URL_SUBSCRIPTIONS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Subscription response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_SUBSCRIPTIONS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return delete a Subscription response. + */ + public function delete($id = NULL) { + return $this->request("DELETE", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * + * @return get a Subscription. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Subscription response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Tokens.php b/libraries/culqi-php/lib/Culqi/Tokens.php index 40f498c..0e738a8 100644 --- a/libraries/culqi-php/lib/Culqi/Tokens.php +++ b/libraries/culqi-php/lib/Culqi/Tokens.php @@ -1,41 +1,51 @@ -request("GET", self::URL_TOKENS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param array|null $options - * - * @return create Token response. - */ - public function create($options = NULL) { - return $this->request("POST", self::URL_TOKENS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Token. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_TOKENS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_TOKENS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param array|null $options + * + * @return create Token response. + */ + public function create($options = NULL) { + return $this->request("POST", self::URL_TOKENS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Token. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_TOKENS . $id . "/", $api_key = $this->culqi->api_key); + } + + /** + * @param string|null $id + * @param array|null $options + * + * @return update Token response. + */ + public function update($id = NULL, $options = NULL) { + return $this->request("PATCH", self::URL_TOKENS . $id . "/", $api_key = $this->culqi->api_key, $options); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/Transfers.php b/libraries/culqi-php/lib/Culqi/Transfers.php index b2641f4..253da74 100644 --- a/libraries/culqi-php/lib/Culqi/Transfers.php +++ b/libraries/culqi-php/lib/Culqi/Transfers.php @@ -1,32 +1,32 @@ -request("GET", self::URL_TRANSFERS, $api_key = $this->culqi->api_key, $options); - } - - /** - * @param string|null $id - * - * @return get a Transfers. - */ - public function get($id = NULL) { - return $this->request("GET", self::URL_TRANSFERS . $id . "/", $api_key = $this->culqi->api_key); - } - -} +request("GET", self::URL_TRANSFERS, $api_key = $this->culqi->api_key, $options); + } + + /** + * @param string|null $id + * + * @return get a Transfers. + */ + public function get($id = NULL) { + return $this->request("GET", self::URL_TRANSFERS . $id . "/", $api_key = $this->culqi->api_key); + } + +} diff --git a/libraries/culqi-php/lib/Culqi/index.php b/libraries/culqi-php/lib/Culqi/index.php deleted file mode 100644 index 8142269..0000000 --- a/libraries/culqi-php/lib/Culqi/index.php +++ /dev/null @@ -1 +0,0 @@ -PUBLIC_API_KEY = getenv("PUBLIC_API_KEY"); + $this->API_KEY = getenv("API_KEY"); + $this->culqi_token = new Culqi(array("api_key" => $this->PUBLIC_API_KEY )); + $this->culqi = new Culqi(array("api_key" => $this->API_KEY )); + } + + protected function createToken() { + $token = $this->culqi_token->Tokens->create( + array( + "card_number" => "4111111111111111", + "cvv" => "123", + "email" => "wmuro".uniqid()."@me.com", + "expiration_month" => 9, + "expiration_year" => 2020, + "fingerprint" => "q352454534" + ) + ); + return $token; + } + + public function testVerifyToken() { + $this->assertEquals('token', $this->createToken()->object); + } + + public function createCharge() { + $charge = $this->culqi->Charges->create( + array( + "amount" => 1000, + "capture" => false, + "currency_code" => "PEN", + "description" => "Venta de prueba", + "email" => "test@culqi.com", + "installments" => 0, + "source_id" => $this->createToken()->id + ) + ); + return $charge; + } + + public function testCreateCharge() { + $this->assertEquals('charge', $this->createCharge()->object); + } + + public function testCaptureCharge() { + $captureCharge = $this->culqi->Charges->capture($this->createCharge()->id); + $this->assertEquals('charge', $captureCharge->object); + } + +} \ No newline at end of file diff --git a/libraries/culqi-php/tests/DeleteTest.php b/libraries/culqi-php/tests/DeleteTest.php new file mode 100644 index 0000000..8c45311 --- /dev/null +++ b/libraries/culqi-php/tests/DeleteTest.php @@ -0,0 +1,105 @@ +PUBLIC_API_KEY = getenv("PUBLIC_API_KEY"); + $this->API_KEY = getenv("API_KEY"); + $this->culqi_token = new Culqi(array("api_key" => $this->PUBLIC_API_KEY )); + $this->culqi = new Culqi(array("api_key" => $this->API_KEY )); + } + + protected function createToken() { + $token = $this->culqi_token->Tokens->create( + array( + "card_number" => "4111111111111111", + "cvv" => "123", + "email" => "wmuro".uniqid()."@me.com", + "expiration_month" => 9, + "expiration_year" => 2020, + "fingerprint" => "q352454534" + ) + ); + return $token; + } + + public function createCustomer() { + $customer = $this->culqi->Customers->create( + array( + "address" => "av lima 123", + "address_city" => "lima", + "country_code" => "PE", + "email" => "www@".uniqid()."me.com", + "first_name" => "Will", + "last_name" => "Muro", + "metadata" => array("test"=>"test"), + "phone_number" => 899898999 + ) + ); + return $customer; + } + + public function createCard() { + $card = $this->culqi->Cards->create( + array( + "customer_id" => $this->createCustomer()->id, + "token_id" => $this->createToken()->id + ) + ); + return $card; + } + + public function createPlan() { + $plan = $this->culqi->Plans->create( + array( + "amount" => 10000, + "currency_code" => "PEN", + "interval" => "dias", + "interval_count" => 1, + "limit" => 12, + "name" => "plan-culqi".uniqid(), + "trial_days" => 15 + ) + ); + return $plan; + } + + public function createSubscription() { + $subscription = $this->culqi->Subscriptions->create( + array( + "card_id" => $this->createCard()->id, + "plan_id" => $this->createPlan()->id + ) + ); + return $subscription; + } + + public function testDeleteSubscription() { + $subscriptionDeleted = $this->culqi->Subscriptions->delete($this->createSubscription()->id); + $this->assertTrue($subscriptionDeleted->deleted); + } + + public function testDeletePlan() { + $planDeleted = $this->culqi->Plans->delete($this->createPlan()->id); + $this->assertTrue($planDeleted->deleted); + } + + public function testDeleteCard() { + $cardDeleted = $this->culqi->Cards->delete($this->createCard()->id); + $this->assertTrue($cardDeleted->deleted); + } + + public function testDeleteCustomer() { + $customerDeleted = $this->culqi->Customers->delete($this->createCustomer()->id); + $this->assertTrue($customerDeleted->deleted); + } + +} \ No newline at end of file diff --git a/libraries/culqi-php/tests/ListTest.php b/libraries/culqi-php/tests/ListTest.php new file mode 100644 index 0000000..6b1414d --- /dev/null +++ b/libraries/culqi-php/tests/ListTest.php @@ -0,0 +1,88 @@ +API_KEY = getenv("API_KEY"); + $this->culqi = new Culqi(array("api_key" => $this->API_KEY )); + } + + public function testListTokens() { + $tokens = $this->culqi->Tokens->all(array("limit" => 50)); + $valid = false; + if(count($tokens->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListCharges() { + $charges = $this->culqi->Charges->all(array("min_amount" => 1000, "max_amount" => 1000000, "limit" => 50)); + $valid = false; + if(count($charges->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListPlans() { + $plans = $this->culqi->Plans->all(array("limit" => 50)); + $valid = false; + if(count($plans->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListCustomers() { + $customers = $this->culqi->Customers->all(array("limit" => 50)); + $valid = false; + if(count($customers->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListCards() { + $cards = $this->culqi->Cards->all(array("limit" => 50)); + $valid = false; + if(count($cards->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListSubscriptions() { + $subscriptions = $this->culqi->Subscriptions->all(array("limit" => 50)); + $valid = false; + if(count($subscriptions->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListRefunds() { + $refunds = $this->culqi->Refunds->all(array("limit" => 50)); + $valid = false; + if(count($refunds->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + + public function testListTransfers() { + $transfers = $this->culqi->Transfers->all(array("limit" => 50)); + $valid = false; + if(count($transfers->data) >= 0) { + $valid = true; + } + $this->assertTrue($valid); + } + +} \ No newline at end of file diff --git a/libraries/culqi-php/tests/Test.php b/libraries/culqi-php/tests/Test.php new file mode 100644 index 0000000..e3e1084 --- /dev/null +++ b/libraries/culqi-php/tests/Test.php @@ -0,0 +1,189 @@ +PUBLIC_API_KEY = getenv("PUBLIC_API_KEY"); + $this->API_KEY = getenv("API_KEY"); + $this->culqi_token = new Culqi(array("api_key" => $this->PUBLIC_API_KEY )); + $this->culqi = new Culqi(array("api_key" => $this->API_KEY )); + } + + public function testValidIins() { + $iin = $this->culqi_token->Iins->get("411111"); + $this->assertEquals('iin', $iin->object); + } + + /** + * Creación de un token con los datos de una tarjeta de prueba + */ + protected function createToken() { + $token = $this->culqi_token->Tokens->create( + array( + "card_number" => "4111111111111111", + "cvv" => "123", + "email" => "wmuro".uniqid()."@me.com", + "expiration_month" => 9, + "expiration_year" => 2020, + "fingerprint" => "q352454534" + ) + ); + return $token; + } + + /** + * Verificar creación de Token + */ + public function testVerifyToken() { + $this->assertEquals('token', $this->createToken()->object); + } + + public function testFindToken() { + $token = $this->culqi->Tokens->get($this->createToken()->id); + $this->assertEquals('token', $token->object); + } + + public function createCharge() { + $charge = $this->culqi->Charges->create( + array( + "amount" => 1000, + "capture" => true, + "currency_code" => "PEN", + "description" => "Venta de prueba", + "email" => "test@culqi.com", + "installments" => 0, + "source_id" => $this->createToken()->id + ) + ); + return $charge; + } + + public function testCreateCharge() { + // Verificacion del campo object no tenga el valor 'error' + $this->assertEquals('charge', $this->createCharge()->object); + } + + public function testFindCharge() { + $charge = $this->culqi->Charges->get($this->createCharge()->id); + $this->assertEquals('charge', $charge->object); + } + + public function createPlan() { + $plan = $this->culqi->Plans->create( + array( + "amount" => 10000, + "currency_code" => "PEN", + "interval" => "dias", + "interval_count" => 1, + "limit" => 12, + "name" => "plan-culqi".uniqid(), + "trial_days" => 15 + ) + ); + return $plan; + } + + public function testCreatePlan() { + // Verificacion del campo object no tenga el valor 'error' + $this->assertEquals('plan', $this->createPlan()->object); + } + + public function testFindPlan() { + $plan = $this->culqi->Plans->get($this->createPlan()->id); + $this->assertEquals('plan', $plan->object); + } + + public function createCustomer() { + $customer = $this->culqi->Customers->create( + array( + "address" => "av lima 123", + "address_city" => "lima", + "country_code" => "PE", + "email" => "www@".uniqid()."me.com", + "first_name" => "Will", + "last_name" => "Muro", + "metadata" => array("test"=>"test"), + "phone_number" => 899898999 + ) + ); + return $customer; + } + + public function testCreateCustomer() { + $this->assertEquals('customer', $this->createCustomer()->object); + } + + public function testFindCustomer() { + $customer = $this->culqi->Customers->get($this->createCustomer()->id); + $this->assertEquals('customer', $customer->object); + } + + public function createCard() { + $card = $this->culqi->Cards->create( + array( + "customer_id" => $this->createCustomer()->id, + "token_id" => $this->createToken()->id + ) + ); + return $card; + } + + public function testCreateCard() { + $this->assertEquals('card', $this->createCard()->object); + } + + public function testFindCard() { + $card = $this->culqi->Cards->get($this->createCard()->id); + $this->assertEquals('card', $card->object); + } + + public function createSubscription() { + $subscription = $this->culqi->Subscriptions->create( + array( + "card_id" => $this->createCard()->id, + "plan_id" => $this->createPlan()->id + ) + ); + return $subscription; + } + + public function testCreateSubscription() { + $this->assertEquals('subscription',$this->createSubscription()->object); + } + + public function testFindSubscription() { + $subscription = $this->culqi->Subscriptions->get($this->createSubscription()->id); + $this->assertEquals('subscription', $subscription->object); + } + + public function createRefund() { + $refund = $this->culqi->Refunds->create( + array( + "amount" => 500, + "charge_id" => $this->createCharge()->id, + "reason" => "solicitud_comprador" + ) + ); + return $refund; + } + + public function testCreateRefund() { + $this->assertEquals('refund',$this->createRefund()->object); + } + + public function testFindRefund() { + $refund = $this->culqi->Refunds->get($this->createRefund()->id); + $this->assertEquals('refund',$refund->object); + } + +} diff --git a/libraries/culqi-php/tests/TestAutoLoad.php b/libraries/culqi-php/tests/TestAutoLoad.php new file mode 100644 index 0000000..3f17ec1 --- /dev/null +++ b/libraries/culqi-php/tests/TestAutoLoad.php @@ -0,0 +1,4 @@ +API_KEY = getenv("API_KEY"); + $this->culqi = new Culqi(array("api_key" => $this->API_KEY )); + } + + public function testUpdatePlan() { + $plan = $this->culqi->Plans->update("pln_test_pLFzcWkwj33xFGF1", + array( + "metadata" => array( + "test" => "test555" + ) + ) + ); + $this->assertEquals('plan', $plan->object); + } +} diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 231cc8d..b8b5f43 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -68,7 +68,7 @@ $(document).ready(function() { currency: 'PEN', description: 'Descripcion tienda', amount: 700, - order: 'ord_test_sm6aEl0TRRHmCXBP' + order: '{/literal}{$order_culqi->id}{literal}' }); @@ -106,12 +106,12 @@ $(document).ready(function() { //run_waitMe(); }); - var installments = (Culqi.token.metadata.installments == undefined) ? 0 : Culqi.token.metadata.installments; + var installments = (Culqi.token.metadata.installments === undefined) ? 0 : Culqi.token.metadata.installments; $.ajax({ type: 'POST', url: fnReplace("{/literal}{$link->getModuleLink('culqi', 'chargeajax', [], true)|escape:'htmlall':'UTF-8'}{literal}"), data: { - //token: Culqi.token.id, + token: Culqi.token.id, //cuotas: Culqi.token.metadata.installments ajax: true, action: 'displayAjax', From 3941f3bcbc1e6dbb105195aacde1dd750baa8832 Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 19 Jul 2020 22:15:18 -0500 Subject: [PATCH 12/30] Correcion de reload --- culqi-efectivo-example | 1 + views/templates/hook/payment.tpl | 123 +++---------------------------- 2 files changed, 13 insertions(+), 111 deletions(-) create mode 160000 culqi-efectivo-example diff --git a/culqi-efectivo-example b/culqi-efectivo-example new file mode 160000 index 0000000..cb029b9 --- /dev/null +++ b/culqi-efectivo-example @@ -0,0 +1 @@ +Subproject commit cb029b9a2f0b7130f756e12e49f5ae44dea70c1a diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index b8b5f43..fcb5146 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -14,39 +14,15 @@ {literal} - {literal} - {/literal} From 8828011f5e178eb42a2e3c438525a9c7d3dceb8a Mon Sep 17 00:00:00 2001 From: "victor.castro.contreras" Date: Sun, 2 Aug 2020 18:50:47 -0500 Subject: [PATCH 21/30] Validando respose de cylwi --- controllers/front/orderStatusChanged.php | 11 ++++++----- culqi.php | 5 ++--- views/templates/hook/payment.tpl | 19 +++++++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/controllers/front/orderStatusChanged.php b/controllers/front/orderStatusChanged.php index 35fc180..08951ac 100644 --- a/controllers/front/orderStatusChanged.php +++ b/controllers/front/orderStatusChanged.php @@ -19,17 +19,18 @@ public function postProcess() die; */ + // $input = file_get_contents("php://input"); $input = '{"object":"event","id":"evt_live_Tf1WJVWcSHF9R3HA","type":"order.status.changed","creation_date":1596248428134,"data":"{\"object\":\"order\",\"id\":\"ord_live_BfjQayoI9DhEwUBG\",\"amount\":1320,\"payment_code\":\"36338442\",\"currency_code\":\"PEN\",\"description\":\"Orden de compra 416\",\"order_number\":\"#id-2570\",\"state\":\"paid\",\"total_fee\":null,\"net_amount\":null,\"fee_details\":null,\"creation_date\":1596247975,\"expiration_date\":1596334374,\"updated_at\":null,\"paid_at\":null,\"available_on\":null,\"metadata\":{}}"}'; $event_json = json_decode($input, true); $data = json_decode($event_json['data'], true); - print_r($data); die; + $idCart = substr($data['description'], 16); + $cart = new Cart($idCart); + $customer = new Customer($cart->id_customer); $ps_os_payment = $data['state'] == "paid" ? Configuration::get('CULQI_STATE_OK') : Configuration::get('CULQI_STATE_ERROR'); + $module_name = $this->module->displayName; - $na = $this->module->displayName; - $key = $customer->secure_key; - - $this->module->validateOrder($cart->id, $ps_os_payment, $total, $na, null, null, $currency->id, false, $key); + // $this->module->validateOrder((int)$cart->id, $ps_os_payment, (float)$cart->getordertotal(true), $module_name, null, null, (int)$cart->id_currency, false, $customer->secure_key); } } \ No newline at end of file diff --git a/culqi.php b/culqi.php index 2c149c8..c0658a5 100644 --- a/culqi.php +++ b/culqi.php @@ -181,7 +181,7 @@ public function charge($token_id, $installments) "currency_code" => $this->context->currency->iso_code, "description" => "Orden de compra ".$cart->id, "installments" => $installments, - "metadata" => array("order_id"=>(string)$cart->id), + "metadata" => ["cart_id" => (string)$cart->id ], "email" => $this->context->customer->email, "source_id" => $token_id ) @@ -252,7 +252,6 @@ public function checkCurrency($cart) public function getCulqiInfoCheckout(){ $cart = $this->context->cart; - $currency = $this->context->currency; $link = new Link; $orderCulqi = $this->orderCulqi(); @@ -265,7 +264,7 @@ public function getCulqiInfoCheckout(){ "descripcion" => "Orden de compra ".$cart->id, "orden" => $cart->id, 'order_culqi' => $orderCulqi, - "total" => $cart->getOrderTotal(true, Cart::BOTH), + "total" => $this->removeComma($cart->getOrderTotal(true, Cart::BOTH)), "llave_publica" => Configuration::get('CULQI_LLAVE_PUBLICA'), "currency" => $this->context->currency->iso_code ); diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 0d818fb..9ad6a38 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -13,10 +13,14 @@ {literal} @@ -24,7 +28,7 @@ $(document).ready(function() { } Culqi = new culqijs.Checkout(); - Culqi.publicKey = '{/literal}{$llave_publica|escape:'htmlall':'UTF-8'}{literal}'; + Culqi.publicKey = $('#clq_key').val(); Culqi.options({ lang: 'auto', modal: true, @@ -36,7 +40,7 @@ $(document).ready(function() { buttontext: '#ffffff', maintext: '#4A4A4A', desctext: '#4A4A4A', - logo: '{/literal}http://{$logo}{literal}' + logo: $('#clq_logo').val() } }) Culqi.settings({ @@ -65,9 +69,10 @@ $(document).ready(function() { // ORDER es pagoefectivo if (Culqi.token) { var installments = (Culqi.token.metadata.installments === undefined) ? 0 : Culqi.token.metadata.installments; + console.log(Culqi.token) $.ajax({ type: 'POST', - url: fnReplace("{/literal}{$link->getModuleLink('culqi', 'chargeajax', [], true)|escape:'htmlall':'UTF-8'}{literal}"), + url: $('#clq_chargeajax').val(), data: { ajax: true, action: 'displayAjax', @@ -79,7 +84,7 @@ $(document).ready(function() { var result; if (data === "Imposible conectar a Culqi API") { - showResult('red', data + ": aumentar el timeout de la consulta"); + showResult('red', data + ": aumentar el timeout de la consulta"); } else if (data === "Error de autenticación") { showResult('red',data + ": verificar si su Llave Secreta es la correcta"); } else { @@ -97,18 +102,9 @@ $(document).ready(function() { switch (result.object) { case 'charge': localStorage.setItem('culqi_message', ''); - console.log('charge success, REDIRECT!!') - // redirect(); + validation('charge', result.outcome.code); break; - /* - case 'order': - localStorage.setItem('culqi_message', ''); - console.log('charge success, REDIRECT!!') - // redirect(); - break; - */ - case 'error': showResult('red', result.user_message); location.reload(); @@ -116,7 +112,7 @@ $(document).ready(function() { default: showResult('black', result.user_message); - Culqi.close(); + // Culqi.close(); break; } } @@ -126,8 +122,8 @@ $(document).ready(function() { } }); } else if (Culqi.order) { - showResult('green', Culqi.order); - alert('Se ha elegido el metodo de pago en efectivo:' + Culqi.order); + alert('Se ha elegido el metodo de pago en efectivo:' + Culqi.order.payment_code); + validation('order', Culqi.order.payment_code) console.log(Culqi.order) } else if (Culqi.closeEvent){ @@ -145,9 +141,9 @@ $(document).ready(function() { $('.showresultcontent').attr('class', '').addClass(style).html(message); } - function redirect() { - var url = fnReplace("{/literal}{$link->getModuleLink('culqi', 'postpayment', [], true)|escape:'htmlall':'UTF-8'}{literal}"); - location.href = url; + function validation(type, code) { + const urlValidation = $('#clq_validation').val() + location.href = urlValidation.replace('CLQ_TYPE', type).replace('CLQ_CODE', code); } function fnReplace(url) { From 688f16bbc05e0f0903d38aca8d3771f2ac490819 Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 9 Aug 2020 13:06:14 -0500 Subject: [PATCH 24/30] Correcion de gitignore --- .gitignore | 3 ++- views/templates/hook/payment.tpl | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1f1025f..7445bba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -.DS_Store \ No newline at end of file +.DS_Store +logs/* diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index ca5d1ae..4453594 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -122,7 +122,6 @@ $(document).ready(function() { } }); } else if (Culqi.order) { - alert('Se ha elegido el metodo de pago en efectivo:' + Culqi.order.payment_code); validation('order', Culqi.order.payment_code) console.log(Culqi.order) } From ae14c2196b921a3d9f0f23e1d9796618c99ac0ac Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 9 Aug 2020 21:55:59 -0500 Subject: [PATCH 25/30] Implementacion de PaymentReturn --- config.xml | 13 +++++++ controllers/front/postpayment.php | 19 --------- controllers/front/validation.php | 5 ++- culqi.php | 56 +++++++++++++++++++++++++++ views/js/confirmation.js | 10 +++++ views/js/waitMe.min.js | 12 ------ views/templates/hook/confirmation.tpl | 30 ++++++++++++++ 7 files changed, 113 insertions(+), 32 deletions(-) create mode 100644 config.xml delete mode 100644 controllers/front/postpayment.php create mode 100644 views/js/confirmation.js delete mode 100644 views/js/waitMe.min.js create mode 100644 views/templates/hook/confirmation.tpl diff --git a/config.xml b/config.xml new file mode 100644 index 0000000..30e6d00 --- /dev/null +++ b/config.xml @@ -0,0 +1,13 @@ + + + culqi + + + + + + + 1 + 1 + + \ No newline at end of file diff --git a/controllers/front/postpayment.php b/controllers/front/postpayment.php deleted file mode 100644 index a4e7d9c..0000000 --- a/controllers/front/postpayment.php +++ /dev/null @@ -1,19 +0,0 @@ -ajax = false; - - $cart = $this->context->cart; - - $customer = new Customer($cart->id_customer); - $this->module->validateOrder((int)$cart->id, Configuration::get('CULQI_STATE_OK'), (float)$cart->getordertotal(true), 'Culqi', null, array(), (int)$cart->id_currency, false, $customer->secure_key); - Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int)$cart->id . '&id_module=' . (int)$this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key); - - } - -} diff --git a/controllers/front/validation.php b/controllers/front/validation.php index a618012..3efd739 100644 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -15,19 +15,22 @@ public function initContent() switch ($type) { case 'charge': $ps_os_payment = $code == "AUT0000" ? Configuration::get('CULQI_STATE_OK') : Configuration::get('CULQI_STATE_ERROR'); + $cip = ''; break; case 'order': $ps_os_payment = $code != "" ? Configuration::get('CULQI_STATE_PENDING') : Configuration::get('CULQI_STATE_ERROR'); + $cip = $code; break; default: $ps_os_payment = Configuration::get('CULQI_STATE_ERROR'); + $cip = ''; } $this->module->validateOrder((int)$cart->id, $ps_os_payment, (float)$cart->getordertotal(true), 'Culqi', null, array(), (int)$cart->id_currency, false, $customer->secure_key); - Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int)$cart->id . '&id_module=' . (int)$this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key); + Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key.'&cip='.$cip); } } diff --git a/culqi.php b/culqi.php index 88ca72b..2563f69 100644 --- a/culqi.php +++ b/culqi.php @@ -64,6 +64,7 @@ public function install() return ( parent::install() && $this->registerHook('paymentOptions') && + $this->registerHook('paymentReturn') && Configuration::updateValue('CULQI_LLAVE_SECRETA', '') && Configuration::updateValue('CULQI_LLAVE_PUBLICA', '') && Configuration::updateValue('CULQI_WEBHOOK_ORDER_STATUS_CHANGED', $this->url_return) @@ -231,6 +232,60 @@ public function hookPaymentOptions($params) return $payment_options; } + public function hookPaymentReturn($params) + { + if (!$this->active) { + return; + } + + $currentState = $params['order']->getCurrentState(); + + $in_array = in_array( + $currentState, + array( + Configuration::get('CULQI_STATE_OK'), + Configuration::get('CULQI_STATE_PENDING'), + Configuration::get('CULQI_STATE_ERROR') + ) + ); + + switch ($currentState) { + case Configuration::get('CULQI_STATE_OK'): + $paymentState['code'] = 'OKS'; + $paymentState['icon'] = 'done_all'; + $paymentState['cip'] = ''; + $paymentState['description'] = 'Pago registrado correctamente'; + break; + + case Configuration::get('CULQI_STATE_PENDING'): + $paymentState['code'] = 'PND'; + $paymentState['icon'] = 'hourglass_empty'; + $paymentState['cip'] = Tools::getValue('cip'); + $paymentState['description'] = 'Pendiente de pago'; + break; + + default: + $paymentState['code'] = 'ERR'; + $paymentState['icon'] = 'error'; + $paymentState['cip'] = ''; + $paymentState['description'] = 'Error de pago'; + break; + } + + if ($in_array) { + $this->smarty->assign([ + 'status' =>'ok', + 'paymentState' => $paymentState, + ]); + } else { + $this->smarty->assign('status', 'failed'); + } + + $this->context->controller->addJS([$this->_path . 'views/js/confirmation.js']); + + return $this->display(__FILE__, 'confirmation.tpl'); + } + public function checkCurrency($cart) { $currency_order = new Currency((int)($cart->id_currency)); @@ -259,6 +314,7 @@ public function getCulqiInfoCheckout(){ 'logo' => $this->domain.'img/'.Configuration::get('PS_LOGO'), "descripcion" => "Orden de compra ".$cart->id, "orden" => $cart->id, + "orden" => $cart->id, 'order_culqi' => $orderCulqi, "total" => $this->removeComma($cart->getOrderTotal(true, Cart::BOTH)), "llave_publica" => Configuration::get('CULQI_LLAVE_PUBLICA'), diff --git a/views/js/confirmation.js b/views/js/confirmation.js new file mode 100644 index 0000000..9c0541d --- /dev/null +++ b/views/js/confirmation.js @@ -0,0 +1,10 @@ +const stateDescription = $('#stateDescription').val() +const stateIcon = $('#stateIcon').val() +const CIP = $('#stateCIP').val() +let msg_cip = ''; + +if (CIP && CIP !== '') { + msg_cip = ' - CIP: ' + CIP +} + +$('.h1.card-title').html(''+ stateIcon +'' + stateDescription + msg_cip) diff --git a/views/js/waitMe.min.js b/views/js/waitMe.min.js deleted file mode 100644 index 69f1956..0000000 --- a/views/js/waitMe.min.js +++ /dev/null @@ -1,12 +0,0 @@ -/* -waitMe - 1.18 [23.09.16] -Author: vadimsva -Github: https://github.com/vadimsva/waitMe -*/ -(function(b){b.fn.waitMe=function(p){return this.each(function(){var f=b(this),x,g,e,r=!1,t="background-color",u="",q="",v,a,w,l={init:function(){function y(a){m.css({top:"auto",transform:"translateY("+a+"px) translateZ(0)"})}a=b.extend({effect:"bounce",text:"",bg:"rgba(255,255,255,0.7)",color:"#000",maxSize:"",textPos:"vertical",fontSize:"",source:"",onClose:function(){}},p);w=(new Date).getMilliseconds();v=b('
');switch(a.effect){case "none":e=0;break; -case "bounce":e=3;break;case "rotateplane":e=1;break;case "stretch":e=5;break;case "orbit":e=2;r=!0;break;case "roundBounce":e=12;break;case "win8":e=5;r=!0;break;case "win8_linear":e=5;r=!0;break;case "ios":e=12;break;case "facebook":e=3;break;case "rotation":e=1;t="border-color";break;case "timer":e=2;var c=b.isArray(a.color)?a.color[0]:a.color;u="border-color:"+c;break;case "pulse":e=1;t="border-color";break;case "progressBar":e=1;break;case "bouncePulse":e=3;break;case "img":e=1}""!==u&&(u+=";"); -if(0';else for(var d=1;d<=e;++d)b.isArray(a.color)?(c=a.color[d],void 0==c&&(c="#000")):c=a.color,q=r?q+('
'):q+('
');g=b('
'+q+"
")}a.text&&(c=b.isArray(a.color)?a.color[0]:a.color,x=b('
'+a.text+"
"));var k=f.find("> .waitMe");k&&k.remove();c=b('
');c.append(g,x);v.append(c);"HTML"==f[0].tagName&&(f=b("body"));f.addClass("waitMe_container").attr("data-waitme_id",w).append(v);var k=f.find("> .waitMe"),m=f.find(".waitMe_content");k.css({background:a.bg});""!==a.maxSize&&"none"!=a.effect&&(c=g.outerHeight(),g.outerWidth(),"img"===a.effect?(g.css({height:a.maxSize+"px"}),g.find(">img").css({maxHeight:"100%"}),m.css({marginTop:-m.outerHeight()/ -2+"px"})):a.maxSize div").css({margin:"0 5%"})):(c=a.maxSize/c-.2,d="-50%","roundBounce"==a.effect?d="-75%":"win8"==a.effect||"timer"==a.effect||"orbit"==a.effect?d="-20%":"ios"==a.effect&&(d="-15%"),g.css({transform:"scale("+c+") translateX("+d+")",whiteSpace:"nowrap"}))));m.css({marginTop:-m.outerHeight()/2+"px"});if(f.outerHeight()>b(window).height()){var c=b(window).scrollTop(),h=m.outerHeight(),n=f.offset().top, -l=f.outerHeight(),d=c-n+b(window).height()/2;0>d&&(d=Math.abs(d));0<=d-h&&d+h<=l?n-c>b(window).height()/2&&(d=h):d=c>n+l-h?c-n-h:c-n+h;y(d);b(document).scroll(function(){var a=b(window).scrollTop()-n+b(window).height()/2;0<=a-h&&a+h<=l&&y(a)})}k.on("destroyed",function(){if(a.onClose&&b.isFunction(a.onClose))a.onClose();k.trigger("close")});b.event.special.destroyed={remove:function(a){a.handler&&a.handler()}};return k},hide:function(){var a=f.attr("data-waitme_id");f.removeClass("waitMe_container").removeAttr("data-waitme_id"); -f.find('.waitMe[data-waitme_id="'+a+'"]').remove()}};if(l[p])return l[p].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof p||!p)return l.init.apply(this,arguments)})};b(window).on("load",function(){b("body.waitMe_body").addClass("hideMe");setTimeout(function(){b("body.waitMe_body").find(".waitMe_container:not([data-waitme_id])").remove();b("body.waitMe_body").removeClass("waitMe_body hideMe")},200)})})(jQuery); diff --git a/views/templates/hook/confirmation.tpl b/views/templates/hook/confirmation.tpl new file mode 100644 index 0000000..32063a3 --- /dev/null +++ b/views/templates/hook/confirmation.tpl @@ -0,0 +1,30 @@ +{* +* 2007-2015 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if $status == 'ok'} + + + +{/if} From 03bb37f7e4efb0273cb088d38658ce8def3e0bc1 Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 9 Aug 2020 22:25:46 -0500 Subject: [PATCH 26/30] Actualizacion de pago desde Webhook --- controllers/front/webhookOrderStatusChanged.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/front/webhookOrderStatusChanged.php b/controllers/front/webhookOrderStatusChanged.php index c3c3fae..64f2532 100644 --- a/controllers/front/webhookOrderStatusChanged.php +++ b/controllers/front/webhookOrderStatusChanged.php @@ -29,7 +29,6 @@ public function postProcess() $idCart = substr($data['description'], 16); $cart = new Cart($idCart); - $customer = new Customer($cart->id_customer); switch ($data['state']) { case 'paid': @@ -43,12 +42,13 @@ public function postProcess() default: $ps_os_payment = Configuration::get('CULQI_STATE_ERROR'); } - $ps_os_payment = $data['state'] == "paid" ? Configuration::get('CULQI_STATE_OK') : Configuration::get('CULQI_STATE_ERROR'); - $module_name = $this->module->displayName; + $orderObject = new Order(); + $order = new Order($orderObject->getOrderByCartId((int)$cart->id)); - - // $this->module->validateOrder((int)$cart->id, $ps_os_payment, (float)$cart->getordertotal(true), $module_name, null, null, (int)$cart->id_currency, false, $customer->secure_key); + $history = new OrderHistory(); + $history->id_order = (int)$order->id; + $history->changeIdOrderState((int)$ps_os_payment, (int)($order->id)); $this->response(200, 'Order updated successfully.'); } else { From 2e4b3c4abe521f36e484d74c618e9f4ee02b32ad Mon Sep 17 00:00:00 2001 From: Nicerova7 Date: Thu, 20 Aug 2020 18:39:18 -0500 Subject: [PATCH 27/30] fixed postpayment --- controllers/front/chargeajax.php | 1 + controllers/front/postpayment.php | 7 ++++++- views/templates/hook/payment.tpl | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/controllers/front/chargeajax.php b/controllers/front/chargeajax.php index 4cb55b2..04e32f5 100644 --- a/controllers/front/chargeajax.php +++ b/controllers/front/chargeajax.php @@ -12,6 +12,7 @@ public function initContent() public function displayAjax() { $result = $this->module->charge(Tools::getValue("token_id"), Tools::getValue("installments")); + if($result->id) Configuration::updateValue($result->id,'generatedCharge'); die(Tools::jsonEncode($result)); } diff --git a/controllers/front/postpayment.php b/controllers/front/postpayment.php index 92f8d8c..32023e5 100644 --- a/controllers/front/postpayment.php +++ b/controllers/front/postpayment.php @@ -10,9 +10,14 @@ public function initContent() $cart = $this->context->cart; $customer = new Customer($cart->id_customer); + + if(!Configuration::get(Tools::getValue('validation'))) die($this->l('Primero, debes pagar la order...')); + if(Configuration::get(Tools::getValue('validation')) !== 'generatedCharge') die($this->l('Primero, debes pagar la orden... ')); + Configuration::deleteByName(Tools::getValue('validation')); $this->module->validateOrder((int)$cart->id, Configuration::get('CULQI_STATE_OK'), (float)$cart->getordertotal(true), 'Culqi', null, array(), (int)$cart->id_currency, false, $customer->secure_key); Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int)$cart->id . '&id_module=' . (int)$this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key); } -} \ No newline at end of file + +} diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 5ec64d5..904ad87 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -143,7 +143,7 @@ function culqi() { if(result.object === 'charge') { showResult('green',result.outcome.user_message); $('#payment-confirmation > .ps-shown-by-js > button').prop("disabled",true); - redirect(); + redirect(result.id); } if(result.object === 'error') { $('body').waitMe('hide'); @@ -176,9 +176,9 @@ function showResult(style,message) { $('#showresultcontent').html(message); } -function redirect() { +function redirect(value) { var url = fnReplace("{/literal}{$link->getModuleLink('culqi', 'postpayment', [], true)|escape:'htmlall':'UTF-8'}{literal}"); - location.href = url; + location.href = url + '?validation=' + value; } function fnReplace(url) { From 67bd2bb3a673a1e6725c824167b01f17f534874b Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 4 Oct 2020 13:18:35 -0500 Subject: [PATCH 28/30] Adding config_es.xml on gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7445bba..4c35b14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .DS_Store logs/* +config_*.xml \ No newline at end of file From b9fef682a660cc7a2dcd9372e18e36fd7b49ccd5 Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 4 Oct 2020 15:54:28 -0500 Subject: [PATCH 29/30] Correcion de sintxys --- views/templates/hook/payment.tpl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 7969512..6bc366c 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -21,12 +21,7 @@ $(document).ready(function() { Culqi.useClasses = true; Culqi.init(); - $('#payment-confirmation > .ps-shown-by-js > button').click(function(e) { - - $('#payment-confirmation > .ps-shown-by-js > button').prop("disabled",true); - var myPaymentMethodSelected = $('.payment-options').find("input[data-module-name='culqi']").is(':checked'); - - /** + /** * Muestra el error de la tarjeta al momento de intentar pagar. */ if (localStorage.getItem('culqi_message') !== '') { From 2784a1b8594c584b945aab9e340d4e79f86deff9 Mon Sep 17 00:00:00 2001 From: Victor Castro Date: Sun, 4 Oct 2020 16:24:10 -0500 Subject: [PATCH 30/30] Correcion de descripcion y order_id --- culqi.php | 4 ++-- views/templates/hook/payment.tpl | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/culqi.php b/culqi.php index 2563f69..5908881 100644 --- a/culqi.php +++ b/culqi.php @@ -180,9 +180,9 @@ public function charge($token_id, $installments) ), "capture" => true, "currency_code" => $this->context->currency->iso_code, - "description" => "Orden de compra ".$cart->id, + "description" => substr($cart->getProducts()[0]['name'], 0, 12), "installments" => $installments, - "metadata" => ["cart_id" => (string)$cart->id ], + "metadata" => ["ORDER_ID" => (string)$cart->id ], "email" => $this->context->customer->email, "source_id" => $token_id ) diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 6bc366c..c8ef09a 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -121,7 +121,6 @@ $(document).ready(function() { }); } else if (Culqi.order) { validation('order', Culqi.order.payment_code) - console.log(Culqi.order) } else if (Culqi.closeEvent){ console.log(Culqi.closeEvent); @@ -138,7 +137,7 @@ $(document).ready(function() { $('.showresultcontent').attr('class', '').addClass(style).html(message); } - function validation(type, code) { + function validation(type, code) { const urlValidation = $('#clq_validation').val() location.href = urlValidation.replace('CLQ_TYPE', type).replace('CLQ_CODE', code); }