Created
July 15, 2019 02:20
-
-
Save ziyadparekh/62f04992b544566a9dc01181bf21b3e1 to your computer and use it in GitHub Desktop.
Safepay Checkout Angular Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.9/angular.js"></script> | |
<script src="https://storage.googleapis.com/safepayobjects/api/safepay-checkout.min.js"></script> | |
<script> | |
window.safepay.Button.driver('angular', window.angular); | |
window.angular.module('app', ['safepay-button']).controller('appController', function($scope) { | |
$scope.opts = { | |
// Either sandbox or production | |
env: 'production', | |
amount: "6800.57", | |
currency: "PKR", | |
client: { | |
sandbox: '<YOUR SANDBOX API KEY>', | |
production: '<YOU PRODUCTION API KEY>' | |
}, | |
// Optionally pass along customer information to | |
// Safepay Checkout to prefill their data | |
customer: { | |
"first_name": "Ziyad", | |
"last_name": "Parekh", | |
"email": "[email protected]", | |
"phone": "03008287540" | |
}, | |
// Optionally pass along customer billing information | |
// to Safepay Checkout to prefill this data | |
billing: { | |
"name": "Default Address", | |
"address_1": "12/1 7th South Street DHA Phase 2", | |
"address_2": "", | |
"city": "Karachi", | |
"province": "Sindh", | |
"postal": "75500", | |
"country": "PK" | |
}, | |
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!"); | |
} | |
}; | |
}); | |
</script> | |
<body ng-app="app" ng-controller="appController"> | |
<safepay-button | |
env="opts.env" | |
amount="opts.amount" | |
currency="opts.currency" | |
client="opts.client" | |
customer="opts.customer" | |
billing="opts.billing" | |
payment="opts.payment" | |
commit="opts.commit" | |
on-cancel="opts.onCancel" | |
on-checkout="opts.onCheckout"> | |
</safepay-button> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I'm trying to use this with angular 9 but I can't set customer object for prefilled detail; I'd appreciate if you give an insight.