|
@@ -44,9 +44,21 @@ class AfterpayController extends Controller
|
|
|
$code = $request->input('code', 'afterpay');
|
|
$code = $request->input('code', 'afterpay');
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- $result = $this->$code->fetchConfiguration($code);
|
|
|
|
|
|
|
+ // afterpay 支持多国家,需要分别查询各国限额
|
|
|
|
|
+ $countries = ($code === 'afterpay')
|
|
|
|
|
+ ? ['US' => '', 'CA' => '_ca'] // US 后缀为空保持兼容,CA 后缀 _ca
|
|
|
|
|
+ : ['GBP' => '']; // clearpay 只查一次
|
|
|
|
|
|
|
|
- if (! $result) {
|
|
|
|
|
|
|
+ $results = [];
|
|
|
|
|
+ foreach ($countries as $countryCode => $keySuffix) {
|
|
|
|
|
+ $result = $this->$code->fetchConfiguration($code, $countryCode);
|
|
|
|
|
+ if (! $result) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $results[$keySuffix] = $result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($results)) {
|
|
|
return response()->json([
|
|
return response()->json([
|
|
|
'success' => false,
|
|
'success' => false,
|
|
|
'message' => 'Failed to fetch configuration from Afterpay',
|
|
'message' => 'Failed to fetch configuration from Afterpay',
|
|
@@ -55,16 +67,18 @@ class AfterpayController extends Controller
|
|
|
|
|
|
|
|
// 写入数据库
|
|
// 写入数据库
|
|
|
$prefix = 'sales.payment_methods.' . $code . '.';
|
|
$prefix = 'sales.payment_methods.' . $code . '.';
|
|
|
- $fields = [
|
|
|
|
|
- 'min_order_total' => $result['min_order_total'] ?? '',
|
|
|
|
|
- 'max_order_total' => $result['max_order_total'] ?? '',
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ foreach ($results as $keySuffix => $result) {
|
|
|
|
|
+ $fields = [
|
|
|
|
|
+ 'min_order_total' . $keySuffix => $result['min_order_total'] ?? '',
|
|
|
|
|
+ 'max_order_total' . $keySuffix => $result['max_order_total'] ?? '',
|
|
|
|
|
+ ];
|
|
|
|
|
|
|
|
- foreach ($fields as $field => $value) {
|
|
|
|
|
- \Webkul\Core\Models\CoreConfig::updateOrCreate(
|
|
|
|
|
- ['code' => $prefix . $field],
|
|
|
|
|
- ['value' => $value]
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ foreach ($fields as $field => $value) {
|
|
|
|
|
+ \Webkul\Core\Models\CoreConfig::updateOrCreate(
|
|
|
|
|
+ ['code' => $prefix . $field],
|
|
|
|
|
+ ['value' => $value]
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 清除配置缓存
|
|
// 清除配置缓存
|
|
@@ -74,8 +88,10 @@ class AfterpayController extends Controller
|
|
|
return response()->json([
|
|
return response()->json([
|
|
|
'success' => true,
|
|
'success' => true,
|
|
|
'message' => 'Limits updated successfully',
|
|
'message' => 'Limits updated successfully',
|
|
|
- 'min_order_total' => $result['min_order_total'] ?? '',
|
|
|
|
|
- 'max_order_total' => $result['max_order_total'] ?? '',
|
|
|
|
|
|
|
+ 'min_order_total' => $results['']['min_order_total'] ?? '',
|
|
|
|
|
+ 'max_order_total' => $results['']['max_order_total'] ?? '',
|
|
|
|
|
+ 'min_order_total_ca' => $results['_ca']['min_order_total'] ?? '',
|
|
|
|
|
+ 'max_order_total_ca' => $results['_ca']['max_order_total'] ?? '',
|
|
|
]);
|
|
]);
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
\Log::channel('payment')->error("{$code} updateLimits error: " . $e->getMessage());
|
|
\Log::channel('payment')->error("{$code} updateLimits error: " . $e->getMessage());
|