|
| 1 | +<?php |
| 2 | +namespace GlobalPayments\Api\Builders; |
| 3 | + |
| 4 | +use GlobalPayments\Api\ServicesContainer; |
| 5 | +use GlobalPayments\Api\Entities\PayFac\BankAccountData; |
| 6 | +use GlobalPayments\Api\Entities\PayFac\BeneficialOwnerData; |
| 7 | +use GlobalPayments\Api\Entities\PayFac\BusinessData; |
| 8 | +use GlobalPayments\Api\Entities\PayFac\SignificantOwnerData; |
| 9 | +use GlobalPayments\Api\Entities\PayFac\ThreatRiskData; |
| 10 | +use GlobalPayments\Api\Entities\PayFac\UserPersonalData; |
| 11 | +use GlobalPayments\Api\Entities\Enums\TransactionType; |
| 12 | +use GlobalPayments\Api\Entities\Enums\TransactionModifier; |
| 13 | +use GlobalPayments\Api\Entities\Exceptions\BuilderException; |
| 14 | + |
| 15 | +class PayFacBuilder extends BaseBuilder |
| 16 | +{ |
| 17 | + public $transactionType; |
| 18 | + public $transactionModifier; |
| 19 | + public $bankAccountData; |
| 20 | + public $beneficialOwnerData; |
| 21 | + public $businessData; |
| 22 | + public $significantOwnerData; |
| 23 | + public $threatRiskData; |
| 24 | + public $userPersonalData; |
| 25 | + public $creditCardInformation; |
| 26 | + public $achInformation; |
| 27 | + public $secondaryBankInformation; |
| 28 | + public $grossBillingInformation; |
| 29 | + public $accountNumber; |
| 30 | + public $password; |
| 31 | + public $accountPermissions; |
| 32 | + public $negativeLimit; |
| 33 | + public $renewalAccountData; |
| 34 | + public $uploadDocumentData; |
| 35 | + public $singleSignOnData; |
| 36 | + public $amount; |
| 37 | + public $receivingAccountNumber; |
| 38 | + public $allowPending; |
| 39 | + public $ccAmount; |
| 40 | + public $requireCCRefund; |
| 41 | + public $transNum; |
| 42 | + public $flashFundsPaymentCardData; |
| 43 | + public $externalId; |
| 44 | + public $sourceEmail; |
| 45 | + |
| 46 | + const UPLOAD_FILE_TYPES = [ |
| 47 | + 'tif', 'tiff', 'bmp', 'jpg', 'jpeg', 'gif', 'png', 'doc', 'docx' |
| 48 | + ]; |
| 49 | + |
| 50 | + /** |
| 51 | + * |
| 52 | + * {@inheritdoc} |
| 53 | + * |
| 54 | + * @param TransactionType $type |
| 55 | + * Request transaction type |
| 56 | + * |
| 57 | + * @return |
| 58 | + */ |
| 59 | + public function __construct($type) |
| 60 | + { |
| 61 | + parent::__construct($type); |
| 62 | + $this->transactionType = $type; |
| 63 | + $this->transactionModifier = TransactionModifier::NONE; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Executes the builder against the gateway. |
| 68 | + * |
| 69 | + * @return mixed |
| 70 | + */ |
| 71 | + public function execute(string $configName = 'default') |
| 72 | + { |
| 73 | + parent::execute($configName); |
| 74 | + |
| 75 | + $client = ServicesContainer::instance()->getPayFac($configName); |
| 76 | + return $client->processPayFac($this); |
| 77 | + } |
| 78 | + |
| 79 | + protected function setupValidations() |
| 80 | + { |
| 81 | + $this->validations->of( |
| 82 | + TransactionType::CREATE_ACCOUNT |
| 83 | + ) |
| 84 | + ->with(TransactionModifier::NONE) |
| 85 | + ->check('beneficialOwnerData')->isNotNull() |
| 86 | + ->check('businessData')->isNotNull() |
| 87 | + ->check('userPersonalData')->isNotNull() |
| 88 | + ->check('creditCardInformation')->isNotNull(); |
| 89 | + |
| 90 | + $this->validations->of( |
| 91 | + TransactionType::EDIT | |
| 92 | + TransactionType::RESET_PASSWORD | |
| 93 | + TransactionType::RENEW_ACCOUNT | |
| 94 | + TransactionType::UPDATE_OWNERSHIP_DETAILS | |
| 95 | + TransactionType::DEACTIVATE | |
| 96 | + TransactionType::UPLOAD_CHARGEBACK_DOCUMENT | |
| 97 | + TransactionType::OBTAIN_SSO_KEY | |
| 98 | + TransactionType::UPDATE_BANK_ACCOUNT_OWNERSHIP | |
| 99 | + TransactionType::ADD_FUNDS | |
| 100 | + TransactionType::SWEEP_FUNDS | |
| 101 | + TransactionType::ADD_CARD_FLASH_FUNDS | |
| 102 | + TransactionType::PUSH_MONEY_FLASH_FUNDS | |
| 103 | + TransactionType::SPEND_BACK | |
| 104 | + TransactionType::REVERSE_SPLITPAY | |
| 105 | + TransactionType::SPLIT_FUNDS | |
| 106 | + TransactionType::GET_ACCOUNT_BALANCE |
| 107 | + ) |
| 108 | + ->with(TransactionModifier::NONE) |
| 109 | + ->check('accountNumber')->isNotNull(); |
| 110 | + |
| 111 | + $this->validations->of( |
| 112 | + TransactionType::UPDATE_OWNERSHIP_DETAILS |
| 113 | + ) |
| 114 | + ->with(TransactionModifier::NONE) |
| 115 | + ->check('beneficialOwnerData')->isNotNull(); |
| 116 | + |
| 117 | + $this->validations->of( |
| 118 | + TransactionType::UPLOAD_CHARGEBACK_DOCUMENT |
| 119 | + ) |
| 120 | + ->with(TransactionModifier::NONE) |
| 121 | + ->check('uploadDocumentData')->isNotNull(); |
| 122 | + |
| 123 | + $this->validations->of( |
| 124 | + TransactionType::OBTAIN_SSO_KEY |
| 125 | + ) |
| 126 | + ->with(TransactionModifier::NONE) |
| 127 | + ->check('singleSignOnData')->isNotNull(); |
| 128 | + |
| 129 | + $this->validations->of( |
| 130 | + TransactionType::UPDATE_BANK_ACCOUNT_OWNERSHIP |
| 131 | + ) |
| 132 | + ->with(TransactionModifier::NONE) |
| 133 | + ->check('beneficialOwnerData')->isNotNull(); |
| 134 | + |
| 135 | + $this->validations->of( |
| 136 | + TransactionType::ADD_FUNDS | |
| 137 | + TransactionType::SWEEP_FUNDS | |
| 138 | + TransactionType::PUSH_MONEY_FLASH_FUNDS | |
| 139 | + TransactionType::SPEND_BACK | |
| 140 | + TransactionType::REVERSE_SPLITPAY | |
| 141 | + TransactionType::SPLIT_FUNDS |
| 142 | + ) |
| 143 | + ->with(TransactionModifier::NONE) |
| 144 | + ->check('amount')->isNotNull(); |
| 145 | + |
| 146 | + $this->validations->of(TransactionType::ADD_CARD_FLASH_FUNDS) |
| 147 | + ->with(TransactionModifier::NONE) |
| 148 | + ->check('flashFundsPaymentCardData')->isNotNull(); |
| 149 | + |
| 150 | + $this->validations->of(TransactionType::DISBURSE_FUNDS) |
| 151 | + ->with(TransactionModifier::NONE) |
| 152 | + ->check('receivingAccountNumber')->isNotNull(); |
| 153 | + |
| 154 | + $this->validations->of(TransactionType::SPEND_BACK) |
| 155 | + ->with(TransactionModifier::NONE) |
| 156 | + ->check('allowPending')->isNotNull() |
| 157 | + ->check('receivingAccountNumber')->isNotNull(); |
| 158 | + |
| 159 | + $this->validations->of(TransactionType::SPLIT_FUNDS) |
| 160 | + ->with(TransactionModifier::NONE) |
| 161 | + ->check('transNum')->isNotNull() |
| 162 | + ->check('receivingAccountNumber')->isNotNull(); |
| 163 | + |
| 164 | + $this->validations->of(TransactionType::REVERSE_SPLITPAY) |
| 165 | + ->with(TransactionModifier::NONE) |
| 166 | + ->check('transNum')->isNotNull() |
| 167 | + ->check('requireCCRefund')->isNotNull() |
| 168 | + ->check('ccAmount')->isNotNull(); |
| 169 | + |
| 170 | + } |
| 171 | + |
| 172 | + /* |
| 173 | + * Primary Bank Account Information – Optional. Used to add a bank account to which funds can be settled |
| 174 | + * |
| 175 | + * var Object GlobalPayments\Api\Entities\PayFac\BankAccountData; |
| 176 | + */ |
| 177 | + public function withBankAccountData(BankAccountData $bankAccountData) |
| 178 | + { |
| 179 | + $this->bankAccountData = $bankAccountData; |
| 180 | + return $this; |
| 181 | + } |
| 182 | + /* |
| 183 | + * Merchant Beneficiary Owner Information – Required for all merchants validating KYC based off of personal data |
| 184 | + * |
| 185 | + * var Object GlobalPayments\Api\Entities\PayFac\BeneficialOwnerData; |
| 186 | + */ |
| 187 | + public function withBeneficialOwnerData(BeneficialOwnerData $beneficialOwnerData) |
| 188 | + { |
| 189 | + $this->beneficialOwnerData = $beneficialOwnerData; |
| 190 | + return $this; |
| 191 | + } |
| 192 | + /* |
| 193 | + * Business Data – Required for business validated accounts. May also be required for personal validated accounts |
| 194 | + * by ProPay Risk Team |
| 195 | + * |
| 196 | + * var Object GlobalPayments\Api\Entities\PayFac\BusinessData; |
| 197 | + */ |
| 198 | + public function withBusinessData(BusinessData $businessData) |
| 199 | + { |
| 200 | + $this->businessData = $businessData; |
| 201 | + return $this; |
| 202 | + } |
| 203 | + /* |
| 204 | + * Significant Owner Information – May be required for some partners based on ProPay Risk decision |
| 205 | + * |
| 206 | + * var Object GlobalPayments\Api\Entities\PayFac\SignificantOwnerData; |
| 207 | + */ |
| 208 | + public function withSignificantOwnerData(SignificantOwnerData $significantOwnerData) |
| 209 | + { |
| 210 | + $this->significantOwnerData = $significantOwnerData; |
| 211 | + return $this; |
| 212 | + } |
| 213 | + /* |
| 214 | + * Threat Risk Assessment Information – May be required based on ProPay Risk Decision |
| 215 | + * |
| 216 | + * var Object GlobalPayments\Api\Entities\PayFac\ThreatRiskData; |
| 217 | + */ |
| 218 | + public function withThreatRiskData(ThreatRiskData $threatRiskData) |
| 219 | + { |
| 220 | + $this->threatRiskData = $threatRiskData; |
| 221 | + return $this; |
| 222 | + } |
| 223 | + |
| 224 | + /* |
| 225 | + * User / Merchant Personal Data |
| 226 | + * |
| 227 | + * var Object GlobalPayments\Api\Entities\PayFac\UserPersonalData; |
| 228 | + */ |
| 229 | + public function withUserPersonalData(UserPersonalData $userPersonalData) |
| 230 | + { |
| 231 | + $this->userPersonalData = $userPersonalData; |
| 232 | + return $this; |
| 233 | + } |
| 234 | + |
| 235 | + public function withCreditCardData($creditCardInformation) |
| 236 | + { |
| 237 | + $this->creditCardInformation = $creditCardInformation; |
| 238 | + return $this; |
| 239 | + } |
| 240 | + |
| 241 | + public function withACHData($achInformation) |
| 242 | + { |
| 243 | + $this->achInformation = $achInformation; |
| 244 | + return $this; |
| 245 | + } |
| 246 | + |
| 247 | + public function withSecondaryBankAccountData($secondaryBankInformation) |
| 248 | + { |
| 249 | + $this->secondaryBankInformation = $secondaryBankInformation; |
| 250 | + return $this; |
| 251 | + } |
| 252 | + |
| 253 | + public function withGrossBillingSettleData($grossBillingInformation) |
| 254 | + { |
| 255 | + $this->grossBillingInformation = $grossBillingInformation; |
| 256 | + return $this; |
| 257 | + } |
| 258 | + |
| 259 | + /* |
| 260 | + * The ProPay account to be updated |
| 261 | + * |
| 262 | + * var int |
| 263 | + */ |
| 264 | + public function withAccountNumber($accountNumber) |
| 265 | + { |
| 266 | + $this->accountNumber = $accountNumber; |
| 267 | + return $this; |
| 268 | + } |
| 269 | + |
| 270 | + /* |
| 271 | + * Temporary password which will allow a onetime login to ProPay’s website. Must be at least eight characters. |
| 272 | + * Must not contain part or the entire first or last name. Must contain at least one capital letter, |
| 273 | + * one lower case letter, and either one symbol or one number |
| 274 | + * |
| 275 | + * var string |
| 276 | + */ |
| 277 | + public function withPassword($password) |
| 278 | + { |
| 279 | + $this->password = $password; |
| 280 | + return $this; |
| 281 | + } |
| 282 | + |
| 283 | + public function withAccountPermissions($accountPermissions) |
| 284 | + { |
| 285 | + $this->accountPermissions = $accountPermissions; |
| 286 | + return $this; |
| 287 | + } |
| 288 | + |
| 289 | + /* |
| 290 | + * amount must be greater than zero |
| 291 | + */ |
| 292 | + public function withNegativeLimit($negativeLimit) |
| 293 | + { |
| 294 | + $this->negativeLimit = $negativeLimit; |
| 295 | + return $this; |
| 296 | + } |
| 297 | + |
| 298 | + public function withRenewalAccountData($renewalAccountData) |
| 299 | + { |
| 300 | + $this->renewalAccountData = $renewalAccountData; |
| 301 | + return $this; |
| 302 | + } |
| 303 | + |
| 304 | + |
| 305 | + /* |
| 306 | + * Document details |
| 307 | + * |
| 308 | + * var GlobalPayments\Api\Entities\PayFac\UploadDocumentData |
| 309 | + */ |
| 310 | + public function withUploadDocumentData($uploadDocumentData) |
| 311 | + { |
| 312 | + //file validations |
| 313 | + if (!file_exists($uploadDocumentData->documentLocation)) { |
| 314 | + throw new BuilderException('File not found!'); |
| 315 | + } elseif (filesize($uploadDocumentData->documentLocation) > 5000000) { |
| 316 | + throw new BuilderException('Max file size 5MB exceeded'); |
| 317 | + } |
| 318 | + |
| 319 | + $fileType = pathinfo($uploadDocumentData->documentLocation, PATHINFO_EXTENSION); |
| 320 | + if (!in_array($fileType, self::UPLOAD_FILE_TYPES)) { |
| 321 | + throw new BuilderException('File type is not supported.'); |
| 322 | + } |
| 323 | + |
| 324 | + $this->uploadDocumentData = $uploadDocumentData; |
| 325 | + return $this; |
| 326 | + } |
| 327 | + |
| 328 | + public function withSingleSignOnData($singleSignOnData) |
| 329 | + { |
| 330 | + $this->singleSignOnData = $singleSignOnData; |
| 331 | + return $this; |
| 332 | + } |
| 333 | + |
| 334 | + public function withAmount($amount) |
| 335 | + { |
| 336 | + $this->amount = $amount; |
| 337 | + return $this; |
| 338 | + } |
| 339 | + |
| 340 | + public function withReceivingAccountNumber($receivingAccountNumber) |
| 341 | + { |
| 342 | + $this->receivingAccountNumber = $receivingAccountNumber; |
| 343 | + return $this; |
| 344 | + } |
| 345 | + |
| 346 | + public function withAllowPending($allowPending) |
| 347 | + { |
| 348 | + $this->allowPending = $allowPending; |
| 349 | + return $this; |
| 350 | + } |
| 351 | + |
| 352 | + public function withCCAmount($ccAmount) |
| 353 | + { |
| 354 | + $this->ccAmount = $ccAmount; |
| 355 | + return $this; |
| 356 | + } |
| 357 | + |
| 358 | + public function withRequireCCRefund($requireCCRefund) |
| 359 | + { |
| 360 | + $this->requireCCRefund = $requireCCRefund; |
| 361 | + return $this; |
| 362 | + } |
| 363 | + |
| 364 | + public function withTransNum($transNum) |
| 365 | + { |
| 366 | + $this->transNum = $transNum; |
| 367 | + return $this; |
| 368 | + } |
| 369 | + |
| 370 | + public function withFlashFundsPaymentCardData($flashFundsPaymentCardData) |
| 371 | + { |
| 372 | + $this->flashFundsPaymentCardData = $flashFundsPaymentCardData; |
| 373 | + return $this; |
| 374 | + } |
| 375 | + |
| 376 | + public function withExternalId($externalId) |
| 377 | + { |
| 378 | + $this->externalId = $externalId; |
| 379 | + return $this; |
| 380 | + } |
| 381 | + |
| 382 | + public function withSourceEmail($sourceEmail) |
| 383 | + { |
| 384 | + $this->sourceEmail = $sourceEmail; |
| 385 | + return $this; |
| 386 | + } |
| 387 | +} |
0 commit comments