Created
June 19, 2014 03:38
-
-
Save aaronroberson/fa10ff91ec5cdf1b3111 to your computer and use it in GitHub Desktop.
Geekwise Day 12 Assets
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
(function(angular) { | |
"use strict"; | |
var app = angular.module('MyStore', ['ngCookies', 'ngMessages', 'ui.router']); | |
app.value('config', { | |
/* Create a merchant account and add the seller email below: | |
* https://www.paypal.com/webapps/mpp/merchant | |
*/ | |
paypal: { | |
merchantID: 'aaronaroberson@gmail.com' | |
} | |
}); | |
})(window.angular); |
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
$scope.checkout = function() { | |
CartService.checkout(); | |
} |
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
checkout: function() { | |
/* PayPal: www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside */ | |
var form = $('<form/></form>'); | |
var data = { | |
cmd: "_cart", | |
business: config.paypal.merchantID, | |
upload: "1", | |
rm: "2", | |
charset: "utf-8", | |
currency_code: 'USD' | |
}; | |
var counter = 0; | |
angular.forEach(items, function(item, key) { | |
counter += 1; | |
data["item_number_" + counter] = item.id; | |
data["item_name_" + counter] = item.title; | |
data["quantity_" + counter] = item.quantity; | |
data["amount_" + counter] = cart.getItemPrice(item); | |
}); | |
form.attr("action", "https://www.paypal.com/cgi-bin/webscr"); | |
form.attr("method", "POST"); | |
form.attr("style", "display:none;"); | |
angular.forEach(data, function(value, name) { | |
if (value != null) { | |
var input = $("<input></input>").attr("type", "hidden").attr("name", name).val(value); | |
form.append(input); | |
} | |
}); | |
$("body").append(form); | |
// submit form | |
form.submit(); | |
form.remove(); | |
} |
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
<td> | |
<button | |
class="btn btn-block btn-link" | |
ng-click="checkout()" | |
ng-disabled="getItemCount() < 1"> | |
<img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" alt="Checkout using PayPal"/> | |
</button> | |
</td> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment