JS Error in Cloudflare Workers

Hi, I’m new to Cloudflare Workers. How do I add the below JavaScript into Cloudflare Workers? It shows me an error.

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>

var merchant_id = 'xxxxxxxxxxxxx';
var secretkey = 'xxxxxxxxxxx';

function pay_senangpay(name,email,phone,amount,type,order_id){

var hash = CryptoJS.HmacSHA256(secretkey.concat(type,amount,order_id), secretkey);

var url = "https://app.senangpay.my/payment/".concat(merchant_id);
var form = $('<form action="' + url + '" method="post">' +
'<input name="detail" value="' + type + '" />' +
'<input name="amount" value="' + amount + '" />' +
'<input name="order_id" value="' + order_id + '" />' +
'<input name="name" value="' + name + '" />' +
'<input name="email" value="' + email + '" />' +
'<input name="phone" value="' + phone + '" />' +
'<input name="hash" value="' + hash + '" />' +

Thank you very much.

This looks like a client-side (browser) JavaScript code. What are you trying to achieve?

1 Like

I’m using SaaS cart system which currently doesn’t support my local payment gateway (SenangPay). They suggest I write a Javascript on Cloudflare Workers, then the system will POST the order details there. This is make my customers make payment thru SenangPay.

The Javascript I have shown is given by SenangPay.

First of all, please redact the merchant_id and secretkey from your initial post so it’s not visible to the public.

Secondly, I would recommend you hire a developer or professional service partner to write (or convert) the code for you.

The code that you provide certainly does not look like Cloudflare Workers code.

Thanks for your advise, Eric. Do you know any person who has knowledge in Cloudflare Workers and good in Javascript in Malaysia? Or will you accept offer XD?

I won’t say that I’m an expert in Cloudflare Workers, but we do have few developers in our company.

Can you please contact us by filling up the contact form:

(Yes, we are based in Malaysia)

Thank you very much Eric!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.