GenericPayment::mapQuoteTransferToGenericPayment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\Payment\MethodMapper;
9
10
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...CheckoutRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use SprykerEco\Shared\Payone\PayoneApiConstants;
15
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer;
16
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\ExpressCheckoutContainer;
17
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer;
18
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\ShippingContainer;
19
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer;
20
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
21
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface;
22
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
23
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface;
24
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPayment\PaydataContainer;
25
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer;
26
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer;
27
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface;
28
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
29
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface;
30
use SprykerEco\Zed\Payone\Business\Payment\GenericPaymentMethodMapperInterface;
31
32
class GenericPayment extends AbstractMapper implements GenericPaymentMethodMapperInterface
33
{
34
    /**
35
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $genericPayment
36
     * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer
37
     *
38
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer
39
     */
40
    public function mapRequestTransferToGenericPayment(
41
        GenericPaymentContainer $genericPayment,
42
        PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer
43
    ): GenericPaymentContainer {
44
        $quoteTransfer = $requestTransfer->getQuote();
45
46
        $genericPayment = $this->mapQuoteTransferToGenericPayment($genericPayment, $quoteTransfer);
47
        $genericPayment->setSuccessUrl($requestTransfer->getSuccessUrl());
48
        $genericPayment->setBackUrl($requestTransfer->getBackUrl());
49
        $genericPayment->setErrorUrl($requestTransfer->getFailureUrl());
50
51
        return $genericPayment;
52
    }
53
54
    /**
55
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $genericPayment
56
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
57
     *
58
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer
59
     */
60
    public function mapQuoteTransferToGenericPayment(
61
        GenericPaymentContainer $genericPayment,
62
        QuoteTransfer $quoteTransfer
63
    ): GenericPaymentContainer {
64
        $genericPayment->setAmount($quoteTransfer->getTotals()->getGrandTotal());
65
        $genericPayment->setWorkOrderId(
66
            $quoteTransfer->getPayment()
67
                ->getPayonePaypalExpressCheckout()->getWorkOrderId()
68
        );
69
70
        return $genericPayment;
71
    }
72
73
    /**
74
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer
75
     */
76
    public function createBaseGenericPaymentContainer(): GenericPaymentContainer
77
    {
78
        $genericPayment = new GenericPaymentContainer();
79
        $paydataContainer = new PaydataContainer();
80
        $genericPayment->setPaydata($paydataContainer);
81
82
        $genericPayment->setAid($this->getStandardParameter()->getAid());
83
        $genericPayment->setClearingType(PayoneApiConstants::CLEARING_TYPE_E_WALLET);
84
        $genericPayment->setCurrency($this->getStandardParameter()->getCurrency());
85
        $genericPayment->setWalletType(PayoneApiConstants::E_WALLET_TYPE_PAYPAL);
86
87
        return $genericPayment;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getName(): string
94
    {
95
        return PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT;
96
    }
97
98
    /**
99
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
100
     *
101
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface
102
     */
103
    public function mapPaymentToPreauthorization(SpyPaymentPayone $paymentEntity): PreAuthorizationContainerInterface
104
    {
105
        $preAuthorizationContainer = new PreAuthorizationContainer();
106
        /** @var \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer $preAuthorizationContainer */
107
        $preAuthorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer);
108
109
        $preAuthorizationContainer->setWorkOrderId($paymentEntity->getSpyPaymentPayoneDetail()->getWorkOrderId());
110
111
        return $preAuthorizationContainer;
112
    }
113
114
    /**
115
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
116
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $authorizationContainer
117
     *
118
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
119
     */
120
    protected function mapPaymentToAbstractAuthorization(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $authorizationContainer)
121
    {
122
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
123
124
        $authorizationContainer->setAid($this->getStandardParameter()->getAid());
125
        $authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_E_WALLET);
126
        $authorizationContainer->setReference($paymentEntity->getReference());
127
        $authorizationContainer->setAmount($paymentDetailEntity->getAmount());
128
        $authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency());
129
        $authorizationContainer->setPaymentMethod($this->createPaymentMethodContainerFromPayment($paymentEntity));
130
131
        $personalContainer = new PersonalContainer();
132
        $this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity);
133
        $authorizationContainer->setPersonalData($personalContainer);
134
135
        $shippingAddressEntity = $paymentEntity->getSpySalesOrder()->getShippingAddress();
136
        $shippingContainer = new ShippingContainer();
137
        $this->mapShippingAddressToShippingContainer($shippingContainer, $shippingAddressEntity);
138
        $authorizationContainer->setShippingData($shippingContainer);
139
140
        return $authorizationContainer;
141
    }
142
143
    /**
144
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
145
     *
146
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\ExpressCheckoutContainer
147
     */
148
    protected function createPaymentMethodContainerFromPayment(SpyPaymentPayone $paymentEntity)
149
    {
150
        $paymentMethodContainer = new ExpressCheckoutContainer();
151
        $paymentMethodContainer->setRedirect($this->createRedirectContainer($paymentEntity->getSpySalesOrder()->getOrderReference()));
152
153
        $paymentMethodContainer->setWalletType($paymentEntity->getSpyPaymentPayoneDetail()->getType());
154
155
        return $paymentMethodContainer;
156
    }
157
158
    /**
159
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
160
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
161
     *
162
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer
163
     */
164
    public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer): AbstractAuthorizationContainer
165
    {
166
        $authorizationContainer = new AuthorizationContainer();
167
        $authorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $authorizationContainer);
168
169
        return $authorizationContainer;
170
    }
171
172
    /**
173
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
174
     *
175
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface
176
     */
177
    public function mapPaymentToCapture(SpyPaymentPayone $paymentEntity): CaptureContainerInterface
178
    {
179
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
180
181
        $captureContainer = new CaptureContainer();
182
        $captureContainer->setAmount($paymentDetailEntity->getAmount());
183
        $captureContainer->setCurrency($this->getStandardParameter()->getCurrency());
184
        $captureContainer->setTxid($paymentEntity->getTransactionId());
185
        $captureContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
186
187
        return $captureContainer;
188
    }
189
190
    /**
191
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
192
     *
193
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface
194
     */
195
    public function mapPaymentToDebit(SpyPaymentPayone $paymentEntity): DebitContainerInterface
196
    {
197
        $debitContainer = new DebitContainer();
198
199
        $debitContainer->setTxid($paymentEntity->getTransactionId());
200
        $debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
201
        $debitContainer->setCurrency($this->getStandardParameter()->getCurrency());
202
        $debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
203
204
        return $debitContainer;
205
    }
206
207
    /**
208
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
209
     *
210
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface
211
     */
212
    public function mapPaymentToRefund(SpyPaymentPayone $paymentEntity): RefundContainerInterface
213
    {
214
        $refundContainer = new RefundContainer();
215
216
        $refundContainer->setTxid($paymentEntity->getTransactionId());
217
        $refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
218
        $refundContainer->setCurrency($this->getStandardParameter()->getCurrency());
219
220
        return $refundContainer;
221
    }
222
}
223