Uploading Files
The following methods allow to upload document.
This method requires a verification identifier, which you can obtain by creating submerchant using the PayU API.
Verification identifier.
Instance options.
Allows to create instance in developer mode which enables you to operate on a site that does not use HTTPS.
PayuDocumentForm instance.
Occurs when creating PayuDocumentForm instance when no verificationId parameter is specified or is empty.
Occurs on MarketplaceVerification instance creation when the protocol of the page, on which JS SDK is loaded, is not https and file, and the page is not loaded from localhost: 127.0.0.1 or 0.0.0.0. During the implementation process you can enable developer mode in the options parameter.
- Example
const documentForm = PayuDocumentForm({verificationId: 'VERIFICATION_ID'});
Examples
- Preview
- HTML
- javascript
- CSS
<script type="text/javascript" src="https://merch-prod.snd.payu.com/javascript/sdk"></script>
<section class="container">
<div class="form-container">
<aside>Important document</aside>
<div id="payuDocumentUpload" class="payu-document-upload-button"></div>
<div id="responseUpload"></div>
</div>
<button id="uploadButton" onclick="df.upload()">Upload</button>
</section>
window.addEventListener('DOMContentLoaded', function () {
const df = PayuDocumentForm({verificationId: 'marketplace-verification-id'}, {dev: true});
df
.on('ready', () => {
console.log('Ready');
});
df
.on('select', (response) => {
if (response.status === 'SUCCESS') {
document.getElementById('responseUpload').innerText = 'File: ' + response.body.name + ', size: ' + response.body.size + ', type: ' + response.body.type;
} else {
alert('Error. ' + JSON.stringify(response.error));
}
});
df
.on('upload', (response) => {
if (response.status === 'SUCCESS') {
alert('File loaded. fileId=[' + response.body.fileId + '], verificationId=[' + response.body.verificationId + ']');
} else {
alert('Error. ' + JSON.stringify(response.error));
}
});
const documentFormOptions = {
title: 'Add or drop file here'
};
df.render('#payuDocumentUpload', documentFormOptions);
});
.container * {
font-family: Arial, Helvetica, sans-serif;
}
.container {
text-align: center;
width: 420px;
margin: 20px auto 10px;
display: block;
border-radius: 5px;
box-sizing: border-box;
}
.form-container {
width: 100%;
margin: 0 auto;
border-radius: 6px;
padding: 10px;
background: rgb(2, 0, 60);
text-align: left;
box-sizing: border-box;
}
.form-container aside, .form-container #responseUpload {
padding-bottom: 6px;
font-size: 14px;
color: #ffffff;
}
.payu-document-upload-button {
background: #438F29;
cursor: pointer;
width: 100%;
height: 40px;
border: 1px solid white;
border-radius: 5px;
color: rgb(2, 0, 60);
font-size: 22px;
}
#uploadButton {
border: none;
background: #438F29;
padding: 8px 15px;
margin: 10px auto;
cursor: pointer;
}
Methods
querySelectorAll
.Add file
will be displayed.appendChild
method is not implemented or it is an input element).- Example
documentForm.render('#documentForm', {title: 'Choose a file or drag it here.'});
- Example
documentForm.upload();
Possible Values | |
---|---|
ready | Emitted when the form is displayed. |
select | Emitted when a file is selected on a secure form. |
upload | Emitted when a file is uploaded to the server. |
- Example
documentForm
.on('ready', function() {
// form ready
});
documentForm
.on('select', function(body) {
// file selected
});
documentForm
.on('upload', function(body) {
// file uploaded
});
Events
Forms emit events to which you can attach your own callback using the on method.
Field | Description |
---|---|
status | File upload status:
|
body | Only for SUCCESS status. This object contains information about the uploaded file. Available fields are:
|
error | Only for ERROR status. Object with messages array which contains error information. Details can be found in Błędy section. |
correlationId | Only for ERROR status. |
Field | Description |
---|---|
status | File upload status:
|
body | Only for SUCCESS status. This object contains information about the uploaded file. Available fields are:
|
error | Only for ERROR status. Object with messages array which contains error information. Details can be found in Błędy section. |
correlationId | Only for ERROR status. |
Errors
error
object contains an array of objects (messages
), which contain detailed information about the errors.
Field | Description |
---|---|
code | KError code. |
message | Error description in english. |
parameters | Object containing changeable error fragments. |
Field | Linked Event | Description |
---|---|---|
error.file.too.large | select | The size of the selected file is too big. Maximum file size is 10MB. Detailed information can be found in parameters object. |
error.file.invalid.type | select | The selected file type is invalid. Supported file types: pdf, jpg, tiff, png, bmp. Detailed information can be found in parameters object. |
error.file.not.selected | upload | File was not selected. |
error.file.read.abort | upload | The loading of files has been aborted. |
error.file.read.error | upload | An error has occured while loading a file. |
error.network | upload | A network communication error has occurred. Information about the cause of the error can be found in parameters object in the error field. |
- Example
{
"status": "ERROR",
"correlationId": "",
"error": {
"messages": [
{
"code": "error.file.too.large",
"parameters": {
"error":"File is larger than 10485760 bytes",
"file":"fileName.pdf"
},
"message": "File too large"
}
]
}
}