@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Fundraising\Frontend\DonationContext\DataAccess; |
| 6 | 6 | |
@@ -40,113 +40,113 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | private $entityManager; |
| 42 | 42 | |
| 43 | - public function __construct( EntityManager $entityManager ) { |
|
| 43 | + public function __construct(EntityManager $entityManager) { |
|
| 44 | 44 | $this->entityManager = $entityManager; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function storeDonation( Donation $donation ) { |
|
| 48 | - if ( $donation->getId() === null ) { |
|
| 49 | - $this->insertDonation( $donation ); |
|
| 47 | + public function storeDonation(Donation $donation) { |
|
| 48 | + if ($donation->getId() === null) { |
|
| 49 | + $this->insertDonation($donation); |
|
| 50 | 50 | } |
| 51 | 51 | else { |
| 52 | - $this->updateDonation( $donation ); |
|
| 52 | + $this->updateDonation($donation); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - private function insertDonation( Donation $donation ) { |
|
| 56 | + private function insertDonation(Donation $donation) { |
|
| 57 | 57 | $doctrineDonation = new DoctrineDonation(); |
| 58 | - $this->updateDonationEntity( $doctrineDonation, $donation ); |
|
| 58 | + $this->updateDonationEntity($doctrineDonation, $donation); |
|
| 59 | 59 | |
| 60 | 60 | try { |
| 61 | - $this->entityManager->persist( $doctrineDonation ); |
|
| 61 | + $this->entityManager->persist($doctrineDonation); |
|
| 62 | 62 | $this->entityManager->flush(); |
| 63 | 63 | } |
| 64 | - catch ( ORMException $ex ) { |
|
| 65 | - throw new StoreDonationException( $ex ); |
|
| 64 | + catch (ORMException $ex) { |
|
| 65 | + throw new StoreDonationException($ex); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - $donation->assignId( $doctrineDonation->getId() ); |
|
| 68 | + $donation->assignId($doctrineDonation->getId()); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - private function updateDonation( Donation $donation ) { |
|
| 72 | - $doctrineDonation = $this->getDoctrineDonationById( $donation->getId() ); |
|
| 71 | + private function updateDonation(Donation $donation) { |
|
| 72 | + $doctrineDonation = $this->getDoctrineDonationById($donation->getId()); |
|
| 73 | 73 | |
| 74 | - if ( $doctrineDonation === null ) { |
|
| 74 | + if ($doctrineDonation === null) { |
|
| 75 | 75 | throw new StoreDonationException(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $this->updateDonationEntity( $doctrineDonation, $donation ); |
|
| 78 | + $this->updateDonationEntity($doctrineDonation, $donation); |
|
| 79 | 79 | |
| 80 | 80 | try { |
| 81 | - $this->entityManager->persist( $doctrineDonation ); |
|
| 81 | + $this->entityManager->persist($doctrineDonation); |
|
| 82 | 82 | $this->entityManager->flush(); |
| 83 | 83 | } |
| 84 | - catch ( ORMException $ex ) { |
|
| 85 | - throw new StoreDonationException( $ex ); |
|
| 84 | + catch (ORMException $ex) { |
|
| 85 | + throw new StoreDonationException($ex); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - private function updateDonationEntity( DoctrineDonation $doctrineDonation, Donation $donation ) { |
|
| 90 | - $doctrineDonation->setId( $donation->getId() ); |
|
| 91 | - $this->updatePaymentInformation( $doctrineDonation, $donation ); |
|
| 92 | - $this->updateDonorInformation( $doctrineDonation, $donation->getDonor() ); |
|
| 93 | - $this->updateComment( $doctrineDonation, $donation->getComment() ); |
|
| 94 | - $doctrineDonation->setDonorOptsIntoNewsletter( $donation->getOptsIntoNewsletter() ); |
|
| 89 | + private function updateDonationEntity(DoctrineDonation $doctrineDonation, Donation $donation) { |
|
| 90 | + $doctrineDonation->setId($donation->getId()); |
|
| 91 | + $this->updatePaymentInformation($doctrineDonation, $donation); |
|
| 92 | + $this->updateDonorInformation($doctrineDonation, $donation->getDonor()); |
|
| 93 | + $this->updateComment($doctrineDonation, $donation->getComment()); |
|
| 94 | + $doctrineDonation->setDonorOptsIntoNewsletter($donation->getOptsIntoNewsletter()); |
|
| 95 | 95 | |
| 96 | - $doctrineDonation->encodeAndSetData( array_merge( |
|
| 96 | + $doctrineDonation->encodeAndSetData(array_merge( |
|
| 97 | 97 | $doctrineDonation->getDecodedData(), |
| 98 | - $this->getDataMap( $donation ) |
|
| 99 | - ) ); |
|
| 98 | + $this->getDataMap($donation) |
|
| 99 | + )); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - private function updatePaymentInformation( DoctrineDonation $doctrineDonation, Donation $donation ) { |
|
| 103 | - $doctrineDonation->setStatus( $donation->getStatus() ); |
|
| 104 | - $doctrineDonation->setAmount( $donation->getAmount()->getEuroString() ); |
|
| 105 | - $doctrineDonation->setPaymentIntervalInMonths( $donation->getPaymentIntervalInMonths() ); |
|
| 102 | + private function updatePaymentInformation(DoctrineDonation $doctrineDonation, Donation $donation) { |
|
| 103 | + $doctrineDonation->setStatus($donation->getStatus()); |
|
| 104 | + $doctrineDonation->setAmount($donation->getAmount()->getEuroString()); |
|
| 105 | + $doctrineDonation->setPaymentIntervalInMonths($donation->getPaymentIntervalInMonths()); |
|
| 106 | 106 | |
| 107 | - $doctrineDonation->setPaymentType( $donation->getPaymentType() ); |
|
| 108 | - $doctrineDonation->setBankTransferCode( $this->getBankTransferCode( $donation->getPaymentMethod() ) ); |
|
| 107 | + $doctrineDonation->setPaymentType($donation->getPaymentType()); |
|
| 108 | + $doctrineDonation->setBankTransferCode($this->getBankTransferCode($donation->getPaymentMethod())); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - private function updateDonorInformation( DoctrineDonation $doctrineDonation, Donor $donor = null ) { |
|
| 112 | - if ( $donor === null ) { |
|
| 113 | - $doctrineDonation->setDonorFullName( 'Anonym' ); |
|
| 111 | + private function updateDonorInformation(DoctrineDonation $doctrineDonation, Donor $donor = null) { |
|
| 112 | + if ($donor === null) { |
|
| 113 | + $doctrineDonation->setDonorFullName('Anonym'); |
|
| 114 | 114 | } else { |
| 115 | - $doctrineDonation->setDonorCity( $donor->getPhysicalAddress()->getCity() ); |
|
| 116 | - $doctrineDonation->setDonorEmail( $donor->getEmailAddress() ); |
|
| 117 | - $doctrineDonation->setDonorFullName( $donor->getName()->getFullName() ); |
|
| 115 | + $doctrineDonation->setDonorCity($donor->getPhysicalAddress()->getCity()); |
|
| 116 | + $doctrineDonation->setDonorEmail($donor->getEmailAddress()); |
|
| 117 | + $doctrineDonation->setDonorFullName($donor->getName()->getFullName()); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - private function updateComment( DoctrineDonation $doctrineDonation, DonationComment $comment = null ) { |
|
| 122 | - if ( $comment === null ) { |
|
| 123 | - $doctrineDonation->setIsPublic( false ); |
|
| 124 | - $doctrineDonation->setComment( '' ); |
|
| 125 | - $doctrineDonation->setPublicRecord( '' ); |
|
| 121 | + private function updateComment(DoctrineDonation $doctrineDonation, DonationComment $comment = null) { |
|
| 122 | + if ($comment === null) { |
|
| 123 | + $doctrineDonation->setIsPublic(false); |
|
| 124 | + $doctrineDonation->setComment(''); |
|
| 125 | + $doctrineDonation->setPublicRecord(''); |
|
| 126 | 126 | } else { |
| 127 | - $doctrineDonation->setIsPublic( $comment->isPublic() ); |
|
| 128 | - $doctrineDonation->setComment( $comment->getCommentText() ); |
|
| 129 | - $doctrineDonation->setPublicRecord( $comment->getAuthorDisplayName() ); |
|
| 127 | + $doctrineDonation->setIsPublic($comment->isPublic()); |
|
| 128 | + $doctrineDonation->setComment($comment->getCommentText()); |
|
| 129 | + $doctrineDonation->setPublicRecord($comment->getAuthorDisplayName()); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - private function getBankTransferCode( PaymentMethod $paymentMethod ): string { |
|
| 134 | - if ( $paymentMethod instanceof BankTransferPayment ) { |
|
| 133 | + private function getBankTransferCode(PaymentMethod $paymentMethod): string { |
|
| 134 | + if ($paymentMethod instanceof BankTransferPayment) { |
|
| 135 | 135 | return $paymentMethod->getBankTransferCode(); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | return ''; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - private function getDataMap( Donation $donation ): array { |
|
| 141 | + private function getDataMap(Donation $donation): array { |
|
| 142 | 142 | return array_merge( |
| 143 | - $this->getDataFieldsFromTrackingInfo( $donation->getTrackingInfo() ), |
|
| 144 | - $this->getDataFieldsForPaymentData( $donation->getPaymentMethod() ), |
|
| 145 | - $this->getDataFieldsFromDonor( $donation->getDonor() ) |
|
| 143 | + $this->getDataFieldsFromTrackingInfo($donation->getTrackingInfo()), |
|
| 144 | + $this->getDataFieldsForPaymentData($donation->getPaymentMethod()), |
|
| 145 | + $this->getDataFieldsFromDonor($donation->getDonor()) |
|
| 146 | 146 | ); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - private function getDataFieldsFromTrackingInfo( DonationTrackingInfo $trackingInfo ): array { |
|
| 149 | + private function getDataFieldsFromTrackingInfo(DonationTrackingInfo $trackingInfo): array { |
|
| 150 | 150 | return [ |
| 151 | 151 | 'layout' => $trackingInfo->getLayout(), |
| 152 | 152 | 'impCount' => $trackingInfo->getTotalImpressionCount(), |
@@ -158,23 +158,23 @@ discard block |
||
| 158 | 158 | ]; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - private function getDataFieldsForPaymentData( PaymentMethod $paymentMethod ): array { |
|
| 162 | - if ( $paymentMethod instanceof DirectDebitPayment ) { |
|
| 163 | - return $this->getDataFieldsFromBankData( $paymentMethod->getBankData() ); |
|
| 161 | + private function getDataFieldsForPaymentData(PaymentMethod $paymentMethod): array { |
|
| 162 | + if ($paymentMethod instanceof DirectDebitPayment) { |
|
| 163 | + return $this->getDataFieldsFromBankData($paymentMethod->getBankData()); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if ( $paymentMethod instanceof PayPalPayment ) { |
|
| 167 | - return $this->getDataFieldsFromPayPalData( $paymentMethod->getPayPalData() ); |
|
| 166 | + if ($paymentMethod instanceof PayPalPayment) { |
|
| 167 | + return $this->getDataFieldsFromPayPalData($paymentMethod->getPayPalData()); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ( $paymentMethod instanceof CreditCardPayment ) { |
|
| 171 | - return $this->getDataFieldsFromCreditCardData( $paymentMethod->getCreditCardData() ); |
|
| 170 | + if ($paymentMethod instanceof CreditCardPayment) { |
|
| 171 | + return $this->getDataFieldsFromCreditCardData($paymentMethod->getCreditCardData()); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | return []; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - private function getDataFieldsFromBankData( BankData $bankData ): array { |
|
| 177 | + private function getDataFieldsFromBankData(BankData $bankData): array { |
|
| 178 | 178 | return [ |
| 179 | 179 | 'iban' => $bankData->getIban()->toString(), |
| 180 | 180 | 'bic' => $bankData->getBic(), |
@@ -184,19 +184,19 @@ discard block |
||
| 184 | 184 | ]; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - private function getDataFieldsFromDonor( Donor $personalInfo = null ): array { |
|
| 188 | - if ( $personalInfo === null ) { |
|
| 189 | - return [ 'adresstyp' => 'anonym' ]; |
|
| 187 | + private function getDataFieldsFromDonor(Donor $personalInfo = null): array { |
|
| 188 | + if ($personalInfo === null) { |
|
| 189 | + return ['adresstyp' => 'anonym']; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | return array_merge( |
| 193 | - $this->getDataFieldsFromPersonName( $personalInfo->getName() ), |
|
| 194 | - $this->getDataFieldsFromAddress( $personalInfo->getPhysicalAddress() ), |
|
| 195 | - [ 'email' => $personalInfo->getEmailAddress() ] |
|
| 193 | + $this->getDataFieldsFromPersonName($personalInfo->getName()), |
|
| 194 | + $this->getDataFieldsFromAddress($personalInfo->getPhysicalAddress()), |
|
| 195 | + ['email' => $personalInfo->getEmailAddress()] |
|
| 196 | 196 | ); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - private function getDataFieldsFromPersonName( DonorName $name ) { |
|
| 199 | + private function getDataFieldsFromPersonName(DonorName $name) { |
|
| 200 | 200 | return [ |
| 201 | 201 | 'adresstyp' => $name->getPersonType(), |
| 202 | 202 | 'anrede' => $name->getSalutation(), |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | ]; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - private function getDataFieldsFromAddress( DonorAddress $address ) { |
|
| 210 | + private function getDataFieldsFromAddress(DonorAddress $address) { |
|
| 211 | 211 | return [ |
| 212 | 212 | 'strasse' => $address->getStreetAddress(), |
| 213 | 213 | 'plz' => $address->getPostalCode(), |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | ]; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - private function getDataFieldsFromPayPalData( PayPalData $payPalData ) { |
|
| 219 | + private function getDataFieldsFromPayPalData(PayPalData $payPalData) { |
|
| 220 | 220 | return [ |
| 221 | 221 | 'paypal_payer_id' => $payPalData->getPayerId(), |
| 222 | 222 | 'paypal_subscr_id' => $payPalData->getSubscriberId(), |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | ]; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - private function getDataFieldsFromCreditCardData( CreditCardTransactionData $ccData ) { |
|
| 241 | + private function getDataFieldsFromCreditCardData(CreditCardTransactionData $ccData) { |
|
| 242 | 242 | return [ |
| 243 | 243 | 'ext_payment_id' => $ccData->getTransactionId(), |
| 244 | 244 | 'ext_payment_status' => $ccData->getTransactionStatus(), |
| 245 | - 'ext_payment_timestamp' => $ccData->getTransactionTimestamp()->format( \DateTime::ATOM ), |
|
| 245 | + 'ext_payment_timestamp' => $ccData->getTransactionTimestamp()->format(\DateTime::ATOM), |
|
| 246 | 246 | 'mcp_amount' => $ccData->getAmount()->getEuroString(), |
| 247 | 247 | 'ext_payment_account' => $ccData->getCustomerId(), |
| 248 | 248 | 'mcp_sessionid' => $ccData->getSessionId(), |
@@ -250,16 +250,16 @@ discard block |
||
| 250 | 250 | 'mcp_title' => $ccData->getTitle(), |
| 251 | 251 | 'mcp_country' => $ccData->getCountryCode(), |
| 252 | 252 | 'mcp_currency' => $ccData->getCurrencyCode(), |
| 253 | - 'mcp_cc_expiry_date' => $this->getExpirationDateAsString( $ccData->getCardExpiry() ) |
|
| 253 | + 'mcp_cc_expiry_date' => $this->getExpirationDateAsString($ccData->getCardExpiry()) |
|
| 254 | 254 | ]; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - private function getExpirationDateAsString( CreditCardExpiry $cardExpiry = null ): string { |
|
| 258 | - if ( $cardExpiry === null ) { |
|
| 257 | + private function getExpirationDateAsString(CreditCardExpiry $cardExpiry = null): string { |
|
| 258 | + if ($cardExpiry === null) { |
|
| 259 | 259 | return ''; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - return implode( '/', [ $cardExpiry->getMonth(), $cardExpiry->getYear() ] ); |
|
| 262 | + return implode('/', [$cardExpiry->getMonth(), $cardExpiry->getYear()]); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -268,19 +268,19 @@ discard block |
||
| 268 | 268 | * @return Donation|null |
| 269 | 269 | * @throws GetDonationException |
| 270 | 270 | */ |
| 271 | - public function getDonationById( int $id ) { |
|
| 271 | + public function getDonationById(int $id) { |
|
| 272 | 272 | try { |
| 273 | - $donation = $this->getDoctrineDonationById( $id ); |
|
| 273 | + $donation = $this->getDoctrineDonationById($id); |
|
| 274 | 274 | } |
| 275 | - catch ( ORMException $ex ) { |
|
| 276 | - throw new GetDonationException( $ex ); |
|
| 275 | + catch (ORMException $ex) { |
|
| 276 | + throw new GetDonationException($ex); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if ( $donation === null ) { |
|
| 279 | + if ($donation === null) { |
|
| 280 | 280 | return null; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - return $this->newDonationDomainObject( $donation ); |
|
| 283 | + return $this->newDonationDomainObject($donation); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -288,22 +288,22 @@ discard block |
||
| 288 | 288 | * @return DoctrineDonation|null |
| 289 | 289 | * @throws ORMException |
| 290 | 290 | */ |
| 291 | - public function getDoctrineDonationById( int $id ) { |
|
| 292 | - return $this->entityManager->getRepository( DoctrineDonation::class )->findOneBy( [ |
|
| 291 | + public function getDoctrineDonationById(int $id) { |
|
| 292 | + return $this->entityManager->getRepository(DoctrineDonation::class)->findOneBy([ |
|
| 293 | 293 | 'id' => $id, |
| 294 | 294 | 'deletionTime' => null |
| 295 | - ] ); |
|
| 295 | + ]); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - private function newDonationDomainObject( DoctrineDonation $dd ): Donation { |
|
| 298 | + private function newDonationDomainObject(DoctrineDonation $dd): Donation { |
|
| 299 | 299 | return new Donation( |
| 300 | 300 | $dd->getId(), |
| 301 | 301 | $dd->getStatus(), |
| 302 | - $this->getDonorFromEntity( $dd ), |
|
| 303 | - $this->getPaymentFromEntity( $dd ), |
|
| 302 | + $this->getDonorFromEntity($dd), |
|
| 303 | + $this->getPaymentFromEntity($dd), |
|
| 304 | 304 | (bool)$dd->getDonorOptsIntoNewsletter(), |
| 305 | - $this->getTrackingInfoFromEntity( $dd ), |
|
| 306 | - $this->getCommentFromEntity( $dd ) |
|
| 305 | + $this->getTrackingInfoFromEntity($dd), |
|
| 306 | + $this->getCommentFromEntity($dd) |
|
| 307 | 307 | ); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -312,83 +312,83 @@ discard block |
||
| 312 | 312 | * |
| 313 | 313 | * @return Donor|null |
| 314 | 314 | */ |
| 315 | - private function getDonorFromEntity( DoctrineDonation $dd ) { |
|
| 316 | - if ( $dd->getDonorEmail() === null ) { |
|
| 315 | + private function getDonorFromEntity(DoctrineDonation $dd) { |
|
| 316 | + if ($dd->getDonorEmail() === null) { |
|
| 317 | 317 | return null; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // This should not happen, but it does (but only with PayPal payments in production), so as a step towards fixing this, we log |
| 321 | - if ( $this->entityHasMissingFields( $dd ) ) { |
|
| 322 | - error_log( sprintf( |
|
| 321 | + if ($this->entityHasMissingFields($dd)) { |
|
| 322 | + error_log(sprintf( |
|
| 323 | 323 | 'Entity %d has missing fields. Field data: %s', |
| 324 | 324 | $dd->getId(), |
| 325 | - var_export( $dd->getDecodedData(), true ) ) |
|
| 325 | + var_export($dd->getDecodedData(), true) ) |
|
| 326 | 326 | ); |
| 327 | - error_log( implode( "\n", array_map( function( $bt ) { |
|
| 328 | - return sprintf( '%s, line %d, %s', $bt['file'], $bt['line'], $bt['function'] ); |
|
| 329 | - }, debug_backtrace() ) ) ); |
|
| 327 | + error_log(implode("\n", array_map(function($bt) { |
|
| 328 | + return sprintf('%s, line %d, %s', $bt['file'], $bt['line'], $bt['function']); |
|
| 329 | + }, debug_backtrace()))); |
|
| 330 | 330 | return null; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | return new Donor( |
| 334 | - $this->getPersonNameFromEntity( $dd ), |
|
| 335 | - $this->getPhysicalAddressFromEntity( $dd ), |
|
| 334 | + $this->getPersonNameFromEntity($dd), |
|
| 335 | + $this->getPhysicalAddressFromEntity($dd), |
|
| 336 | 336 | $dd->getDonorEmail() |
| 337 | 337 | ); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - private function getPaymentFromEntity( DoctrineDonation $dd ): DonationPayment { |
|
| 340 | + private function getPaymentFromEntity(DoctrineDonation $dd): DonationPayment { |
|
| 341 | 341 | return new DonationPayment( |
| 342 | - Euro::newFromString( $dd->getAmount() ), |
|
| 342 | + Euro::newFromString($dd->getAmount()), |
|
| 343 | 343 | $dd->getPaymentIntervalInMonths(), |
| 344 | - $this->getPaymentMethodFromEntity( $dd ) |
|
| 344 | + $this->getPaymentMethodFromEntity($dd) |
|
| 345 | 345 | ); |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - private function getPaymentMethodFromEntity( DoctrineDonation $dd ): PaymentMethod { |
|
| 349 | - if ( $dd->getPaymentType() === PaymentType::BANK_TRANSFER ) { |
|
| 350 | - return new BankTransferPayment( $dd->getBankTransferCode() ); |
|
| 348 | + private function getPaymentMethodFromEntity(DoctrineDonation $dd): PaymentMethod { |
|
| 349 | + if ($dd->getPaymentType() === PaymentType::BANK_TRANSFER) { |
|
| 350 | + return new BankTransferPayment($dd->getBankTransferCode()); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - if ( $dd->getPaymentType() === PaymentType::DIRECT_DEBIT ) { |
|
| 354 | - return new DirectDebitPayment( $this->getBankDataFromEntity( $dd ) ); |
|
| 353 | + if ($dd->getPaymentType() === PaymentType::DIRECT_DEBIT) { |
|
| 354 | + return new DirectDebitPayment($this->getBankDataFromEntity($dd)); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if ( $dd->getPaymentType() === PaymentType::PAYPAL ) { |
|
| 358 | - return new PayPalPayment( $this->getPayPalDataFromEntity( $dd ) ); |
|
| 357 | + if ($dd->getPaymentType() === PaymentType::PAYPAL) { |
|
| 358 | + return new PayPalPayment($this->getPayPalDataFromEntity($dd)); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( $dd->getPaymentType() === PaymentType::CREDIT_CARD ) { |
|
| 362 | - return new CreditCardPayment( $this->getCreditCardDataFromEntity( $dd ) ); |
|
| 361 | + if ($dd->getPaymentType() === PaymentType::CREDIT_CARD) { |
|
| 362 | + return new CreditCardPayment($this->getCreditCardDataFromEntity($dd)); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - return new PaymentWithoutAssociatedData( $dd->getPaymentType() ); |
|
| 365 | + return new PaymentWithoutAssociatedData($dd->getPaymentType()); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - private function getPersonNameFromEntity( DoctrineDonation $dd ): DonorName { |
|
| 368 | + private function getPersonNameFromEntity(DoctrineDonation $dd): DonorName { |
|
| 369 | 369 | $data = $dd->getDecodedData(); |
| 370 | 370 | |
| 371 | 371 | $name = $data['adresstyp'] === DonorName::PERSON_COMPANY |
| 372 | 372 | ? DonorName::newCompanyName() : DonorName::newPrivatePersonName(); |
| 373 | 373 | |
| 374 | - $name->setSalutation( $data['anrede'] ); |
|
| 375 | - $name->setTitle( $data['titel'] ); |
|
| 376 | - $name->setFirstName( $data['vorname'] ); |
|
| 377 | - $name->setLastName( $data['nachname'] ); |
|
| 378 | - $name->setCompanyName( $data['firma'] ); |
|
| 374 | + $name->setSalutation($data['anrede']); |
|
| 375 | + $name->setTitle($data['titel']); |
|
| 376 | + $name->setFirstName($data['vorname']); |
|
| 377 | + $name->setLastName($data['nachname']); |
|
| 378 | + $name->setCompanyName($data['firma']); |
|
| 379 | 379 | |
| 380 | 380 | return $name->freeze()->assertNoNullFields(); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - private function getPhysicalAddressFromEntity( DoctrineDonation $dd ): DonorAddress { |
|
| 383 | + private function getPhysicalAddressFromEntity(DoctrineDonation $dd): DonorAddress { |
|
| 384 | 384 | $data = $dd->getDecodedData(); |
| 385 | 385 | |
| 386 | 386 | $address = new DonorAddress(); |
| 387 | 387 | |
| 388 | - $address->setStreetAddress( $data['strasse'] ); |
|
| 389 | - $address->setCity( $data['ort'] ); |
|
| 390 | - $address->setPostalCode( $data['plz'] ); |
|
| 391 | - $address->setCountryCode( $data['country'] ); |
|
| 388 | + $address->setStreetAddress($data['strasse']); |
|
| 389 | + $address->setCity($data['ort']); |
|
| 390 | + $address->setPostalCode($data['plz']); |
|
| 391 | + $address->setCountryCode($data['country']); |
|
| 392 | 392 | |
| 393 | 393 | return $address->freeze()->assertNoNullFields(); |
| 394 | 394 | } |
@@ -398,17 +398,17 @@ discard block |
||
| 398 | 398 | * |
| 399 | 399 | * @return BankData|null |
| 400 | 400 | */ |
| 401 | - private function getBankDataFromEntity( DoctrineDonation $dd ) { |
|
| 401 | + private function getBankDataFromEntity(DoctrineDonation $dd) { |
|
| 402 | 402 | $data = $dd->getDecodedData(); |
| 403 | 403 | |
| 404 | - if ( array_key_exists( 'iban', $data ) ) { |
|
| 404 | + if (array_key_exists('iban', $data)) { |
|
| 405 | 405 | $bankData = new BankData(); |
| 406 | 406 | |
| 407 | - $bankData->setIban( new Iban( $data['iban'] ) ); |
|
| 408 | - $bankData->setBic( $data['bic'] ); |
|
| 409 | - $bankData->setAccount( $data['konto'] ); |
|
| 410 | - $bankData->setBankCode( $data['blz'] ); |
|
| 411 | - $bankData->setBankName( $data['bankname'] ); |
|
| 407 | + $bankData->setIban(new Iban($data['iban'])); |
|
| 408 | + $bankData->setBic($data['bic']); |
|
| 409 | + $bankData->setAccount($data['konto']); |
|
| 410 | + $bankData->setBankCode($data['blz']); |
|
| 411 | + $bankData->setBankName($data['bankname']); |
|
| 412 | 412 | |
| 413 | 413 | return $bankData->freeze()->assertNoNullFields(); |
| 414 | 414 | } |
@@ -416,18 +416,18 @@ discard block |
||
| 416 | 416 | return null; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - private function getTrackingInfoFromEntity( DoctrineDonation $dd ): DonationTrackingInfo { |
|
| 419 | + private function getTrackingInfoFromEntity(DoctrineDonation $dd): DonationTrackingInfo { |
|
| 420 | 420 | $data = $dd->getDecodedData(); |
| 421 | 421 | |
| 422 | 422 | $trackingInfo = new DonationTrackingInfo(); |
| 423 | 423 | |
| 424 | - $trackingInfo->setLayout( $data['layout'] ); |
|
| 425 | - $trackingInfo->setTotalImpressionCount( $data['impCount'] ); |
|
| 426 | - $trackingInfo->setSingleBannerImpressionCount( $data['bImpCount'] ); |
|
| 427 | - $trackingInfo->setTracking( $data['tracking'] ); |
|
| 428 | - $trackingInfo->setSkin( $data['skin'] ); |
|
| 429 | - $trackingInfo->setColor( $data['color'] ); |
|
| 430 | - $trackingInfo->setSource( $data['source'] ); |
|
| 424 | + $trackingInfo->setLayout($data['layout']); |
|
| 425 | + $trackingInfo->setTotalImpressionCount($data['impCount']); |
|
| 426 | + $trackingInfo->setSingleBannerImpressionCount($data['bImpCount']); |
|
| 427 | + $trackingInfo->setTracking($data['tracking']); |
|
| 428 | + $trackingInfo->setSkin($data['skin']); |
|
| 429 | + $trackingInfo->setColor($data['color']); |
|
| 430 | + $trackingInfo->setSource($data['source']); |
|
| 431 | 431 | |
| 432 | 432 | return $trackingInfo->freeze()->assertNoNullFields(); |
| 433 | 433 | } |
@@ -436,26 +436,26 @@ discard block |
||
| 436 | 436 | * @param DoctrineDonation $dd |
| 437 | 437 | * @return PayPalData|null |
| 438 | 438 | */ |
| 439 | - private function getPayPalDataFromEntity( DoctrineDonation $dd ) { |
|
| 439 | + private function getPayPalDataFromEntity(DoctrineDonation $dd) { |
|
| 440 | 440 | $data = $dd->getDecodedData(); |
| 441 | 441 | |
| 442 | - if ( array_key_exists( 'paypal_payer_id', $data ) ) { |
|
| 443 | - return ( new PayPalData() ) |
|
| 444 | - ->setPayerId( $data['paypal_payer_id'] ) |
|
| 445 | - ->setSubscriberId( $data['paypal_subscr_id'] ) |
|
| 446 | - ->setPayerStatus( $data['paypal_payer_status'] ) |
|
| 447 | - ->setAddressStatus( $data['paypal_address_status'] ) |
|
| 448 | - ->setAmount( Euro::newFromString( $data['paypal_mc_gross'] ) ) |
|
| 449 | - ->setCurrencyCode( $data['paypal_mc_currency'] ) |
|
| 450 | - ->setFee( Euro::newFromString( $data['paypal_mc_fee'] ) ) |
|
| 451 | - ->setSettleAmount( Euro::newFromString( $data['paypal_settle_amount'] ) ) |
|
| 452 | - ->setFirstName( $data['paypal_first_name'] ) |
|
| 453 | - ->setLastName( $data['paypal_last_name'] ) |
|
| 454 | - ->setAddressName( $data['paypal_address_name'] ) |
|
| 455 | - ->setPaymentId( $data['ext_payment_id'] ) |
|
| 456 | - ->setPaymentType( $data['ext_payment_type'] ) |
|
| 457 | - ->setPaymentStatus( $data['ext_payment_status'] ) |
|
| 458 | - ->setPaymentTimestamp( $data['ext_payment_timestamp'] ) |
|
| 442 | + if (array_key_exists('paypal_payer_id', $data)) { |
|
| 443 | + return (new PayPalData()) |
|
| 444 | + ->setPayerId($data['paypal_payer_id']) |
|
| 445 | + ->setSubscriberId($data['paypal_subscr_id']) |
|
| 446 | + ->setPayerStatus($data['paypal_payer_status']) |
|
| 447 | + ->setAddressStatus($data['paypal_address_status']) |
|
| 448 | + ->setAmount(Euro::newFromString($data['paypal_mc_gross'])) |
|
| 449 | + ->setCurrencyCode($data['paypal_mc_currency']) |
|
| 450 | + ->setFee(Euro::newFromString($data['paypal_mc_fee'])) |
|
| 451 | + ->setSettleAmount(Euro::newFromString($data['paypal_settle_amount'])) |
|
| 452 | + ->setFirstName($data['paypal_first_name']) |
|
| 453 | + ->setLastName($data['paypal_last_name']) |
|
| 454 | + ->setAddressName($data['paypal_address_name']) |
|
| 455 | + ->setPaymentId($data['ext_payment_id']) |
|
| 456 | + ->setPaymentType($data['ext_payment_type']) |
|
| 457 | + ->setPaymentStatus($data['ext_payment_status']) |
|
| 458 | + ->setPaymentTimestamp($data['ext_payment_timestamp']) |
|
| 459 | 459 | ->freeze()->assertNoNullFields(); |
| 460 | 460 | } |
| 461 | 461 | |
@@ -466,22 +466,22 @@ discard block |
||
| 466 | 466 | * @param DoctrineDonation $dd |
| 467 | 467 | * @return CreditCardTransactionData|null |
| 468 | 468 | */ |
| 469 | - private function getCreditCardDataFromEntity( DoctrineDonation $dd ) { |
|
| 469 | + private function getCreditCardDataFromEntity(DoctrineDonation $dd) { |
|
| 470 | 470 | $data = $dd->getDecodedData(); |
| 471 | 471 | |
| 472 | - if ( array_key_exists( 'mcp_auth', $data ) ) { |
|
| 473 | - return ( new CreditCardTransactionData() ) |
|
| 474 | - ->setTransactionId( $data['ext_payment_id'] ) |
|
| 475 | - ->setTransactionStatus( $data['ext_payment_status'] ) |
|
| 476 | - ->setTransactionTimestamp( new \DateTime( $data['ext_payment_timestamp'] ) ) |
|
| 477 | - ->setAmount( Euro::newFromString( $data['mcp_amount'] ) ) |
|
| 478 | - ->setCustomerId( $data['ext_payment_account'] ) |
|
| 479 | - ->setSessionId( $data['mcp_sessionid'] ) |
|
| 480 | - ->setAuthId( $data['mcp_auth'] ) |
|
| 481 | - ->setCardExpiry( CreditCardExpiry::newFromString( $data['mcp_cc_expiry_date'] ) ) |
|
| 482 | - ->setTitle( $data['mcp_title'] ) |
|
| 483 | - ->setCountryCode( $data['mcp_country'] ) |
|
| 484 | - ->setCurrencyCode( $data['mcp_currency'] ) |
|
| 472 | + if (array_key_exists('mcp_auth', $data)) { |
|
| 473 | + return (new CreditCardTransactionData()) |
|
| 474 | + ->setTransactionId($data['ext_payment_id']) |
|
| 475 | + ->setTransactionStatus($data['ext_payment_status']) |
|
| 476 | + ->setTransactionTimestamp(new \DateTime($data['ext_payment_timestamp'])) |
|
| 477 | + ->setAmount(Euro::newFromString($data['mcp_amount'])) |
|
| 478 | + ->setCustomerId($data['ext_payment_account']) |
|
| 479 | + ->setSessionId($data['mcp_sessionid']) |
|
| 480 | + ->setAuthId($data['mcp_auth']) |
|
| 481 | + ->setCardExpiry(CreditCardExpiry::newFromString($data['mcp_cc_expiry_date'])) |
|
| 482 | + ->setTitle($data['mcp_title']) |
|
| 483 | + ->setCountryCode($data['mcp_country']) |
|
| 484 | + ->setCurrencyCode($data['mcp_currency']) |
|
| 485 | 485 | ->freeze(); |
| 486 | 486 | } |
| 487 | 487 | |
@@ -492,8 +492,8 @@ discard block |
||
| 492 | 492 | * @param DoctrineDonation $dd |
| 493 | 493 | * @return DonationComment|null |
| 494 | 494 | */ |
| 495 | - private function getCommentFromEntity( DoctrineDonation $dd ) { |
|
| 496 | - if ( $dd->getComment() === '' ) { |
|
| 495 | + private function getCommentFromEntity(DoctrineDonation $dd) { |
|
| 496 | + if ($dd->getComment() === '') { |
|
| 497 | 497 | return null; |
| 498 | 498 | } |
| 499 | 499 | |
@@ -504,14 +504,14 @@ discard block |
||
| 504 | 504 | ); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - private function entityHasMissingFields( DoctrineDonation $dd ): bool { |
|
| 507 | + private function entityHasMissingFields(DoctrineDonation $dd): bool { |
|
| 508 | 508 | $data = $dd->getDecodedData(); |
| 509 | 509 | return |
| 510 | - !isset( $data['anrede'] ) || $data['anrede'] === null || |
|
| 511 | - !isset( $data['titel'] ) || $data['titel'] === null || |
|
| 512 | - !isset( $data['vorname'] ) || $data['vorname'] === null || |
|
| 513 | - !isset( $data['nachname'] ) || $data['nachname'] === null || |
|
| 514 | - !isset( $data['firma'] ) || $data['firma'] === null; |
|
| 510 | + !isset($data['anrede']) || $data['anrede'] === null || |
|
| 511 | + !isset($data['titel']) || $data['titel'] === null || |
|
| 512 | + !isset($data['vorname']) || $data['vorname'] === null || |
|
| 513 | + !isset($data['nachname']) || $data['nachname'] === null || |
|
| 514 | + !isset($data['firma']) || $data['firma'] === null; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | } |