Last active
January 13, 2017 22:55
-
-
Save mitchlloyd/9f4d5d42e6435d52b40c5d46ac632818 to your computer and use it in GitHub Desktop.
Wrap Third Party APIs - Adapter
This file contains hidden or 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
/* globals Stripe, ApplePaySession*/ | |
import Ember from 'ember'; | |
const { Service, RSVP, run } = Ember; | |
export default Service.extend({ | |
charge(paymentRequest) { | |
return new RSVP.Promise(function(resolve, reject) { | |
let runLoopResolve = (...args) => run.join(() => resolve(...args)); | |
let runLoopReject = (...args) => run.join(() => reject(...args)); | |
Stripe.applePay.buildSession(paymentRequest, buildSuccessHandler(runLoopResolve), runLoopReject).begin(); | |
}); | |
} | |
}); | |
function buildSuccessHandler(resolve) { | |
return function successHandlerResolution(result, completion) { | |
resolve({ | |
result, | |
notify: { | |
success() { | |
completion(ApplePaySession.STATUS_SUCCESS); | |
}, | |
failure() { | |
completion(ApplePaySession.STATUS_FAILURE); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment