Skip to content

Commit a8cb9cd

Browse files
1.1.0
1 parent c95ae97 commit a8cb9cd

File tree

18 files changed

+288
-51
lines changed

18 files changed

+288
-51
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ Fintecture is a Fintech that has a payment solution via bank transfer available
1212
- Connect to your server (FTP/SSH...)
1313
- Browse to **/var/www/html** (may be different for you, depending on where you have installed Magento 1)
1414
- Copy/paste **app** folder (but don't delete yours, it should just add new files)
15+
- Empty your cache on System > Cache Management > Flush Magento Cache & Flush Cache Storage, it will run upgrade scripts
1516

1617
## Activation
18+
1719
- Enable the module in System -> Payment Methods
1820

1921
## Configuration
@@ -22,7 +24,6 @@ Go to Stores > Configuration > Sales > Payment methods.
2224

2325
- Select environment (test/production)
2426
- Fill API key, API secret and API private key based on the selected environment (https://console.fintecture.com/)
25-
- Choose to display Fintecture logo or not
2627
- Test your connection (if everything is ok you should have a success message)
2728
- Don't forget to enable the payment method unless it won't be displayed on front-end
2829
- Empty your cache on System > Cache Management > Flush Magento Cache & Flush Cache Storage

app/code/local/Fintecture/Payment/Block/Form/Payment.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ protected function _construct()
1313
->setTemplate('fintecture_payment/form/payment.phtml')
1414
->setMethodTitle($this->__('Instant bank payment'));
1515

16-
if ($config['show_logo'] = Mage::getStoreConfig('payment/fintecture/show_logo')) {
17-
$fintecture_logo = Mage::getConfig()->getBlockClassName('core/template');
18-
$fintecture_logo = new $fintecture_logo();
19-
$fintecture_logo->setTemplate('fintecture_payment/form/logo.phtml');
20-
$this->setMethodLabelAfterHtml($fintecture_logo->toHtml());
21-
}
16+
$fintecture_logo = Mage::getConfig()->getBlockClassName('core/template');
17+
$fintecture_logo = new $fintecture_logo();
18+
$fintecture_logo->setTemplate('fintecture_payment/form/logo.phtml');
19+
$this->setMethodLabelAfterHtml($fintecture_logo->toHtml());
2220
}
2321
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
class Fintecture_Payment_Block_Form_PaymentBnpl extends Mage_Core_Block_Template
4+
{
5+
protected function _construct()
6+
{
7+
parent::_construct();
8+
9+
$parse = parse_url(Mage::getBaseUrl());
10+
$host = $parse['scheme'] . '://' . $parse['host'];
11+
12+
$this->setData('host', $host)
13+
->setTemplate('fintecture_payment/form/payment_bnpl.phtml')
14+
->setMethodTitle($this->__('Buy Now, Pay Later. Without fee.'))
15+
->setCustomText($this->__('Benefit from a 30 day payment term for your professional purchases.'));
16+
17+
$fintecture_logo = Mage::getConfig()->getBlockClassName('core/template');
18+
$fintecture_logo = new $fintecture_logo();
19+
$fintecture_logo->setTemplate('fintecture_payment/form/logo.phtml');
20+
$this->setMethodLabelAfterHtml($fintecture_logo->toHtml());
21+
}
22+
23+
public function getCustomText()
24+
{
25+
return $this->customText;
26+
}
27+
28+
public function setCustomText($text)
29+
{
30+
$this->customText = $text;
31+
return $this;
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
class Fintecture_Payment_Block_Payment_InfoBnpl extends Mage_Payment_Block_Info
4+
{
5+
protected function _construct()
6+
{
7+
parent::_construct();
8+
$this->setTemplate('fintecture_payment/info_bnpl.phtml');
9+
}
10+
11+
public function getPaymentServiceTitle()
12+
{
13+
return $this->getMethod()->getTitle();
14+
}
15+
16+
public function getPaymentSessionId()
17+
{
18+
$order = $this->getInfo()->getOrder();
19+
$payment = $order ? $order->getPayment() : null;
20+
21+
return $payment ? $payment->getAdditionalInformation('fintecture_session_id') : null;;
22+
}
23+
}

app/code/local/Fintecture/Payment/Helper/Curl.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public function getAccessTokenTest($environment, $app_id = '', $app_secret = '',
117117
return true;
118118
}
119119

120-
public function connect($payload, $params)
120+
/**
121+
* This function is used to create a link of payment
122+
*/
123+
public function connect($payload, $params, $method)
121124
{
122125
$config = Mage::helper('fintecture_payment/config');
123126
$app = $config->getAppInformation();
@@ -130,6 +133,10 @@ public function connect($payload, $params)
130133
return false;
131134
}
132135

136+
if ($method && $method === 'bnpl') {
137+
$payload['meta']['type'] = 'BuyNowPayLater';
138+
}
139+
133140
$url = '/pis/v2/connect?' . $params;
134141

135142
$crypto = Mage::helper('fintecture_payment/crypto');

app/code/local/Fintecture/Payment/Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
class Fintecture_Payment_Helper_Data extends Mage_Payment_Helper_Data
44
{
5-
}
5+
}

app/code/local/Fintecture/Payment/Helper/Stats.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Fintecture_Payment_Helper_Stats extends Mage_Payment_Helper_Data
44
{
5-
const FINTECTURE_PLUGIN_VERSION = '1.0.7';
5+
const FINTECTURE_PLUGIN_VERSION = '1.1.0';
66
const FINTECTURE_STATS_URL = 'https://api.fintecture.com/ext/v1/activity';
77

88
public function logAction($action)
@@ -25,6 +25,7 @@ private function getSystemInfos()
2525
{
2626
$enabled = Mage::helper('core')->isModuleEnabled('Fintecture_Payment');
2727
$active = Mage::getStoreConfig('payment/fintecture/active');
28+
$bnplActive = Mage::getStoreConfig('payment/bnpl_fintecture/active');
2829
$isProduction = Mage::getStoreConfig('payment/fintecture/environment') === 'production';
2930
$allActivePaymentMethods = Mage::getModel('payment/config')->getActiveMethods();
3031

@@ -41,7 +42,8 @@ private function getSystemInfos()
4142
'module_production' => $isProduction,
4243
'module_sandbox_app_id' => Mage::getStoreConfig('payment/fintecture/sandbox_app_id'),
4344
'module_production_app_id' => Mage::getStoreConfig('payment/fintecture/production_app_id'),
44-
'module_branding' => Mage::getStoreConfig('payment/fintecture/show_logo')
45+
'module_bnpl' => $enabled && $bnplActive,
46+
'module_bnpl_min_amount' => Mage::getStoreConfig('payment/bnpl_fintecture/minimun_amount_bnpl'),
4547
];
4648
}
4749
}

app/code/local/Fintecture/Payment/Helper/Util.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function getOrderState($payment_status, $get_status, $transaction_id)
4040
return $this->mappedState('payment_created');
4141
} elseif ($payment_status['meta']['status'] === 'payment_pending') {
4242
return $this->mappedState('payment_pending');
43+
} elseif ($payment_status['meta']['status'] === 'order_created') {
44+
return $this->mappedState('order_created');
4345
}
4446
}
4547
}
@@ -51,6 +53,8 @@ public function mappedState($status = '')
5153
switch ($status) {
5254
case 'payment_created':
5355
return Mage_Sales_Model_Order::STATE_PROCESSING;
56+
case 'order_created':
57+
return 'order_created';
5458
case 'payment_pending':
5559
return Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
5660
case 'payment_unsuccessful':
@@ -68,7 +72,7 @@ public function createPayload($order)
6872
$amount = (string) round($data['grand_total'], 2); // keep only 2 decimals
6973
$communication = self::FINTECTURE_PAYMENT_PREFIX . $data['increment_id'];
7074

71-
return [
75+
$payload = [
7276
'data' => [
7377
'type' => 'PAYMENT',
7478
'attributes' => [
@@ -82,7 +86,6 @@ public function createPayload($order)
8286
'psu_email' => $data['customer_email'],
8387
'psu_ip' => $data['remote_ip'],
8488
'psu_phone' => $address['telephone'],
85-
'psu_company' => $address['company'],
8689
'psu_address' => [
8790
'street' => $address['street'],
8891
'complement' => $address['street'],
@@ -92,6 +95,12 @@ public function createPayload($order)
9295
]
9396
]
9497
];
98+
99+
if (!empty($address['company'])) {
100+
$payload['meta']['psu_company'] = $address['company'];
101+
}
102+
103+
return $payload;
95104
}
96105

97106
public function validSignature($private_key)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
class Fintecture_Payment_Model_PaymentBnpl extends Mage_Payment_Model_Method_Abstract
4+
{
5+
protected $_code = 'bnpl_fintecture';
6+
7+
protected $_formBlockType = 'fintecture_payment/form_paymentBnpl'; // This is the block that's displayed on the checkout
8+
protected $_infoBlockType = 'fintecture_payment/payment_infoBnpl'; // This is the block that's displayed on the checkout
9+
10+
protected $_isInitializeNeeded = true;
11+
12+
protected $_canUseInternal = true;
13+
14+
protected $_isGateway = true; // Is this payment method a gateway (online auth/charge) ?
15+
16+
protected $_canAuthorize = true; // Can authorize online?
17+
18+
protected $_canUseCheckout = true; // Can show this payment method as an option on checkout payment page?
19+
20+
public function getOrderPlaceRedirectUrl()
21+
{
22+
return Mage::getUrl('fintecture/standard/redirect', array('_query' => 'method=bnpl', '_use_rewrite' => false));
23+
}
24+
25+
// Use this to set whether the payment method should be available in only certain circumstances
26+
public function isAvailable($quote = null)
27+
{
28+
// Check that Fintecture BNPL is enabled
29+
if (!Mage::getStoreConfigFlag('payment/bnpl_fintecture/active')) {
30+
return false;
31+
}
32+
33+
// Check that we have a quote
34+
if (!$quote) {
35+
return false;
36+
}
37+
38+
// Check if the order amount is less than the amount required to display BNPL
39+
$cartAmount = (float) $quote->getGrandTotal();
40+
if ($cartAmount < (float) Mage::getStoreConfig('payment/bnpl_fintecture/minimun_amount_bnpl')) {
41+
return false;
42+
}
43+
44+
return true;
45+
}
46+
47+
// Errors are handled as a javascript alert on the client side
48+
// This method gets run twice - once on the quote payment object, once on the order payment object
49+
// To make sure the values come across from quote payment to order payment, use the config node sales_convert_quote_payment
50+
public function validate()
51+
{
52+
parent::validate();
53+
54+
// This returns Mage_Sales_Model_Quote_Payment, or the Mage_Sales_Model_Order_Payment
55+
$info = $this->getInfoInstance();
56+
57+
return $this;
58+
}
59+
}

app/code/local/Fintecture/Payment/controllers/StandardController.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public function redirectAction()
2222

2323
// Get redirect URL
2424
$curl = Mage::helper('fintecture_payment/curl');
25-
$connect = $curl->connect($payload, $params);
25+
26+
$method = $this->getRequest()->getParam('method');
27+
$connect = $curl->connect($payload, $params, $method);
28+
2629
if (!$connect) {
2730
Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure');
2831
} else {
@@ -54,7 +57,7 @@ public function responseAction()
5457
}
5558

5659
$error = empty($params['state']) || empty($params['status']) || empty($params['session_id'] ||
57-
!in_array($params['status'], ['payment_created', 'payment_pending']));
60+
!in_array($params['status'], ['payment_created', 'payment_pending', 'order_created']));
5861

5962
if (!$error) {
6063
$curl = Mage::helper('fintecture_payment/curl');
@@ -69,7 +72,10 @@ public function responseAction()
6972
$state = $util->getOrderState($payment_status, $params['status'], $transaction_id);
7073
$order->setState($state, true);
7174

72-
if ($state === Mage_Sales_Model_Order::STATE_PROCESSING) {
75+
if (in_array($state, [
76+
Mage_Sales_Model_Order::STATE_PROCESSING,
77+
'order_created',
78+
])) {
7379
// Payment was successful, so update the order's state, send order email and move to the success page
7480
$order->sendNewOrderEmail();
7581
$order->setEmailSent(true);
@@ -94,7 +100,7 @@ public function responseAction()
94100
$invoice->getOrder()->setIsInProcess(true);
95101
$order->addStatusHistoryComment(
96102
'Auto Invoice generated.',
97-
Mage_Sales_Model_Order::STATE_PROCESSING
103+
$state
98104
)->setIsCustomerNotified(true);
99105
} else {
100106
$order->addStatusHistoryComment('Fintecture: Order cannot be invoiced.', false);

0 commit comments

Comments
 (0)