-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Provide Dispute Evidence API endpoint.
- Loading branch information
Showing
8 changed files
with
206 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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,101 @@ | ||
<?php | ||
|
||
namespace Srmklive\PayPal\Services; | ||
|
||
use GuzzleHttp\Psr7\MimeType; | ||
|
||
class VerifyDocuments | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static $dispute_evidence_types = [ | ||
'application/pdf', | ||
'image/gif', | ||
'image/jpeg', | ||
'image/png', | ||
]; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected static $dispute_evidence_file_size = 10; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected static $dispute_evidences_size = 50; | ||
|
||
/** | ||
* Get Mime type from filename. | ||
* | ||
* @param string $file | ||
* | ||
* @return string | ||
*/ | ||
public static function getMimeType($file) | ||
{ | ||
return MimeType::fromFilename($file); | ||
} | ||
|
||
/** | ||
* Check if the evidence file being submitted mime type is valid. | ||
* | ||
* @param array $files | ||
* | ||
* @return bool | ||
*/ | ||
public static function isValidEvidenceFile(array $files) | ||
{ | ||
$validFile = true; | ||
$validSize = true; | ||
$total_size = 0; | ||
|
||
self::setFilesSize(); | ||
|
||
foreach ($files as $file) { | ||
$mime_type = self::getMimeType($file); | ||
|
||
if (!in_array($mime_type, self::$dispute_evidence_types)) { | ||
$validFile = false; | ||
break; | ||
} | ||
|
||
$size = filesize($file); | ||
|
||
if ($size > self::$dispute_evidence_file_size) { | ||
$validSize = false; | ||
break; | ||
} | ||
|
||
$total_size += $size; | ||
|
||
if ($size > self::$dispute_evidences_size) { | ||
$validSize = false; | ||
break; | ||
} | ||
} | ||
|
||
if (($validFile === false) || ($validSize === false)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Check file size. | ||
* | ||
* @param int $bytes | ||
* @param int $decimals | ||
* | ||
* @return array | ||
*/ | ||
protected static function setFilesSize() | ||
{ | ||
$size_in_bytes = pow(1024, 2); | ||
|
||
self::$dispute_evidence_file_size *= $size_in_bytes; | ||
self::$dispute_evidences_size *= $size_in_bytes; | ||
Check failure on line 99 in src/Services/VerifyDocuments.php GitHub Actions / PHP 8.0
Check failure on line 99 in src/Services/VerifyDocuments.php GitHub Actions / PHP 7.4
Check failure on line 99 in src/Services/VerifyDocuments.php GitHub Actions / PHP 7.2
Check failure on line 99 in src/Services/VerifyDocuments.php GitHub Actions / PHP 7.3
Check failure on line 99 in src/Services/VerifyDocuments.php GitHub Actions / PHP 8.1
|
||
} | ||
} |
This file contains 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 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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.