Skip to content

Instantly share code, notes, and snippets.

@aaronroberson
Created June 19, 2014 03:38
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 aaronroberson/fa10ff91ec5cdf1b3111 to your computer and use it in GitHub Desktop.
Save aaronroberson/fa10ff91ec5cdf1b3111 to your computer and use it in GitHub Desktop.
Geekwise Day 12 Assets
(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);
$scope.checkout = function() {
CartService.checkout();
}
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();
}
<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