| 15 | ] |
| 16 | |
| 17 | const makeButton = function (options) { |
| 18 | const { buttonContainerID, product, onPaymentStarted, onPaymentComplete, description } = options |
| 19 | return typeof paypal !== 'undefined' && paypal !== null ? paypal.Button.render(_.assign({ |
| 20 | env: application.isProduction() ? 'production' : 'sandbox', // sandbox | production |
| 21 | |
| 22 | locale: (() => { |
| 23 | const preferredLanguage = (me.get('preferredLanguage') || 'en-US').replace('-', '_') |
| 24 | if (Array.from(acceptableLanguages).includes(preferredLanguage)) { return preferredLanguage } else { return 'en_US' } |
| 25 | } |
| 26 | )(), |
| 27 | // Style the button: https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/customize-button/ |
| 28 | style: { |
| 29 | size: 'responsive', |
| 30 | shape: 'rect' |
| 31 | }, |
| 32 | |
| 33 | // PayPal Client IDs - replace with your own |
| 34 | // Create a PayPal app: https://developer.paypal.com/developer/applications/create |
| 35 | client: { |
| 36 | sandbox: 'AcS4lYmr_NwK_TTWSJzOzTh01tVDceWDjB_N7df3vlvW4alTV_AF2rtmcaZDh0AmnTcOof9gKyLyHkm-', |
| 37 | production: 'AXP_Bf0KAz8_HV0X6EFSu9cMAXcb7AoaRAYqrfPKBxnl5zTWEt5JzMTMJdXiCjK29AFlp_zAdP4zefRD' |
| 38 | }, |
| 39 | // Show the buyer a 'Pay Now' button in the checkout flow |
| 40 | commit: true, |
| 41 | // payment() is called when the button is clicked |
| 42 | payment (data, actions) { |
| 43 | // Make a call to the REST api to create the payment |
| 44 | onPaymentStarted() |
| 45 | const paymentData = { |
| 46 | payment: { |
| 47 | transactions: [ |
| 48 | { |
| 49 | amount: { total: product.adjustedPriceStringNoSymbol(), currency: 'USD' }, |
| 50 | item_list: { |
| 51 | items: [{ |
| 52 | sku: product.id, |
| 53 | name: product.translateName(), |
| 54 | quantity: 1, |
| 55 | price: product.adjustedPriceStringNoSymbol(), |
| 56 | currency: 'USD' |
| 57 | }] |
| 58 | }, |
| 59 | description // Is this what shows up on their credit card, or so? TODO: Translate? |
| 60 | } |
| 61 | ] |
| 62 | } |
| 63 | } |
| 64 | return actions.payment.create(paymentData) |
| 65 | }, |
| 66 | // onAuthorize() is called when the buyer approves the payment |
| 67 | onAuthorize (data, actions) { |
| 68 | // Pass the payment info along, so we can tell the server to execute it |
| 69 | return actions.payment.get().then(payment => onPaymentComplete(payment)) |
| 70 | } |
| 71 | }, options.payPalOptions), buttonContainerID) : undefined |
| 72 | } |
| 73 | |
| 74 | module.exports = { |