-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aashish
committed
Mar 27, 2024
1 parent
79bd394
commit 0e31693
Showing
11 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Omise\Payment\Helper; | ||
|
||
class RequestHelper | ||
{ | ||
public function get_client_ip() | ||
{ | ||
$headersToCheck = [ | ||
// Check for a client using a shared internet connection | ||
'HTTP_CLIENT_IP', | ||
|
||
// Check if the proxy is used for IP/IPs | ||
'HTTP_X_FORWARDED_FOR', | ||
|
||
// check for other possible forwarded IP headers | ||
'HTTP_X_FORWARDED', | ||
'HTTP_FORWARDED_FOR', | ||
'HTTP_FORWARDED', | ||
]; | ||
|
||
foreach($headersToCheck as $header) { | ||
Check warning on line 22 in Helper/RequestHelper.php
|
||
if (empty($_SERVER[$header])) { | ||
continue; | ||
} | ||
|
||
if ($header === 'HTTP_X_FORWARDED_FOR') { | ||
return self::process_forwarded_for_header($_SERVER[$header]); | ||
} | ||
|
||
return $_SERVER[$header]; | ||
} | ||
|
||
// return default remote IP address | ||
return $_SERVER['REMOTE_ADDR']; | ||
} | ||
|
||
private function process_forwarded_for_header($forwardedForHeader) | ||
{ | ||
// Split if multiple IP addresses exist and get the last IP address | ||
if (strpos($forwardedForHeader, ',') !== false) { | ||
$multiple_ips = explode(",", $forwardedForHeader); | ||
return trim(current($multiple_ips)); | ||
} | ||
return $forwardedForHeader; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace Omise\Payment\Model\Config; | ||
|
||
use Omise\Payment\Model\Config\Config; | ||
|
||
class WeChatPay extends Config | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
const CODE = 'omise_offsite_wechat_pay'; | ||
|
||
/** | ||
* Backends identifier | ||
* @var string | ||
*/ | ||
const ID = 'wechat_pay'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
view/frontend/web/js/view/payment/method-renderer/omise-offsite-wechat-pay-method.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
define( | ||
[ | ||
'ko', | ||
'Omise_Payment/js/view/payment/omise-offsite-method-renderer', | ||
'Magento_Checkout/js/view/payment/default', | ||
'Magento_Checkout/js/model/quote', | ||
], | ||
function ( | ||
ko, | ||
Base, | ||
Component, | ||
quote | ||
) { | ||
'use strict'; | ||
|
||
return Component.extend(Base).extend({ | ||
defaults: { | ||
template: 'Omise_Payment/payment/offsite-common-form' | ||
}, | ||
|
||
isPlaceOrderActionAllowed: ko.observable(quote.billingAddress() != null), | ||
|
||
code: 'omise_offsite_wechat_pay', | ||
restrictedToCurrencies: ['thb'], | ||
logo: { | ||
file: "images/wechat_pay.svg", | ||
width: "30", | ||
height: "30", | ||
name: "wechat_pay" | ||
} | ||
}); | ||
} | ||
); |