{"id":1780,"date":"2025-06-09T10:21:51","date_gmt":"2025-06-09T10:21:51","guid":{"rendered":"https:\/\/mytreasurer.com.au\/?page_id=1780"},"modified":"2025-06-14T15:07:01","modified_gmt":"2025-06-14T15:07:01","slug":"1780-2","status":"publish","type":"page","link":"https:\/\/mytreasurer.com.au\/index.php\/1780-2\/","title":{"rendered":"test payment"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<!-- Amount Input -->\n<label for=\"amount-input\">Amount (AUD):<\/label>\n<input type=\"number\" id=\"amount-input\" min=\"0.01\" step=\"0.01\" placeholder=\"e.g. 10.00\" \/>\n\n<!-- SecurePay UI container for card details -->\n<div id=\"securepay-ui-container\"><\/div>\n\n<!-- Pay Now Button -->\n<button id=\"securepay-submit-btn\">Pay Now<\/button>\n\n<!-- SecurePay UI Component (sandbox) -->\n<script id=\"securepay-ui-js\" src=\"https:\/\/payments-stest.npe.auspost.zone\/v3\/ui\/client\/securepay-ui.min.js\"><\/script>\n\n<script>\n  \/\/ Initialize SecurePay UI\n  var mySecurePayUI = new securePayUI.init({\n    containerId: 'securepay-ui-container',\n    scriptId:    'securepay-ui-js',\n    clientId:    '0oaxb9i8P9vQdXTsn3l5',      \/\/ Replace with your sandbox clientId\n    merchantCode:'5AR0055',                   \/\/ Replace with your sandbox merchantCode\n    card: { \n      onTokeniseSuccess: function(tokenisedCard) {\n        const cardToken = tokenisedCard.singleUseTokenId || tokenisedCard.token;\n        \/\/ Get amount from input\n        const amountStr = document.getElementById('amount-input').value;\n        if (!amountStr || isNaN(amountStr) || parseFloat(amountStr) <= 0) {\n          alert('Please enter a valid amount.');\n          return;\n        }\n        const amountCents = Math.round(parseFloat(amountStr) * 100);\n\n        \/\/ AJAX to your server (admin-ajax.php)\n        fetch('\/wp-admin\/admin-ajax.php?action=securepay_charge', {\n          method: 'POST',\n          headers: { 'Content-Type': 'application\/json' },\n          body: JSON.stringify({ token: cardToken, amount: amountCents })\n        })\n        .then(response => response.json())\n        .then(data => {\n          if(data.success) {\n            alert('Payment successful! Receipt ID: ' + data.receipt);\n          } else {\n            alert('Payment failed: ' + data.error);\n          }\n        })\n        .catch(err => {\n          console.error('AJAX error:', err);\n          alert('Payment could not be processed. Please try again.');\n        });\n      },\n      onTokeniseError: function(errors) {\n        console.error('Tokenization error:', errors);\n        alert('Payment error: could not tokenize card. Please check details and try again.');\n      }\n    }\n  });\n\n  \/\/ Button click triggers SecurePay tokenization\n  document.getElementById('securepay-submit-btn').onclick = function(){\n    mySecurePayUI.tokenise();\n  };\n<\/script>\n\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Amount (AUD): Pay Now<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1780","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/pages\/1780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=1780"}],"version-history":[{"count":12,"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/pages\/1780\/revisions"}],"predecessor-version":[{"id":1799,"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/pages\/1780\/revisions\/1799"}],"wp:attachment":[{"href":"https:\/\/mytreasurer.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=1780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}