| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FormMigration\Steps; |
| 4 |
|
| 5 |
use Give\FormMigration\Contracts\FormMigrationStep; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 3.14.0 |
| 9 |
*/ |
| 10 |
class RazorpayPerFormSettings extends FormMigrationStep |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @since 3.14.0 |
| 14 |
*/ |
| 15 |
public function canHandle(): bool |
| 16 |
{ |
| 17 |
return $this->formV2->isRazorpayPerFormSettingsEnabled(); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* @since 3.14.0 |
| 22 |
*/ |
| 23 |
public function process() |
| 24 |
{ |
| 25 |
$oldFormId = $this->formV2->id; |
| 26 |
|
| 27 |
$paymentGatewaysBlock = $this->fieldBlocks->findByName('givewp/payment-gateways'); |
| 28 |
|
| 29 |
$paymentGatewaysBlock->setAttribute('razorpayUseGlobalSettings', |
| 30 |
$this->getMetaValue($oldFormId, 'razorpay_per_form_account_options', 'global') === 'global'); |
| 31 |
|
| 32 |
$paymentGatewaysBlock->setAttribute('razorpayLiveKeyId', |
| 33 |
$this->getMetaValue($oldFormId, 'razorpay_per_form_live_merchant_key_id', '')); |
| 34 |
$paymentGatewaysBlock->setAttribute('razorpayLiveSecretKey', |
| 35 |
$this->getMetaValue($oldFormId, 'razorpay_per_form_live_merchant_secret_key', '')); |
| 36 |
|
| 37 |
$paymentGatewaysBlock->setAttribute('razorpayTestKeyId', |
| 38 |
$this->getMetaValue($oldFormId, 'razorpay_per_form_test_merchant_key_id', '')); |
| 39 |
$paymentGatewaysBlock->setAttribute('razorpayTestSecretKey', |
| 40 |
$this->getMetaValue($oldFormId, 'razorpay_per_form_test_merchant_secret_key', '')); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* @since 3.14.0 |
| 45 |
*/ |
| 46 |
private function getMetaValue(int $formId, string $metaKey, $defaultValue) |
| 47 |
{ |
| 48 |
$metaValue = give()->form_meta->get_meta($formId, $metaKey, true); |
| 49 |
|
| 50 |
if ( ! $metaValue) { |
| 51 |
return $defaultValue; |
| 52 |
} |
| 53 |
|
| 54 |
return $metaValue; |
| 55 |
} |
| 56 |
} |
| 57 |
|