@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @throws BadResponseException |
| 39 | 39 | * @throws ConnectException |
| 40 | 40 | */ |
| 41 | - function create(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface |
|
| 41 | + function create(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface |
|
| 42 | 42 | { |
| 43 | 43 | return $this->request('post', $checkout) ? $checkout : null; |
| 44 | 44 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @throws BadResponseException |
| 49 | 49 | * @throws ConnectException |
| 50 | 50 | */ |
| 51 | - function complete(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface |
|
| 51 | + function complete(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface |
|
| 52 | 52 | { |
| 53 | 53 | return $this->request('put', $checkout) ? $checkout : null; |
| 54 | 54 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param string|null $endpoint |
| 60 | 60 | * @return bool|null |
| 61 | 61 | */ |
| 62 | - function request(string $action, $checkout, string $endpoint = null):? bool |
|
| 62 | + function request(string $action, $checkout, string $endpoint = null): ? bool |
|
| 63 | 63 | { |
| 64 | 64 | if (!$checkout->isValid()) { |
| 65 | 65 | throw new InvalidCheckoutException($checkout); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | /** |
| 202 | 202 | * @return AccessToken |
| 203 | 203 | */ |
| 204 | - function getToken():? AccessToken |
|
| 204 | + function getToken(): ? AccessToken |
|
| 205 | 205 | { |
| 206 | 206 | return $this->currentToken; |
| 207 | 207 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | static function getCompleteUrl(CheckoutInterface $checkout): string |
| 214 | 214 | { |
| 215 | 215 | if ($checkout->getId()) { |
| 216 | - return SumUp::getEntrypoint().$checkout->getId(); |
|
| 216 | + return SumUp::getEntrypoint() . $checkout->getId(); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | return ''; |
@@ -22,71 +22,71 @@ discard block |
||
| 22 | 22 | request as protected traitRequest; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - protected $context; |
|
| 26 | - protected $lastResponse; |
|
| 25 | + protected $context; |
|
| 26 | + protected $lastResponse; |
|
| 27 | 27 | protected $options = []; |
| 28 | 28 | protected $currentToken; |
| 29 | 29 | |
| 30 | 30 | function __construct(ContextInterface $context, ?array $options = []) |
| 31 | - { |
|
| 32 | - $this->context = $context; |
|
| 31 | + { |
|
| 32 | + $this->context = $context; |
|
| 33 | 33 | $this->options = $options; |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @inheritDoc |
|
| 38 | - * @throws BadResponseException |
|
| 39 | - * @throws ConnectException |
|
| 40 | - */ |
|
| 36 | + /** |
|
| 37 | + * @inheritDoc |
|
| 38 | + * @throws BadResponseException |
|
| 39 | + * @throws ConnectException |
|
| 40 | + */ |
|
| 41 | 41 | function create(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface |
| 42 | - { |
|
| 42 | + { |
|
| 43 | 43 | return $this->request('post', $checkout) ? $checkout : null; |
| 44 | - } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @inheritDoc |
|
| 48 | - * @throws BadResponseException |
|
| 49 | - * @throws ConnectException |
|
| 50 | - */ |
|
| 46 | + /** |
|
| 47 | + * @inheritDoc |
|
| 48 | + * @throws BadResponseException |
|
| 49 | + * @throws ConnectException |
|
| 50 | + */ |
|
| 51 | 51 | function complete(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface |
| 52 | - { |
|
| 52 | + { |
|
| 53 | 53 | return $this->request('put', $checkout) ? $checkout : null; |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param string $action |
|
| 58 | - * @param CheckoutInterface $checkout |
|
| 56 | + /** |
|
| 57 | + * @param string $action |
|
| 58 | + * @param CheckoutInterface $checkout |
|
| 59 | 59 | * @param string|null $endpoint |
| 60 | - * @return bool|null |
|
| 61 | - */ |
|
| 60 | + * @return bool|null |
|
| 61 | + */ |
|
| 62 | 62 | function request(string $action, $checkout, string $endpoint = null):? bool |
| 63 | - { |
|
| 63 | + { |
|
| 64 | 64 | if (!$checkout->isValid()) { |
| 65 | 65 | throw new InvalidCheckoutException($checkout); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | return $this->traitRequest($action, $checkout); |
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Generate a body to create a new checkout |
|
| 73 | - * |
|
| 74 | - * @param CheckoutInterface $checkout |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Generate a body to create a new checkout |
|
| 73 | + * |
|
| 74 | + * @param CheckoutInterface $checkout |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | 77 | protected static function getCheckoutBody(CheckoutInterface $checkout): array |
| 78 | - { |
|
| 79 | - return [ |
|
| 80 | - "checkout_reference" => $checkout->getReference(), |
|
| 81 | - "amount" => $checkout->getAmount(), |
|
| 82 | - "currency" => $checkout->getCurrency(), |
|
| 83 | - "fee_amount" => $checkout->getFeeAmount(), |
|
| 84 | - "pay_to_email" => $checkout->getPayToEmail(), |
|
| 85 | - "pay_from_email" => $checkout->getPayFromEmail(), |
|
| 86 | - "description" => $checkout->getDescription(), |
|
| 87 | - "return_url" => $checkout->getRedirectUrl(), |
|
| 88 | - ]; |
|
| 89 | - } |
|
| 78 | + { |
|
| 79 | + return [ |
|
| 80 | + "checkout_reference" => $checkout->getReference(), |
|
| 81 | + "amount" => $checkout->getAmount(), |
|
| 82 | + "currency" => $checkout->getCurrency(), |
|
| 83 | + "fee_amount" => $checkout->getFeeAmount(), |
|
| 84 | + "pay_to_email" => $checkout->getPayToEmail(), |
|
| 85 | + "pay_from_email" => $checkout->getPayFromEmail(), |
|
| 86 | + "description" => $checkout->getDescription(), |
|
| 87 | + "return_url" => $checkout->getRedirectUrl(), |
|
| 88 | + ]; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * @param CheckoutInterface $checkout |
@@ -94,74 +94,74 @@ discard block |
||
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | 96 | static function getBody($checkout, string $type = null): array |
| 97 | - { |
|
| 98 | - $defaultBody = self::getCheckoutBody($checkout); |
|
| 99 | - switch ($checkout->getType()) { |
|
| 100 | - case 'card': |
|
| 101 | - $completeBody = self::getCardBody($checkout); |
|
| 102 | - break; |
|
| 103 | - |
|
| 104 | - case 'boleto': |
|
| 105 | - $completeBody = self::getBoletoBody($checkout); |
|
| 106 | - break; |
|
| 107 | - |
|
| 108 | - default: |
|
| 109 | - $completeBody = []; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return array_merge($defaultBody, $completeBody); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - private static function getCardBody(CheckoutInterface $checkout): array |
|
| 116 | - { |
|
| 117 | - return [ |
|
| 118 | - 'payment_type' => $checkout->getType(), |
|
| 119 | - 'token' => $checkout->getCard()->getToken(), |
|
| 120 | - 'customer_id' => $checkout->getCustomer()->getCustomerId() |
|
| 121 | - ]; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - private static function getBoletoBody(CheckoutInterface $checkout): array |
|
| 125 | - { |
|
| 126 | - $customer = $checkout->getCustomer(); |
|
| 127 | - return [ |
|
| 128 | - 'payment_type' => $checkout->getType(), |
|
| 129 | - 'description' => $checkout->getDescription(), |
|
| 130 | - 'boleto_details' => [ |
|
| 97 | + { |
|
| 98 | + $defaultBody = self::getCheckoutBody($checkout); |
|
| 99 | + switch ($checkout->getType()) { |
|
| 100 | + case 'card': |
|
| 101 | + $completeBody = self::getCardBody($checkout); |
|
| 102 | + break; |
|
| 103 | + |
|
| 104 | + case 'boleto': |
|
| 105 | + $completeBody = self::getBoletoBody($checkout); |
|
| 106 | + break; |
|
| 107 | + |
|
| 108 | + default: |
|
| 109 | + $completeBody = []; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return array_merge($defaultBody, $completeBody); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + private static function getCardBody(CheckoutInterface $checkout): array |
|
| 116 | + { |
|
| 117 | + return [ |
|
| 118 | + 'payment_type' => $checkout->getType(), |
|
| 119 | + 'token' => $checkout->getCard()->getToken(), |
|
| 120 | + 'customer_id' => $checkout->getCustomer()->getCustomerId() |
|
| 121 | + ]; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + private static function getBoletoBody(CheckoutInterface $checkout): array |
|
| 125 | + { |
|
| 126 | + $customer = $checkout->getCustomer(); |
|
| 127 | + return [ |
|
| 128 | + 'payment_type' => $checkout->getType(), |
|
| 129 | + 'description' => $checkout->getDescription(), |
|
| 130 | + 'boleto_details' => [ |
|
| 131 | 131 | // 'cpf_cnpj' => $customer->getCpfCnpj(), |
| 132 | - 'payer_name' => $customer->getName(), |
|
| 133 | - 'payer_address' => $customer->getAddress(), |
|
| 134 | - 'payer_city' => $customer->getAddress()->getCity(), |
|
| 135 | - 'payer_state_code' => $customer->getAddress()->getState(), |
|
| 136 | - 'payer_post_code' => $customer->getAddress()->getPostalCode() |
|
| 137 | - ], |
|
| 138 | - ]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @inheritDoc |
|
| 143 | - */ |
|
| 132 | + 'payer_name' => $customer->getName(), |
|
| 133 | + 'payer_address' => $customer->getAddress(), |
|
| 134 | + 'payer_city' => $customer->getAddress()->getCity(), |
|
| 135 | + 'payer_state_code' => $customer->getAddress()->getState(), |
|
| 136 | + 'payer_post_code' => $customer->getAddress()->getPostalCode() |
|
| 137 | + ], |
|
| 138 | + ]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @inheritDoc |
|
| 143 | + */ |
|
| 144 | 144 | static function getScopes(): array |
| 145 | - { |
|
| 146 | - return [ |
|
| 147 | - 'payments', |
|
| 148 | - 'boleto' |
|
| 149 | - ]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - function getLastResponse(): ResponseInterface |
|
| 153 | - { |
|
| 154 | - return $this->lastResponse; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * return the context used to created the client. |
|
| 159 | - * @return ContextInterface |
|
| 160 | - */ |
|
| 161 | - function getContext(): ContextInterface |
|
| 162 | - { |
|
| 163 | - return $this->context; |
|
| 164 | - } |
|
| 145 | + { |
|
| 146 | + return [ |
|
| 147 | + 'payments', |
|
| 148 | + 'boleto' |
|
| 149 | + ]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + function getLastResponse(): ResponseInterface |
|
| 153 | + { |
|
| 154 | + return $this->lastResponse; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * return the context used to created the client. |
|
| 159 | + * @return ContextInterface |
|
| 160 | + */ |
|
| 161 | + function getContext(): ContextInterface |
|
| 162 | + { |
|
| 163 | + return $this->context; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | function getOptions(): array |
| 167 | 167 | { |
@@ -11,48 +11,48 @@ |
||
| 11 | 11 | |
| 12 | 12 | trait PropertyHandler |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @param array $data |
|
| 16 | - */ |
|
| 14 | + /** |
|
| 15 | + * @param array $data |
|
| 16 | + */ |
|
| 17 | 17 | function fillProperties(array $data): void |
| 18 | - { |
|
| 19 | - foreach ($data as $p => $v) |
|
| 20 | - { |
|
| 21 | - $this->fillProperty($p, $v); |
|
| 22 | - } |
|
| 23 | - } |
|
| 18 | + { |
|
| 19 | + foreach ($data as $p => $v) |
|
| 20 | + { |
|
| 21 | + $this->fillProperty($p, $v); |
|
| 22 | + } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param string $property |
|
| 27 | - * @param mixed $value |
|
| 28 | - */ |
|
| 25 | + /** |
|
| 26 | + * @param string $property |
|
| 27 | + * @param mixed $value |
|
| 28 | + */ |
|
| 29 | 29 | function fillProperty(string $property, $value): void |
| 30 | - { |
|
| 31 | - $property = lcfirst(str_replace('_', '', ucwords($property, '_'))); |
|
| 32 | - if(property_exists(__CLASS__, $property)) |
|
| 33 | - { |
|
| 34 | - $method = sprintf('set%s', ucfirst($property)); |
|
| 35 | - $this->{$method}($value); |
|
| 36 | - } |
|
| 37 | - } |
|
| 30 | + { |
|
| 31 | + $property = lcfirst(str_replace('_', '', ucwords($property, '_'))); |
|
| 32 | + if(property_exists(__CLASS__, $property)) |
|
| 33 | + { |
|
| 34 | + $method = sprintf('set%s', ucfirst($property)); |
|
| 35 | + $this->{$method}($value); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return array |
|
| 41 | - */ |
|
| 42 | - function getPropertyArray(): array |
|
| 43 | - { |
|
| 44 | - $reflection = new \ReflectionClass(__CLASS__); |
|
| 45 | - $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED); |
|
| 46 | - $data = []; |
|
| 47 | - foreach($properties as $property){ |
|
| 48 | - $prop_name = $property->getName(); |
|
| 49 | - $method = sprintf('get%s', ucfirst($prop_name)); |
|
| 50 | - $form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name)); |
|
| 51 | - if($reflection->hasMethod($method)){ |
|
| 52 | - $data[$form_name] = $this->{$method}(); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - return $data; |
|
| 56 | - } |
|
| 39 | + /** |
|
| 40 | + * @return array |
|
| 41 | + */ |
|
| 42 | + function getPropertyArray(): array |
|
| 43 | + { |
|
| 44 | + $reflection = new \ReflectionClass(__CLASS__); |
|
| 45 | + $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED); |
|
| 46 | + $data = []; |
|
| 47 | + foreach($properties as $property){ |
|
| 48 | + $prop_name = $property->getName(); |
|
| 49 | + $method = sprintf('get%s', ucfirst($prop_name)); |
|
| 50 | + $form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name)); |
|
| 51 | + if($reflection->hasMethod($method)){ |
|
| 52 | + $data[$form_name] = $this->{$method}(); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + return $data; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | function fillProperty(string $property, $value): void |
| 30 | 30 | { |
| 31 | 31 | $property = lcfirst(str_replace('_', '', ucwords($property, '_'))); |
| 32 | - if(property_exists(__CLASS__, $property)) |
|
| 32 | + if (property_exists(__CLASS__, $property)) |
|
| 33 | 33 | { |
| 34 | 34 | $method = sprintf('set%s', ucfirst($property)); |
| 35 | 35 | $this->{$method}($value); |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | $reflection = new \ReflectionClass(__CLASS__); |
| 45 | 45 | $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED); |
| 46 | 46 | $data = []; |
| 47 | - foreach($properties as $property){ |
|
| 47 | + foreach ($properties as $property) { |
|
| 48 | 48 | $prop_name = $property->getName(); |
| 49 | 49 | $method = sprintf('get%s', ucfirst($prop_name)); |
| 50 | 50 | $form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name)); |
| 51 | - if($reflection->hasMethod($method)){ |
|
| 51 | + if ($reflection->hasMethod($method)) { |
|
| 52 | 52 | $data[$form_name] = $this->{$method}(); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | * @throws BadResponseException |
| 30 | 30 | * @throws ConnectException |
| 31 | 31 | */ |
| 32 | - function request(string $action, $object = null, string $endpoint = null):? bool |
|
| 32 | + function request(string $action, $object = null, string $endpoint = null): ? bool |
|
| 33 | 33 | { |
| 34 | 34 | /** @var SumUpClientInterface $this */ |
| 35 | 35 | |
@@ -17,5 +17,5 @@ |
||
| 17 | 17 | * @param string|null $endpoint |
| 18 | 18 | * @return bool|null |
| 19 | 19 | */ |
| 20 | - function request(string $action, $object, string $endpoint = null):? bool; |
|
| 20 | + function request(string $action, $object, string $endpoint = null): ? bool; |
|
| 21 | 21 | } |