// Register shortcode
add_shortcode('payment_form', 'render_payment_form');
// Payment Form
function render_payment_form() {
ob_start();
?>
<!-- Payment form HTML -->
<div class="payment-form-container">
<form class="payment-form" id="payment-form" method="post" action="">
<label for="payment_option">Select Payment Option:</label>
<select name="card_type" id="card_type">
<option value="eu_consumer">Consumer Card issued in the European Union</option>
<option value="non_eu_commercial">Commercial Card or Card issued outside of the EU</option>
</select>
<br />
<label for="amount">Enter Amount (EUR):</label>
<input type="text" name="amount" id="amount" required>
<br />
<button type="submit" name="pay_now">Pay Now</button>
</form>
</div>
<?php
return ob_get_clean();
}
/* Styles for the form container */
.payment-form-container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
/* Styles for form elements */
.payment-form label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}
.payment-form select,
.payment-form input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
box-sizing: border-box;
}
.payment-form button {
background-color: #4caf50;
color: #fff;
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
}
/* Additional styling for better readability */
.payment-form option {
font-weight: normal;
}
// On form submit
add_action('init', 'process_payment_form');
function process_payment_form() {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['amount']) && isset($_POST['card_type'])) {
$amount = $_POST['amount'];
$card_type = $_POST['card_type'];
if ($card_type === 'eu_consumer') {
// GETNET
$url = 'https://paymentpage-test.getneteurope.com/api/payment/register';
$headers = array(
'Authorization' => 'Basic NTE1MjI1LUdldG5ldEV1cm9wZVRFU1Q6NGNITFJFLVE3WWNBUA==',
'Content-Type' => 'application/json'
);
$body = array(
'payment' => array(
'merchant-account-id' => array('value' => '5c4a8a42-04a8-4970-a595-262f0ba0a108'),
'request-id' => uniqid(),
'transaction-type' => 'authorization',
'requested-amount' => array('value' => $amount, 'currency' => 'EUR'),
'account-holder' => array('first-name' => 'John', 'last-name' => 'Doe'),
'payment-methods' => array('payment-method' => array(array('name' => 'creditcard'))),
'success-redirect-url' => 'https://demoshop-test.getneteurope.com/demoshop/#/success',
'fail-redirect-url' => 'https://demoshop-test.getneteurope.com/demoshop/#/error',
'cancel-redirect-url' => 'https://demoshop-test.getneteurope.com/demoshop/#/cancel'
)
);
$response = wp_remote_post($url, array('headers' => $headers, 'body' => json_encode($body)));
$response_body = wp_remote_retrieve_body($response);
$response_data = json_decode($response_body, true);
// Redirect to payment page
if (isset($response_data['payment-redirect-url'])) {
wp_redirect($response_data['payment-redirect-url']);
exit;
}
} elseif ($card_type === 'non_eu_commercial') {
// NEXI
// $url = 'https://test.api.dibspayment.eu/v1/payments';
$url = 'https://test.api.dibspayment.eu';
$headers = array(
'Authorization' => 'test-secret-key-faef953531d6488cb52f394ba19a0ee8',
'Content-Type' => 'application/json'
);
$body = array
{
"order": {
"items": [
{
"reference": "string",
"name": "string",
"quantity": 0,
"unit": "string",
"unitPrice": 0,
"taxRate": 0,
"taxAmount": 0,
"grossTotalAmount": 0,
"netTotalAmount": 0
}
],
"amount": 0,
"currency": "string",
"reference": "string"
},
"checkout": {
"url": "string",
"integrationType": "string",
"returnUrl": "string",
"cancelUrl": "string",
"consumer": {
"reference": "string",
"email": "string",
"shippingAddress": {
"addressLine1": "string",
"addressLine2": "string",
"postalCode": "string",
"city": "string",
"country": "string"
},
"phoneNumber": {
"prefix": "string",
"number": "string"
},
"privatePerson": {
"firstName": "string",
"lastName": "string"
},
"company": {
"name": "string",
"contact": {
"firstName": "string",
"lastName": "string"
}
}
},
"termsUrl": "string",
"merchantTermsUrl": "string",
"shippingCountries": [
{
"countryCode": "string"
}
],
"shipping": {
"countries": [
{
"countryCode": "string"
}
],
"merchantHandlesShippingCost": true,
"enableBillingAddress": true
},
"consumerType": {
"default": "string",
"supportedTypes": [
"string"
]
},
"charge": true,
"publicDevice": true,
"merchantHandlesConsumerData": true,
"appearance": {
"displayOptions": {
"showMerchantName": true,
"showOrderSummary": true
},
"textOptions": {
"completePaymentButtonText": "string"
}
},
"countryCode": "string"
},
"merchantNumber": "string",
"notifications": {
"webHooks": [
{
"eventName": "string",
"url": "string",
"authorization": "string",
"headers": null
}
]
},
"subscription": {
"subscriptionId": "d079718b-ff63-45dd-947b-4950c023750f",
"endDate": "2019-08-24T14:15:22Z",
"interval": 0
},
"unscheduledSubscription": {
"create": true,
"unscheduledSubscriptionId": "92143051-9e78-40af-a01f-245ccdcd9c03"
},
"paymentMethodsConfiguration": [
{
"name": "string",
"enabled": true
}
],
"paymentMethods": [
{
"name": "string",
"fee": {
"reference": "string",
"name": "string",
"quantity": 0,
"unit": "string",
"unitPrice": 0,
"taxRate": 0,
"taxAmount": 0,
"grossTotalAmount": 0,
"netTotalAmount": 0
}
}
],
"myReference": "string"
}
$response = wp_remote_post($url, array('headers' => $headers, 'body' => json_encode($body)));
$response_body = wp_remote_retrieve_body($response);
$response_data = json_decode($response_body, true);
// Redirect to payment page
if (isset($response_data['hostedPaymentPageUrl'])) {
wp_redirect($response_data['hostedPaymentPageUrl']);
exit;
}
}
}
}
Post Views: 10