-
Notifications
You must be signed in to change notification settings - Fork 75
Introduce verification-doc component with 4 states #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
106 changes: 106 additions & 0 deletions
106
app/components/payments/funds-recipient/identity-document-file-upload.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import Ember from 'ember'; | ||
| import EmberUploader from 'ember-uploader'; | ||
| import ENV from 'code-corps-ember/config/environment'; | ||
|
|
||
| const { | ||
| computed, | ||
| get, | ||
| getProperties, | ||
| isEmpty | ||
| } = Ember; | ||
|
|
||
| const { Uploader } = EmberUploader; | ||
|
|
||
| /** | ||
| * `payments/funds-recipient/identity-document-file-upload` provides a file input | ||
| * for uploading an identity verification document to stripe. | ||
| * | ||
| * | ||
| * @class identity-document-file-upload | ||
| * @module Component | ||
| * @extends EmberUploader.FileField | ||
| */ | ||
| export default EmberUploader.FileField.extend({ | ||
| classNames: ['identity-document-file-upload'], | ||
|
|
||
| /** | ||
| * Object containing additional properties to be passed | ||
| * in as part of the form data being uploaded | ||
| * @type {Object} | ||
| */ | ||
| additionalUploadData: { | ||
| // required to authorize the upload request | ||
| key: ENV.stripe.publishableKey, | ||
| purpose: 'identity_document' | ||
| }, | ||
|
|
||
| maxFileSize: 1024 * 1024 * 8, // 8mb | ||
| multiple: false, | ||
| supportedFileTypes: ['image/jpeg', 'image/jpg', 'image/png'], | ||
| url: 'https://uploads.stripe.com/v1/files', | ||
|
|
||
| /** | ||
| * A computed property containing settings for the ajax request | ||
| * Used to set stripe account id in the request header | ||
| * @return {Object} | ||
| */ | ||
| ajaxSettings: computed('stripeConnectAccount', function() { | ||
| let headers = { | ||
| 'Stripe-Account': get(this, 'stripeConnectAccount.idFromStripe') | ||
| }; | ||
|
|
||
| return { headers }; | ||
| }), | ||
|
|
||
| /** | ||
| * Triggers when the file selection for the rendered file input changes | ||
| * @param {[File]} files An array of files selected by the user. | ||
| * Since the `multiple` setting is set to false, only 1 file | ||
| * is in the array. | ||
| */ | ||
| filesDidChange(files) { | ||
| if (!isEmpty(files) && this._validate(files[0])) { | ||
| this._performUpload(files[0]); | ||
| } | ||
| }, | ||
|
|
||
| _validate({ size, type }) { | ||
| let { maxFileSize, supportedFileTypes } = getProperties(this, 'maxFileSize', 'supportedFileTypes'); | ||
| let isValid = (size <= maxFileSize) && (supportedFileTypes.indexOf(type) >= 0); | ||
|
|
||
| if (!isValid) { | ||
| this.sendAction('validationError'); | ||
| } | ||
|
|
||
| return isValid; | ||
| }, | ||
|
|
||
| _performUpload(file) { | ||
| this.sendAction('uploadStarted'); | ||
|
|
||
| let params = getProperties(this, 'url', 'ajaxSettings'); | ||
| let uploader = Uploader.create(params); | ||
|
|
||
| uploader.on('progress', (event) => this._handleUploadProgress(event)); | ||
|
|
||
| let additionalUploadData = get(this, 'additionalUploadData'); | ||
|
|
||
| uploader.upload(file, additionalUploadData) | ||
| .then((event) => this._handleUploadDone(event)) | ||
| .catch((reason) => this._handleUploadError(reason)); | ||
| }, | ||
|
|
||
| // error handlers | ||
|
|
||
| _handleUploadDone({ id }) { | ||
| this.sendAction('uploadDone', id); | ||
| }, | ||
|
|
||
| _handleUploadError(reason) { | ||
| this.sendAction('uploadError', reason); | ||
| }, | ||
|
|
||
| _handleUploadProgress(event) { | ||
| this.sendAction('uploadProgress', event.percent); | ||
| } | ||
| }); |
46 changes: 46 additions & 0 deletions
46
app/components/payments/funds-recipient/verification-document.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import Ember from 'ember'; | ||
|
|
||
| const { | ||
| Component, | ||
| computed, | ||
| get, | ||
| set | ||
| } = Ember; | ||
|
|
||
| const VALIDATION_ERROR = 'The file you selected is invalid. Only .jpg and .png images of up to 8mb in size are supported.'; | ||
| const UPLOAD_ERROR = 'There was a problem with uploading your file. Please try again.'; | ||
|
|
||
| export default Component.extend({ | ||
| classNames: ['verification-document'], | ||
| status: computed.alias('stripeConnectAccount.verificationDocumentStatus'), | ||
|
|
||
| progressPercentage: 0, | ||
| progressMessage: computed('progressPercentage', function() { | ||
| let percentage = get(this, 'progressPercentage'); | ||
| return `Uploading... ${percentage}`; | ||
| }), | ||
|
|
||
| onUploadStarted() { | ||
| set(this, 'isUploading', true); | ||
| set(this, 'error', null); | ||
| }, | ||
|
|
||
| onUploadProgress(percentage) { | ||
| set(this, 'progressPercentage', percentage); | ||
| }, | ||
|
|
||
| onUploadDone(stripeFileUploadId) { | ||
| set(this, 'isUploading', false); | ||
| let onVerificationDocumentSubmitted = get(this, 'onVerificationDocumentSubmitted'); | ||
| onVerificationDocumentSubmitted(stripeFileUploadId); | ||
| }, | ||
|
|
||
| onUploadError() { | ||
| set(this, 'isUploading', false); | ||
| set(this, 'error', UPLOAD_ERROR); | ||
| }, | ||
|
|
||
| onValidationError() { | ||
| set(this, 'error', VALIDATION_ERROR); | ||
| } | ||
| }); |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also alpha-order here.