Skip to content

Commit

Permalink
release 2.2.0
Browse files Browse the repository at this point in the history
- add support for PHP 5.6
- fix for curl verify
  • Loading branch information
Craig Christenson committed May 30, 2021
1 parent 93fabf3 commit 52f2e1f
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
$_['help_secret_word'] = 'The secret word to confirm transactions with (must be the same as defined on the merchant account configuration page).';
$_['help_secret_key'] = 'The secret key (from your 2Checkout account) is required to authenticate into 2Checkout.';
$_['help_total'] = 'The checkout total the order must reach before this payment method becomes active.';
$_['help_entry_processing_status'] = 'This status is used for setting order status after payment callback.';

// Error
$_['error_permission'] = 'Warning: You do not have permission to modify 2Checkout!';
Expand Down
5 changes: 3 additions & 2 deletions upload/admin/model/extension/payment/twocheckout_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public function uninstall()
* @param int $order_id
* @return null
*/
public function getTransactionByOrderId(int $order_id)
public function getTransactionByOrderId($order_id)
{
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "twocheckout_api` WHERE `order_id` = '" . (int)$order_id . "' LIMIT 1");
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "twocheckout_api` WHERE `order_id` = '" .
intval($order_id) . "' LIMIT 1");

return ($query->num_rows) ? $query->row : null;
}
Expand Down
5 changes: 3 additions & 2 deletions upload/admin/model/extension/payment/twocheckout_cplus.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public function uninstall() {
*
* @return null
*/
public function getTransactionByOrderId( int $order_id ) {
$query = $this->db->query( "SELECT * FROM `" . DB_PREFIX . "twocheckout_cplus` WHERE `order_id` = '" . (int) $order_id . "' LIMIT 1" );
public function getTransactionByOrderId( $order_id ) {
$query = $this->db->query( "SELECT * FROM `" . DB_PREFIX . "twocheckout_cplus` WHERE `order_id` = '" .
intval($order_id) . "' LIMIT 1" );

return ( $query->num_rows ) ? $query->row : null;
}
Expand Down
5 changes: 3 additions & 2 deletions upload/admin/model/extension/payment/twocheckout_inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public function uninstall()
* @param int $order_id
* @return null
*/
public function getTransactionByOrderId(int $order_id)
public function getTransactionByOrderId( $order_id)
{
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "twocheckout_inline` WHERE `order_id` = '" . (int)$order_id . "' LIMIT 1");
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "twocheckout_inline` WHERE `order_id` = '" .
intval($order_id) . "' LIMIT 1");

return ($query->num_rows) ? $query->row : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="payment_twocheckout_cplus_processing_status_id">{{ entry_processing_status }}</label>
<label class="col-sm-2 control-label" for="payment_twocheckout_cplus_processing_status_id">
<span data-toggle="tooltip" title="{{ help_entry_processing_status }}">{{ entry_processing_status }}</span>
</label>
<div class="col-sm-10">
<select name="payment_twocheckout_cplus_processing_status_id" id="payment_twocheckout_cplus_processing_status_id" class="form-control">
{% for order_status in order_statuses %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function purchase()
'Language' => strtolower(substr($this->session->data['language'], 0, 2)),
'Country' => $country_iso,
'CustomerIP' => $model->getCustomerIp(),
'Source' => 'OPENCART_3',
'Source' => 'OPENCART_'.str_replace('.','_',VERSION),
'ExternalReference' => $order_id,
'Items' => $model->getItem($order_info['store_name'], $total),
'BillingDetails' => $model->getBillingDetails($order_info, $country_iso),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ public function success() {
if ( in_array( $api_response['Status'], [ 'AUTHRECEIVED', 'COMPLETE' ] ) )
{
$order_status_id = $this->config->get( 'payment_twocheckout_cplus_processing_status_id' );
$this->model_checkout_order->addOrderHistory( $params['order-ext-ref'], $order_status_id );
$this->model_checkout_order->addOrderHistory(
$this->session->data['order_id'],
$order_status_id,
'2Checkout transaction ID:<strong style="color: #12578c;"> ' . $api_response['RefNo'] . '</strong>'
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ public function index()
'name' => $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'],
'phone' => $order_info['telephone'],
'country' => $order_info['payment_iso_code_2'],
'state' => $order_info['payment_zone_code'] ?? 'XX',
'state' => isset($order_info['payment_zone_code']) ? $order_info['payment_zone_code'] : 'XX',
'email' => $order_info['email'],
'address' => $order_info['payment_address_1'],
'address2' => $order_info['payment_address_2'] ?? '',
'address2' => isset($order_info['payment_address_2']) ? $order_info['payment_address_2'] : '',
'city' => $order_info['payment_city'],
'company-name' => $order_info['payment_company'],
'zip' => $order_info['payment_postcode'],
];

$shippingAddressData = [
'ship-name' => '',//$order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname'],
'ship-name' => $order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname'],
'ship-country' => $order_info['shipping_iso_code_2'],
'ship-state' => $order_info['shipping_zone_code'] ?? 'XX',
'ship-state' => isset($order_info['shipping_zone_code']) ? $order_info['shipping_zone_code'] : 'XX',
'ship-city' => $order_info['shipping_city'],
'ship-email' => '',//$order_info['email'],
'ship-email' => $order_info['email'],
'ship-address' => $order_info['shipping_address_1'],
'ship-address2' => !empty($order_info['shipping_address_2']) ? $order_info['shipping_address_2'] : '',
'ship-address2' => (isset($order_info['shipping_address_2']) && !empty($order_info['shipping_address_2'])
) ? $order_info['shipping_address_2'] : '',
];

$payload['products'][] = [
Expand All @@ -77,7 +78,7 @@ public function index()
$payload['test'] = $config['payment_twocheckout_inline_test'] === 'yes' ? 1 : 0;
$payload['order-ext-ref'] = $order_id;
$payload['customer-ext-ref'] = $order_info['email'];
$payload['src'] = 'OPENCART_3_6';
$payload['src'] = 'OPENCART_'.str_replace('.','_',VERSION);
$payload['mode'] = 'DYNAMIC';
$payload['dynamic'] = '1';
$payload['country'] = strtoupper($order_info['payment_iso_code_2']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// Text
$_['text_title'] = 'Credit Card / Debit Card (2Checkout)';
$_['text_title'] = 'Credit Card / Debit Card (2Checkout 2PayJs)';
$_['generic_error'] = 'The payment could not be processed for order! Please try again or contact us.';
$_['updated_order_status'] = 'Order status updated to: ';
20 changes: 11 additions & 9 deletions upload/catalog/model/extension/payment/twocheckout_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public function getMethod($address, $total)
*
* @return array
*/
public function getBillingDetails(array $post_data, string $country_iso)
public function getBillingDetails( array $post_data, $country_iso)
{
$address = [
'Address1' => $post_data['payment_address_1'],
'City' => $post_data['payment_city'],
'State' => $post_data['payment_zone_code'] ?? 'XX',
'State' => isset($post_data['payment_zone_code']) ? $post_data['payment_zone_code'] : 'XX',
'CountryCode' => $country_iso,
'Email' => $post_data['email'],
'FirstName' => $post_data['payment_firstname'],
Expand All @@ -153,7 +153,7 @@ public function getBillingDetails(array $post_data, string $country_iso)
* @param float $total
* @return mixed
*/
public function getItem(string $name, float $total)
public function getItem( $name, $total)
{
$items[] = [
'Code' => null,
Expand All @@ -179,7 +179,7 @@ public function getItem(string $name, float $total)
* @param string $currency
* @return array
*/
public function getPaymentDetails(string $type, string $token, string $currency)
public function getPaymentDetails( $type, $token, $currency)
{

return [
Expand Down Expand Up @@ -375,9 +375,11 @@ public function processOrderStatus($params)
*/
private function isChargeBack($params)
{
$chargeBackResolution = isset($params['CHARGEBACK_RESOLUTION']) ? trim($params['CHARGEBACK_RESOLUTION']) : '';
$chargeBackReasonCode = isset($params['CHARGEBACK_REASON_CODE']) ? trim($params['CHARGEBACK_REASON_CODE']) : '';

// we need to mock up a message with some params in order to add this note
if (!empty(trim($params['CHARGEBACK_RESOLUTION']) && trim($params['CHARGEBACK_RESOLUTION']) !== 'NONE') &&
!empty(trim($params['CHARGEBACK_REASON_CODE']))) {
if (!empty($chargeBackResolution) && $chargeBackResolution !== 'NONE' && !empty($chargeBackReasonCode)) {

$this->load->model('checkout/order');
// list of chargeback reasons on 2CO platform
Expand All @@ -395,10 +397,10 @@ private function isChargeBack($params)
'NOT_AS_DESCRIBED' => 'Product(s) not as described/not functional'
];

$why = isset($reasons[trim($params['CHARGEBACK_REASON_CODE'])]) ?
$reasons[trim($params['CHARGEBACK_REASON_CODE'])] :
$why = isset($reasons[$chargeBackReasonCode]) ?
$reasons[$chargeBackReasonCode] :
$reasons['UNKNOWN'];
$message = '2Checkout chargeback status is now ' . $params['CHARGEBACK_RESOLUTION'] . '. Reason: ' . $why . '!';
$message = '2Checkout chargeback status is now ' . $chargeBackResolution . '. Reason: ' . $why . '!';
$this->model_checkout_order->addOrderHistory($params['REFNOEXT'], self::OPENCART_CHARGEBACK, $message);

return true;
Expand Down
66 changes: 40 additions & 26 deletions upload/catalog/model/extension/payment/twocheckout_cplus.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function getHeaders($sellerId, $secretKey)
* @return mixed
* @throws Exception
*/
public function call( string $endpoint, array $params, $method = 'POST', $sellerId, $secretKey) {
public function call( $endpoint, array $params, $method = 'POST', $sellerId, $secretKey) {
// if endpoint does not starts or end with a '/' we add it, as the API needs it
if ( $endpoint[0] !== '/' ) {
$endpoint = '/' . $endpoint;
Expand All @@ -120,6 +120,11 @@ public function call( string $endpoint, array $params, $method = 'POST', $seller
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $params, JSON_UNESCAPED_UNICODE ) );
}

if ( $this->config->get( 'payment_twocheckout_cplus_test' ) ) {
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); //by default value is 2
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); //by default value is 1
}
$response = curl_exec( $ch );

if ( $response === false ) {
Expand Down Expand Up @@ -160,8 +165,14 @@ public function getSignature( $merchant_id, $buy_link_secret_word, $payload ) {
'content-type: application/json',
'cache-control: no-cache',
'merchant-token: ' . $jwtToken,

],
] );

if ( $this->config->get( 'payment_twocheckout_cplus_test' ) ) {
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false ); //by default value is 2
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false ); //by default value is 1
}
$response = curl_exec( $curl );
$err = curl_error( $curl );
curl_close( $curl );
Expand Down Expand Up @@ -417,30 +428,33 @@ private function _processOrderStatus( $params ) {
*/
private function isChargeBack($params)
{
// we need to mock up a message with some params in order to add this note
if (!empty($params['CHARGEBACK_RESOLUTION']) && $params['CHARGEBACK_RESOLUTION'] !== 'NONE' &&
!empty($params['CHARGEBACK_REASON_CODE'])) {

$this->load->model('checkout/order');
// list of chargeback reasons on 2CO platform
$reasons = [
'UNKNOWN' => 'Unknown', //default
'MERCHANDISE_NOT_RECEIVED' => 'Order not fulfilled/not delivered',
'DUPLICATE_TRANSACTION' => 'Duplicate order',
'FRAUD / NOT_RECOGNIZED' => 'Fraud/Order not recognized',
'FRAUD' => 'Fraud',
'CREDIT_NOT_PROCESSED' => 'Agreed refund not processed',
'NOT_RECOGNIZED' => 'New/renewal order not recognized',
'AUTHORIZATION_PROBLEM' => 'Authorization problem',
'INFO_REQUEST' => 'Information request',
'CANCELED_RECURRING' => 'Recurring payment was canceled',
'NOT_AS_DESCRIBED' => 'Product(s) not as described/not functional'
];

$why = isset($reasons[trim($params['CHARGEBACK_REASON_CODE'])]) ?
$reasons[trim($params['CHARGEBACK_REASON_CODE'])] :
$reasons['UNKNOWN'];
$message = '2Checkout chargeback status is now ' . $params['CHARGEBACK_RESOLUTION'] . '. Reason: ' . $why . '!';
$chargeBackResolution = isset($params['CHARGEBACK_RESOLUTION']) ? trim($params['CHARGEBACK_RESOLUTION']) : '';
$chargeBackReasonCode = isset($params['CHARGEBACK_REASON_CODE']) ? trim($params['CHARGEBACK_REASON_CODE']) : '';

// we need to mock up a message with some params in order to add this note
if (!empty($chargeBackResolution) && $chargeBackResolution !== 'NONE' && !empty($chargeBackReasonCode)) {

$this->load->model('checkout/order');
// list of chargeback reasons on 2CO platform
$reasons = [
'UNKNOWN' => 'Unknown', //default
'MERCHANDISE_NOT_RECEIVED' => 'Order not fulfilled/not delivered',
'DUPLICATE_TRANSACTION' => 'Duplicate order',
'FRAUD / NOT_RECOGNIZED' => 'Fraud/Order not recognized',
'FRAUD' => 'Fraud',
'CREDIT_NOT_PROCESSED' => 'Agreed refund not processed',
'NOT_RECOGNIZED' => 'New/renewal order not recognized',
'AUTHORIZATION_PROBLEM' => 'Authorization problem',
'INFO_REQUEST' => 'Information request',
'CANCELED_RECURRING' => 'Recurring payment was canceled',
'NOT_AS_DESCRIBED' => 'Product(s) not as described/not functional'
];

$why = isset($reasons[$chargeBackReasonCode]) ?
$reasons[$chargeBackReasonCode] :
$reasons['UNKNOWN'];
$message = '2Checkout chargeback status is now ' . $chargeBackResolution . '. Reason: ' . $why . '!';

$this->log->write('Order status changed to chargeback');
$order_status_id = $this->config->get('payment_twocheckout_cplus_chargeback_status_id');
$this->model_checkout_order->addOrderHistory($params['REFNOEXT'], $order_status_id, $message);
Expand Down Expand Up @@ -537,7 +551,7 @@ public function getOtherDetails($order_info, $test, $seller_id, $price, $languag
$buy_link_params['qty'] = 1;
$buy_link_params['type'] = 'PRODUCT';
$buy_link_params['tangible'] = 0;
$buy_link_params['src'] = 'OPENCART_3_0_3_6';
$buy_link_params['src'] = 'OPENCART_'.str_replace('.','_',VERSION);
$buy_link_params['return-type'] = 'redirect';
$buy_link_params['return-url'] = $this->url->link( 'extension/payment/twocheckout_cplus/success' );
$buy_link_params['expiration'] = time() + ( 3600 * 5 );
Expand Down
12 changes: 7 additions & 5 deletions upload/catalog/model/extension/payment/twocheckout_inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ public function processOrderStatus($params)
*/
private function isChargeBack($params)
{
$chargeBackResolution = isset($params['CHARGEBACK_RESOLUTION']) ? trim($params['CHARGEBACK_RESOLUTION']) : '';
$chargeBackReasonCode = isset($params['CHARGEBACK_REASON_CODE']) ? trim($params['CHARGEBACK_REASON_CODE']) : '';

// we need to mock up a message with some params in order to add this note
if (!empty(trim($params['CHARGEBACK_RESOLUTION']) && trim($params['CHARGEBACK_RESOLUTION']) !== 'NONE') &&
!empty(trim($params['CHARGEBACK_REASON_CODE']))) {
if (!empty($chargeBackResolution) && $chargeBackResolution !== 'NONE' && !empty($chargeBackReasonCode)) {

$this->load->model('checkout/order');
// list of chargeback reasons on 2CO platform
Expand All @@ -285,10 +287,10 @@ private function isChargeBack($params)
'NOT_AS_DESCRIBED' => 'Product(s) not as described/not functional'
];

$why = isset($reasons[trim($params['CHARGEBACK_REASON_CODE'])]) ?
$reasons[trim($params['CHARGEBACK_REASON_CODE'])] :
$why = isset($reasons[$chargeBackReasonCode]) ?
$reasons[$chargeBackReasonCode] :
$reasons['UNKNOWN'];
$message = '2Checkout chargeback status is now ' . $params['CHARGEBACK_RESOLUTION'] . '. Reason: ' . $why . '!';
$message = '2Checkout chargeback status is now ' . $chargeBackResolution . '. Reason: ' . $why . '!';
$this->model_checkout_order->addOrderHistory($params['REFNOEXT'], self::OPENCART_CHARGEBACK, $message);

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<form id="tco-payment-form">
<button class="btn btn-primary pull-right" id="placeOrderTco">{{ button_confirm }}</button>
<button class="btn btn-primary pull-right" id="placeOrderTcoInline">{{ button_confirm }}</button>
<div class="clearfix"></div>
</form>

<script>
var params = {{ payload }};
$(document).ready(function () {
resetTwoCheckout();
$('body').on('click', '#placeOrderTco', function (event) {
$('body').on('click', '#placeOrderTcoInline', function (event) {
event.preventDefault();
twoCheckoutInline();
});
Expand Down

0 comments on commit 52f2e1f

Please sign in to comment.