forked from aarondunn/bugkick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamurai.php
52 lines (51 loc) · 1.96 KB
/
samurai.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php die; ?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Samurai API test</title>
<script type="text/javascript" src="https://samurai.feefighters.com/assets/api/samurai.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
/*<![CDATA[*/
google.load('jquery', '1');
/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
Samurai.init({
merchant_key: '952695745c65d49afe12bd78',
//merchant_key: 'e84803ad9cf61cb21405ab79',
sandbox: true
});
var form = $('#payment-form form').get(0);
var errorHandler = new Samurai.PaymentErrorHandler(form);
// Bind to the samurai.payment event, which lets you know when a payment_method
// has been created and gives you a payment_method_token to use in the transaction
Samurai.on('form', 'payment', function(event, data) {
// Send the payment_method to the server and let it create the transaction
$.post('/payment/createTransaction', data.payment_method, function(data) {
// Parse the transaction response JSON and convert it to an object
var transaction = $.parseJSON(data).transaction;
if(transaction.success) {
// Update the page to display the results
$('form').children('.results').html(
'<h3>Your purchase is complete!</h3><h4>'
+ transaction.payment_method.payment_method.first_name
+ ' ' + transaction.payment_method.payment_method.last_name
+ ': $' + transaction.amount +' - ' + transaction.description + '</h4>'
);
Samurai.trigger('form', 'completed');
} else {
// Let the error handler scan the response object for errors,
// then display these errors
Samurai.PaymentErrorHandler.for(form).handleErrorsFromResponse(transaction);
}
});
});
/*]]>*/
</script>
</head>
<body>
<div id="payment-form" data-samurai-payment-form class="samurai-standard samurai-placeholders"></div>
</body>
</html>