Skip to content

Instantly share code, notes, and snippets.

@ziyadparekh
Last active September 16, 2020 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziyadparekh/e55a196ad343850b65be8f9e00308078 to your computer and use it in GitHub Desktop.
Save ziyadparekh/e55a196ad343850b65be8f9e00308078 to your computer and use it in GitHub Desktop.
Safepay Integration
safepay.Button.render({
env: 'sandbox',
amount: 6800.57,
client: {
"sandbox": "sec_4f84abd2-0bae-4476-be6b-22c8c9e35133"
"production": "<YOUR_CLIENT_KEY>"
},
payment: function (data, actions) {
return actions.payment.create({
transaction: {
amount: 6800.57,
currency: 'PKR'
}
})
},
onCancel: function (data, actions) {
console.log(data)
console.log(actions)
},
onCheckout: function(data, actions) {
console.log(data)
console.log("You completed the payment!");
}
}, '#container');
@saeedahmed78
Copy link

How i get amount value by input

@ziyadparekh
Copy link
Author

You can use jquery, angular, or react or vanilla javascript (any framework really) to get the input value from your input field

@saeedahmed78
Copy link

saeedahmed78 commented May 20, 2020 via email

@ziyadparekh
Copy link
Author

Its pretty simple to implement but the implementation details are left to the developer since each developer will have a different way to get the value. What you can do is something similar to this:

Lets say you have an input on your page

<input type="text" id="my-input" />

Then with jQuery you can do something like this

var value = $("#my-input").value();

@saeedahmed78
Copy link

I did, i resolved this, the issue is when we get value from input this should be convert into parseJSON now working perfeclty, Thank You so much

@saeedahmed78
Copy link

can you please guid men how i customized safepay button or get input value on button click

@simondoul18
Copy link

function dopayment(amount){
$('#safepay-button-container').html('');
safepay.Button.render({
// Choose between "production" or "sandbox"
env: 'sandbox',
// The amount you wish you charge
amount: amount,
// The currency of the purchase
currency: "PKR",
// Your API Keys
client: {
"sandbox": "sec_8cac76dd-3cfb-403d-a2fb-beee3f3eb98e"
// "production": "e154d770af7bc7999e1baf56dae8cfea123be4abedaca07269b168dc6385da23"
},
payment: function (data, actions) {
return actions.payment.create({
transaction: {
amount: amount,
currency: 'PKR'
}
})
},
onCheckout: function(data, actions) {
console.log(data)
console.log("You completed the payment!");
}
}, '#safepay-button-container');
}

Call thw function on click event and pass amount

@HunzlaSheikh
Copy link

How can i use this code in angular typescript? It gives me error "cannot find name safepay"

@ziyadparekh
Copy link
Author

Hey you can check out this link for angular integration.
https://gist.github.com/ziyadparekh/62f04992b544566a9dc01181bf21b3e1

I don’t think we have typescript bindings at the moment though

@HunzlaSheikh
Copy link

Ok thanks. Got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment