| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | namespace Worldline\Connect\Sdk\V1\Merchant\Captures; |
| 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\DeclinedRefundException; |
| 16: | use Worldline\Connect\Sdk\V1\Domain\CaptureResponse; |
| 17: | use Worldline\Connect\Sdk\V1\Domain\CreateDisputeRequest; |
| 18: | use Worldline\Connect\Sdk\V1\Domain\DisputeResponse; |
| 19: | use Worldline\Connect\Sdk\V1\Domain\DisputesResponse; |
| 20: | use Worldline\Connect\Sdk\V1\Domain\RefundRequest; |
| 21: | use Worldline\Connect\Sdk\V1\Domain\RefundResponse; |
| 22: | use Worldline\Connect\Sdk\V1\ExceptionFactory; |
| 23: | use Worldline\Connect\Sdk\V1\IdempotenceException; |
| 24: | use Worldline\Connect\Sdk\V1\PlatformException; |
| 25: | use Worldline\Connect\Sdk\V1\ReferenceException; |
| 26: | use Worldline\Connect\Sdk\V1\ValidationException; |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | class CapturesClient extends ApiResource |
| 32: | { |
| 33: | |
| 34: | private $responseExceptionFactory = null; |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | public function get($captureId, CallContext $callContext = null) |
| 53: | { |
| 54: | $this->context['captureId'] = $captureId; |
| 55: | $responseClassMap = new ResponseClassMap(); |
| 56: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\CaptureResponse'; |
| 57: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 58: | try { |
| 59: | return $this->getCommunicator()->get( |
| 60: | $responseClassMap, |
| 61: | $this->instantiateUri('/v1/{merchantId}/captures/{captureId}'), |
| 62: | $this->getClientMetaInfo(), |
| 63: | null, |
| 64: | $callContext |
| 65: | ); |
| 66: | } catch (ErrorResponseException $e) { |
| 67: | throw $this->getResponseExceptionFactory()->createException( |
| 68: | $e->getHttpStatusCode(), |
| 69: | $e->getErrorResponse(), |
| 70: | $callContext |
| 71: | ); |
| 72: | } |
| 73: | } |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | public function refund($captureId, RefundRequest $body, CallContext $callContext = null) |
| 94: | { |
| 95: | $this->context['captureId'] = $captureId; |
| 96: | $responseClassMap = new ResponseClassMap(); |
| 97: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundResponse'; |
| 98: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\RefundErrorResponse'; |
| 99: | try { |
| 100: | return $this->getCommunicator()->post( |
| 101: | $responseClassMap, |
| 102: | $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/refund'), |
| 103: | $this->getClientMetaInfo(), |
| 104: | $body, |
| 105: | null, |
| 106: | $callContext |
| 107: | ); |
| 108: | } catch (ErrorResponseException $e) { |
| 109: | throw $this->getResponseExceptionFactory()->createException( |
| 110: | $e->getHttpStatusCode(), |
| 111: | $e->getErrorResponse(), |
| 112: | $callContext |
| 113: | ); |
| 114: | } |
| 115: | } |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: | public function disputes($captureId, CallContext $callContext = null) |
| 134: | { |
| 135: | $this->context['captureId'] = $captureId; |
| 136: | $responseClassMap = new ResponseClassMap(); |
| 137: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\DisputesResponse'; |
| 138: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 139: | try { |
| 140: | return $this->getCommunicator()->get( |
| 141: | $responseClassMap, |
| 142: | $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/disputes'), |
| 143: | $this->getClientMetaInfo(), |
| 144: | null, |
| 145: | $callContext |
| 146: | ); |
| 147: | } catch (ErrorResponseException $e) { |
| 148: | throw $this->getResponseExceptionFactory()->createException( |
| 149: | $e->getHttpStatusCode(), |
| 150: | $e->getErrorResponse(), |
| 151: | $callContext |
| 152: | ); |
| 153: | } |
| 154: | } |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | public function dispute($captureId, CreateDisputeRequest $body, CallContext $callContext = null) |
| 174: | { |
| 175: | $this->context['captureId'] = $captureId; |
| 176: | $responseClassMap = new ResponseClassMap(); |
| 177: | $responseClassMap->defaultSuccessResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\DisputeResponse'; |
| 178: | $responseClassMap->defaultErrorResponseClassName = '\Worldline\Connect\Sdk\V1\Domain\ErrorResponse'; |
| 179: | try { |
| 180: | return $this->getCommunicator()->post( |
| 181: | $responseClassMap, |
| 182: | $this->instantiateUri('/v1/{merchantId}/captures/{captureId}/dispute'), |
| 183: | $this->getClientMetaInfo(), |
| 184: | $body, |
| 185: | null, |
| 186: | $callContext |
| 187: | ); |
| 188: | } catch (ErrorResponseException $e) { |
| 189: | throw $this->getResponseExceptionFactory()->createException( |
| 190: | $e->getHttpStatusCode(), |
| 191: | $e->getErrorResponse(), |
| 192: | $callContext |
| 193: | ); |
| 194: | } |
| 195: | } |
| 196: | |
| 197: | |
| 198: | private function getResponseExceptionFactory() |
| 199: | { |
| 200: | if (is_null($this->responseExceptionFactory)) { |
| 201: | $this->responseExceptionFactory = new ExceptionFactory(); |
| 202: | } |
| 203: | return $this->responseExceptionFactory; |
| 204: | } |
| 205: | } |
| 206: | |