| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | namespace Worldline\Connect\Sdk\V1\Merchant\Payouts; |
| 7: | |
| 8: | use Worldline\Connect\Sdk\ApiResource; |
| 9: | use Worldline\Connect\Sdk\CallContext; |
| 10: | use Worldline\Connect\Sdk\Communication\ErrorResponseException; |
| 11: | use Worldline\Connect\Sdk\Communication\InvalidResponseException; |
| 12: | use Worldline\Connect\Sdk\Communication\ResponseClassMap; |
| 13: | use Worldline\Connect\Sdk\V1\ApiException; |
| 14: | use Worldline\Connect\Sdk\V1\AuthorizationException; |
| 15: | use Worldline\Connect\Sdk\V1\DeclinedPayoutException; |
| 16: | use Worldline\Connect\Sdk\V1\Domain\ApprovePayoutRequest; |
| 17: | use Worldline\Connect\Sdk\V1\Domain\CreatePayoutRequest; |
| 18: | use Worldline\Connect\Sdk\V1\Domain\FindPayoutsResponse; |
| 19: | use Worldline\Connect\Sdk\V1\Domain\PayoutResponse; |
| 20: | use Worldline\Connect\Sdk\V1\ExceptionFactory; |
| 21: | use Worldline\Connect\Sdk\V1\IdempotenceException; |
| 22: | use Worldline\Connect\Sdk\V1\PlatformException; |
| 23: | use Worldline\Connect\Sdk\V1\ReferenceException; |
| 24: | use Worldline\Connect\Sdk\V1\ValidationException; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | class PayoutsClient extends ApiResource |
| 32: | { |
| 33: | |
| 34: | |
| 35: | |
| 36: | private ?ExceptionFactory $responseExceptionFactory = null; |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | public function create(CreatePayoutRequest $body, ?CallContext $callContext = null): PayoutResponse |
| 56: | { |
| 57: | $responseClassMap = new ResponseClassMap(); |
| 58: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutResponse'; |
| 59: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutErrorResponse'; |
| 60: | try { |
| 61: | return $this->getCommunicator()->post( |
| 62: | $responseClassMap, |
| 63: | $this->instantiateUri('/v1/{merchantId}/payouts'), |
| 64: | $this->getClientMetaInfo(), |
| 65: | $body, |
| 66: | null, |
| 67: | $callContext |
| 68: | ); |
| 69: | } catch (ErrorResponseException $e) { |
| 70: | throw $this->getResponseExceptionFactory()->createException( |
| 71: | $e->getHttpStatusCode(), |
| 72: | $e->getErrorResponse(), |
| 73: | $callContext |
| 74: | ); |
| 75: | } |
| 76: | } |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | public function find(FindPayoutsParams $query, ?CallContext $callContext = null): FindPayoutsResponse |
| 95: | { |
| 96: | $responseClassMap = new ResponseClassMap(); |
| 97: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\FindPayoutsResponse'; |
| 98: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 99: | try { |
| 100: | return $this->getCommunicator()->get( |
| 101: | $responseClassMap, |
| 102: | $this->instantiateUri('/v1/{merchantId}/payouts'), |
| 103: | $this->getClientMetaInfo(), |
| 104: | $query, |
| 105: | $callContext |
| 106: | ); |
| 107: | } catch (ErrorResponseException $e) { |
| 108: | throw $this->getResponseExceptionFactory()->createException( |
| 109: | $e->getHttpStatusCode(), |
| 110: | $e->getErrorResponse(), |
| 111: | $callContext |
| 112: | ); |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | public function get(string $payoutId, ?CallContext $callContext = null): PayoutResponse |
| 133: | { |
| 134: | $this->context['payoutId'] = $payoutId; |
| 135: | $responseClassMap = new ResponseClassMap(); |
| 136: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutResponse'; |
| 137: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 138: | try { |
| 139: | return $this->getCommunicator()->get( |
| 140: | $responseClassMap, |
| 141: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}'), |
| 142: | $this->getClientMetaInfo(), |
| 143: | null, |
| 144: | $callContext |
| 145: | ); |
| 146: | } catch (ErrorResponseException $e) { |
| 147: | throw $this->getResponseExceptionFactory()->createException( |
| 148: | $e->getHttpStatusCode(), |
| 149: | $e->getErrorResponse(), |
| 150: | $callContext |
| 151: | ); |
| 152: | } |
| 153: | } |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | public function approve(string $payoutId, ApprovePayoutRequest $body, ?CallContext $callContext = null): PayoutResponse |
| 173: | { |
| 174: | $this->context['payoutId'] = $payoutId; |
| 175: | $responseClassMap = new ResponseClassMap(); |
| 176: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\PayoutResponse'; |
| 177: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 178: | try { |
| 179: | return $this->getCommunicator()->post( |
| 180: | $responseClassMap, |
| 181: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}/approve'), |
| 182: | $this->getClientMetaInfo(), |
| 183: | $body, |
| 184: | null, |
| 185: | $callContext |
| 186: | ); |
| 187: | } catch (ErrorResponseException $e) { |
| 188: | throw $this->getResponseExceptionFactory()->createException( |
| 189: | $e->getHttpStatusCode(), |
| 190: | $e->getErrorResponse(), |
| 191: | $callContext |
| 192: | ); |
| 193: | } |
| 194: | } |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: | |
| 209: | |
| 210: | |
| 211: | |
| 212: | public function cancel(string $payoutId, ?CallContext $callContext = null): void |
| 213: | { |
| 214: | $this->context['payoutId'] = $payoutId; |
| 215: | $responseClassMap = new ResponseClassMap(); |
| 216: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 217: | try { |
| 218: | $this->getCommunicator()->post( |
| 219: | $responseClassMap, |
| 220: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}/cancel'), |
| 221: | $this->getClientMetaInfo(), |
| 222: | null, |
| 223: | null, |
| 224: | $callContext |
| 225: | ); |
| 226: | } catch (ErrorResponseException $e) { |
| 227: | throw $this->getResponseExceptionFactory()->createException( |
| 228: | $e->getHttpStatusCode(), |
| 229: | $e->getErrorResponse(), |
| 230: | $callContext |
| 231: | ); |
| 232: | } |
| 233: | } |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | |
| 244: | |
| 245: | |
| 246: | |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | public function cancelapproval(string $payoutId, ?CallContext $callContext = null): void |
| 252: | { |
| 253: | $this->context['payoutId'] = $payoutId; |
| 254: | $responseClassMap = new ResponseClassMap(); |
| 255: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 256: | try { |
| 257: | $this->getCommunicator()->post( |
| 258: | $responseClassMap, |
| 259: | $this->instantiateUri('/v1/{merchantId}/payouts/{payoutId}/cancelapproval'), |
| 260: | $this->getClientMetaInfo(), |
| 261: | null, |
| 262: | null, |
| 263: | $callContext |
| 264: | ); |
| 265: | } catch (ErrorResponseException $e) { |
| 266: | throw $this->getResponseExceptionFactory()->createException( |
| 267: | $e->getHttpStatusCode(), |
| 268: | $e->getErrorResponse(), |
| 269: | $callContext |
| 270: | ); |
| 271: | } |
| 272: | } |
| 273: | |
| 274: | |
| 275: | |
| 276: | |
| 277: | private function getResponseExceptionFactory(): ExceptionFactory |
| 278: | { |
| 279: | if (is_null($this->responseExceptionFactory)) { |
| 280: | $this->responseExceptionFactory = new ExceptionFactory(); |
| 281: | } |
| 282: | return $this->responseExceptionFactory; |
| 283: | } |
| 284: | } |
| 285: | |