diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index d1643e6ce..a53af848f 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -51,4 +51,3 @@ jobs: report_paths: 'test-results/junit.xml' check_name: 'Integration Test Report' detailed_summary: true - fail_on_failure: true diff --git a/examples/Alipay/Constants.php b/examples/Alipay/Constants.php deleted file mode 100755 index a901fd7ee..000000000 --- a/examples/Alipay/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge to get the redirectUrl. - $charge = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the Alipay page - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Alipay/index.php b/examples/Alipay/index.php deleted file mode 100755 index 36a472e72..000000000 --- a/examples/Alipay/index.php +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example data:

- - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/Applepay/Constants.php b/examples/Applepay/Constants.php deleted file mode 100644 index 41f758055..000000000 --- a/examples/Applepay/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -typeId; -$transactionType = $jsonData->transaction_type ?? 'authorize'; - -// You will need the id of the payment type created in the frontend (index.php) -if (empty($paymentTypeId)) { - echo json_encode(['result' => false]); - return; -} - -// Catch API errors, write the message to your log and show the ClientMessage to the client. -try { - // Create an Unzer object using your private key and register a debug handler if you want to. - $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); - $unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - switch ($transactionType) { - case 'charge': - $transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - break; - default: - $transaction = $unzer->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - break; - } - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - if ($transaction->isSuccess()) { - echo json_encode(['transactionStatus' => 'success']); - return; - } - if ($transaction->isPending()) { - echo json_encode(['transactionStatus' => 'pending']); - return; - } -} catch (UnzerApiException $e) { - $_SESSION['merchantMessage'] = $e->getMerchantMessage(); - $_SESSION['clientMessage'] = $e->getClientMessage(); -} catch (RuntimeException $e) { - $_SESSION['merchantMessage'] = $e->getMessage(); -} - -echo json_encode(['transactionStatus' => 'error']); diff --git a/examples/Applepay/index.php b/examples/Applepay/index.php deleted file mode 100644 index 2765c13cb..000000000 --- a/examples/Applepay/index.php +++ /dev/null @@ -1,241 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - - -

Click here to open our test data in new tab.

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - - diff --git a/examples/Applepay/merchantvalidation.php b/examples/Applepay/merchantvalidation.php deleted file mode 100644 index fb3beb43b..000000000 --- a/examples/Applepay/merchantvalidation.php +++ /dev/null @@ -1,65 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - /* - * Just for demonstration purpose. - * It is NOT RECOMMENDED to get get the domain name this way on a production environment, because of security reasons. - */ - $domainName = $_SERVER['HTTP_HOST']; - - $applepaySession = new ApplepaySession(UNZER_EXAMPLE_APPLEPAY_MERCHANT_IDENTIFIER, 'PHP-SDK Example', $domainName); - $appleAdapter = new ApplepayAdapter(); - - $appleAdapter->init(UNZER_EXAMPLE_APPLEPAY_MERCHANT_CERT, UNZER_EXAMPLE_APPLEPAY_MERCHANT_CERT_KEY); - - // Send the applepay validation request. - $validationResponse = $appleAdapter->validateApplePayMerchant($merchantValidationURL, $applepaySession); - - // Return the validation response to your frontend. - print_r($validationResponse, 0); -} catch (RuntimeException | ApplepayMerchantValidationException $e) { - // Dont give internal error directly to the frontend. - throw new Exception('There has been an error validating the merchant. Please try again later.'); -} diff --git a/examples/Backend/CancelPaymentController.php b/examples/Backend/CancelPaymentController.php deleted file mode 100644 index f2a7e07ea..000000000 --- a/examples/Backend/CancelPaymentController.php +++ /dev/null @@ -1,80 +0,0 @@ -fetchPayment($paymentId); - -// Catch API errors, write the message to your log and show the ClientMessage to the client. -try { - // Create an Unzer object using your private key and register a debug handler if you want to. - $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); - $unzer->setDebugMode(true)->setDebugHandler($debugHandler); - - if ($payment->isCompleted()) { - $transaction = $unzer->cancelChargedPayment($paymentId); - $_SESSION['additionalPaymentInformation'] = '

Refund was successful.

'; - } else { - $transaction = $unzer->cancelAuthorizedPayment($paymentId); - $_SESSION['additionalPaymentInformation'] = '

Reversal was successful.

'; - } - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['ShortId'] = $transaction->getShortId(); - unset($_SESSION['isAuthorizeTransaction']); - - // Redirect to the failure page or to success depending on the state of the transaction - $redirect = !empty($transaction->getRedirectUrl()); - if (!$redirect && $transaction->isSuccess()) { - redirect(BACKEND_URL); - } elseif ($redirect && $transaction->isPending()) { - redirect(BACKEND_FAILURE_URL, 'Transaction initiated by merchant should not redirect to 3ds Page. The customer needs to - do the 3ds authentication first for that payment type.'); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(BACKEND_FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Backend/ChargePaymentController.php b/examples/Backend/ChargePaymentController.php deleted file mode 100644 index c2727a337..000000000 --- a/examples/Backend/ChargePaymentController.php +++ /dev/null @@ -1,73 +0,0 @@ -setDebugMode(true)->setDebugHandler($debugHandler); - - $transaction = $unzer->performChargeOnPayment($paymentId, new Charge()); - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['ShortId'] = $transaction->getShortId(); - unset($_SESSION['isAuthorizeTransaction']); - - // Redirect to the failure page or to success depending on the state of the transaction - $redirect = !empty($transaction->getRedirectUrl()); - if (!$redirect && $transaction->isSuccess()) { - $_SESSION['additionalPaymentInformation'] = '

Charge was successful.

'; - redirect(BACKEND_URL); - } elseif ($redirect && $transaction->isPending()) { - redirect(BACKEND_FAILURE_URL, 'Transaction initiated by merchant should not redirect to 3ds Page. The customer needs to - do the 3ds authentication first for that payment type.'); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(BACKEND_FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Backend/Failure.php b/examples/Backend/Failure.php deleted file mode 100644 index c28d75a6e..000000000 --- a/examples/Backend/Failure.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - -
-

Failure

-

- There has been an error performing the transaction - Merchant message (don\'t show this to the customer): ' . $_SESSION['merchantMessage'] . '

'; - } - if (isset($_SESSION['clientMessage']) && !empty($_SESSION['clientMessage'])) { - echo '

Client message (this is the error message for the customer): ' . $_SESSION['clientMessage'] . '

'; - } - if (isset($_SESSION['ShortId']) && !empty($_SESSION['ShortId'])) { - echo '

Please look for ShortId ' . $_SESSION['ShortId'] . ' in Unzer Insights to see the transaction.

'; - } - if (isset($_SESSION['PaymentId']) && !empty($_SESSION['PaymentId'])) { - echo '

The PaymentId of your transaction is \'' . $_SESSION['PaymentId'] . '\'.

'; - } - echo '

Back to Manage Payment page.

'; - ?> -

- start again -
- - diff --git a/examples/Backend/ManagePayment.php b/examples/Backend/ManagePayment.php deleted file mode 100644 index 8dc5bfd6b..000000000 --- a/examples/Backend/ManagePayment.php +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - - - -
-

Manage Payment (Merchant only)

-
- ' . $additionalPaymentInformation . ''; - } - - $paymentId = $_SESSION['PaymentId'] ?? null; - if ($paymentId !== null) { - echo '

The PaymentId of your transaction is \'' . $paymentId . '\'.

'; - } - - $unzer = new \UnzerSDK\Unzer(UNZER_PAPI_PRIVATE_KEY); - $payment = $unzer->fetchPayment($paymentId); - if ($shortId !== null) { - $defaultTransactionMessage = '

Please look for ShortId ' . $shortId . ' in Unzer Insights to see the transaction.

'; - $paylaterTransactionMessage = '

Please use the "descriptor" to look for the transaction in the Unzer Pay Later Merchant Portal.

'; - echo preg_match('/[\d]{4}.[\d]{4}.[\d]{4}/', $shortId) ? $defaultTransactionMessage : $paylaterTransactionMessage; - } - - if ($payment->getAmount()->getRemaining() > 0 && $payment->getAuthorization() !== null) { - echo '

Charge payment

-

You can use the payment ID to charge the payment.

-
- -
-
- -
-
-

'; - } - - if ($payment->getPaymentType()->supportsDirectPaymentCancel() && !$payment->isCanceled()) { - echo '

Cancel payment.

-

You can use the payment ID to cancel the payment.

-
- -
-
- -
-
-

'; - } - - if ($payment->getPaymentType() instanceof Paypal) { - echo '

PayPal Express only: Finalize a transaction

-

You can finalize a transaction in resumed state.

-
- - - -
-
- -
-
-

'; - } - - ?> - start again -
- - diff --git a/examples/Backend/UpdateTransactionController.php b/examples/Backend/UpdateTransactionController.php deleted file mode 100644 index ace3b9f72..000000000 --- a/examples/Backend/UpdateTransactionController.php +++ /dev/null @@ -1,105 +0,0 @@ -setDebugMode(true)->setDebugHandler($debugHandler); - - $payment = $unzer->fetchPayment($paymentId); - $transaction = $payment->getInitialTransaction(); - - if (!$transaction->isResumed()) { - redirect(BACKEND_FAILURE_URL, 'Transaction can only be updated in resumed state.'); - } - - //Add Shipping cost to initial amount. - $updatedCost = $transaction->getAmount() + $shippingCost; - - // Update transaction amount. - $transaction->setAmount($updatedCost); - - //Update basket - $basket = $payment->getBasket(); - - if ($basket !== null && $shippingCost > 0) { - $shippingItem = new BasketItem('shipping costs'); - $shippingItem->setAmountPerUnitGross($shippingCost); - $basket->addBasketItem($shippingItem); - $basket->setTotalValueGross($updatedCost); - $unzer->updateBasket($basket); - } - - if ($transaction instanceof Authorization) { - $unzer->updateAuthorization($transaction->getPaymentId(), $transaction); - } else { - /** @var $transaction Charge */ - $unzer->updateCharge($transaction->getPaymentId(), $transaction); - } - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['ShortId'] = $transaction->getShortId(); - unset($_SESSION['isAuthorizeTransaction']); - - // Redirect to the failure page or to success depending on the state of the transaction - $redirect = !empty($transaction->getRedirectUrl()); - if (!$redirect && $transaction->isSuccess()) { - $_SESSION['additionalPaymentInformation'] = '

Updating(PATCH) transaction was successful.

'; - redirect(BACKEND_URL); - } elseif ($redirect && $transaction->isPending()) { - redirect(BACKEND_FAILURE_URL, 'Transaction initiated by merchant should not redirect to 3ds Page. The customer needs to - do the 3ds authentication first for that payment type.'); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(BACKEND_FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Bancontact/Constants.php b/examples/Bancontact/Constants.php deleted file mode 100644 index c8bfd87ea..000000000 --- a/examples/Bancontact/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge transaction to get the redirectUrl. - $transaction = $unzer->charge(12.32, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the Bancontact page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Bancontact/index.php b/examples/Bancontact/index.php deleted file mode 100644 index 28700cefb..000000000 --- a/examples/Bancontact/index.php +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
- -
-
-
- -
-
- - - - diff --git a/examples/BankTransfer/Constants.php b/examples/BankTransfer/Constants.php deleted file mode 100644 index 92b31bb1d..000000000 --- a/examples/BankTransfer/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge transaction to get the redirectUrl. - $transaction = $unzer->charge(12.32, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the Sofort page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/BankTransfer/index.php b/examples/BankTransfer/index.php deleted file mode 100644 index 5d173b450..000000000 --- a/examples/BankTransfer/index.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/Card/Constants.php b/examples/Card/Constants.php deleted file mode 100644 index f499e1c00..000000000 --- a/examples/Card/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge/authorize transaction - // The 3D secured flag can be used to switch between 3ds and non-3ds. - // If your merchant is only configured for one of those you can omit the flag. - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $customer->setEmail('test@test.com'); - - switch ($transactionType) { - case 'charge': - $transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, $use3Ds); - break; - case 'payout': - $transaction = $unzer->payout(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); - break; - default: - $transaction = $unzer->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, $use3Ds); - break; - } - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the 3ds page or to success depending on the state of the transaction - $payment = $transaction->getPayment(); - $redirect = !empty($transaction->getRedirectUrl()); - - switch (true) { - case (!$redirect && $transaction->isSuccess()): - redirect(SUCCESS_URL); - break; - case (!$redirect && $transaction->isPending()): - redirect(PENDING_URL); - break; - case ($redirect && $transaction->isPending()): - redirect($transaction->getRedirectUrl()); - break; - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Card/index.php b/examples/Card/index.php deleted file mode 100644 index 87cb6c0b7..000000000 --- a/examples/Card/index.php +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example Data for VISA:

- - -

Example Data for Mastercard:

- - -

Click here to open our test data in new tab.

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- -
-
- - - -
-
-
- - -
-
- -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
-
- - - - diff --git a/examples/CardExtended/Constants.php b/examples/CardExtended/Constants.php deleted file mode 100644 index cd7efd897..000000000 --- a/examples/CardExtended/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge/authorize transaction - // For 3Ds2 compliance an email need to be set either in card type or in customer resource. - // If your merchant is only configured for one of those you can omit the flag. - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - switch ($transactionType) { - case 'charge': - $transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, true); - break; - case 'payout': - $transaction = $unzer->payout(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); - break; - default: - $transaction = $unzer->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, true); - break; - } - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the 3ds page or to success depending on the state of the transaction - $payment = $transaction->getPayment(); - $redirect = !empty($transaction->getRedirectUrl()); - - switch (true) { - case (!$redirect && $transaction->isSuccess()): - redirect(SUCCESS_URL); - break; - case (!$redirect && $transaction->isPending()): - redirect(PENDING_URL); - break; - case ($redirect && $transaction->isPending()): - redirect($transaction->getRedirectUrl()); - break; - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/CardExtended/index.php b/examples/CardExtended/index.php deleted file mode 100644 index cbd1ada4b..000000000 --- a/examples/CardExtended/index.php +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example Data for VISA:

- - -

Example Data for Mastercard:

- - -

Click here to open our test data in new tab.

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- - - -
-
- -
-
-
-
- -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
-
-
-
- -
-
- - - - diff --git a/examples/CardRecurring/Constants.php b/examples/CardRecurring/Constants.php deleted file mode 100644 index 94e49993d..000000000 --- a/examples/CardRecurring/Constants.php +++ /dev/null @@ -1,13 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - $charge = (new Charge(12.99, 'EUR', MY_RETURN_CONTROLLER_URL)) - ->setRecurrenceType($recurrenceType, $paymentType); - - $transaction = $unzer->performCharge($charge, $paymentTypeId); - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentTypeId'] = $paymentTypeId; - $_SESSION['ShortId'] = $transaction->getShortId(); - $_SESSION['recurrenceType'] = $transaction->getRecurrenceType(); - - // Redirect to the 3ds page or to success depending on the state of the transaction - $redirect = !empty($transaction->getRedirectUrl()); - if (!$redirect && $transaction->isSuccess()) { - redirect(SUCCESS_URL); - } elseif ($redirect && $transaction->isPending()) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/CardRecurring/RecurringPaymentController.php b/examples/CardRecurring/RecurringPaymentController.php deleted file mode 100644 index b4d14bcb2..000000000 --- a/examples/CardRecurring/RecurringPaymentController.php +++ /dev/null @@ -1,77 +0,0 @@ -setDebugMode(true)->setDebugHandler($debugHandler); - - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $customer->setEmail('test@test.com'); - - $transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, true, null, null, $recurrenceTyp); - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentTypeId'] = $paymentTypeId; - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the failure page or to success depending on the state of the transaction - $redirect = !empty($transaction->getRedirectUrl()); - if (!$redirect && $transaction->isSuccess()) { - redirect(SUCCESS_URL); - } elseif ($redirect && $transaction->isPending()) { - redirect(FAILURE_URL, 'Transaction initiated by merchant should not redirect to 3ds Page. The customer needs to - do the 3ds authentication first for that payment type.'); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/CardRecurring/ReturnController.php b/examples/CardRecurring/ReturnController.php deleted file mode 100644 index 6e7e014ac..000000000 --- a/examples/CardRecurring/ReturnController.php +++ /dev/null @@ -1,62 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Redirect to success if the payment has been successfully completed or is still in handled. - /** @var Card $paymentType */ - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - if ($paymentType->isRecurring()) { - redirect(SUCCESS_URL); - } - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} - -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/CardRecurring/index.php b/examples/CardRecurring/index.php deleted file mode 100644 index 1bc34ef3c..000000000 --- a/examples/CardRecurring/index.php +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example Data for VISA:

- - -

Example Data for Mastercard:

- - -

Click here to open our test data in new tab.

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
- - -
-
- -
-
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
- -
-
- - - - diff --git a/examples/Constants.php b/examples/Constants.php deleted file mode 100755 index be2f01a4b..000000000 --- a/examples/Constants.php +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - Unzer UI Examples - - - - -

Create

-

- The payment is in create state, meaning the Payment page was not used for a payment yet.
- The payment also stays in this state when the customer clicked the "Back to merchant" button or closed the browser tab.
- It is still active and could be used by the customer for the current payment.
- Payment page'; - - if (!empty($additionalPaymentInformation)) { - echo $additionalPaymentInformation; - } - - if ($shortId !== null) { - $defaultTransactionMessage = '

Please look for ShortId ' . $shortId . ' in Unzer Insights to see the transaction.

'; - $paylaterTransactionMessage = '

Please use the "descriptor" to look for the transaction in the Unzer Pay Later Merchant Portal.

'; - echo preg_match('/[\d]{4}.[\d]{4}.[\d]{4}/', $shortId) ? $defaultTransactionMessage : $paylaterTransactionMessage; - } - $paymentId = $_SESSION['PaymentId'] ?? null; - if ($paymentId !== null) { - echo '

The PaymentId is \'' . $paymentId . '\'.

'; - } - - if ($paymentTypeId !== null) { - echo '

The TypeId for the recurring payment is \'' . $paymentTypeId . '\'. You can use it - now for subsequent transactions.

-
- -
-
- -
-
-
'; - } - ?> -

-

start again

- - diff --git a/examples/EPSCharge/Constants.php b/examples/EPSCharge/Constants.php deleted file mode 100755 index 660fe965e..000000000 --- a/examples/EPSCharge/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge to get the redirectUrl. - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $charge = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the EPS page of the selected bank - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/EPSCharge/index.php b/examples/EPSCharge/index.php deleted file mode 100755 index b2edc4404..000000000 --- a/examples/EPSCharge/index.php +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
-
- -
-
- - - - diff --git a/examples/EmbeddedPayPage/Constants.php b/examples/EmbeddedPayPage/Constants.php deleted file mode 100644 index db6d5d52e..000000000 --- a/examples/EmbeddedPayPage/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // A customer with matching addresses is mandatory for Installment payment type - $address = (new Address()) - ->setName('Max Mustermann') - ->setStreet('Vangerowstr. 18') - ->setCity('Heidelberg') - ->setZip('69155') - ->setCountry('DE'); - - // Create a charge/authorize transaction - $customer = CustomerFactory::createCustomer('Max', 'Mustermann') - ->setSalutation(Salutations::MR) - ->setBirthDate('2000-02-12') - ->setLanguage('de') - ->setEmail('test@test.com'); - - // These are the mandatory parameters for the payment page ... - $paypage = new Paypage(119.00, 'EUR', RETURN_CONTROLLER_URL); - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - // Just for example purpose. Make sure to generate a unique ID. - $threatMetrixId = 'php-sdk-example_' . $orderId; - - // ... however you can customize the Payment Page using additional parameters. - $paypage->setShopName('My Test Shop') - ->setTagline('Try and stop us from being awesome!') - ->setTermsAndConditionUrl('https://www.unzer.com/en/') - ->setPrivacyPolicyUrl('https://www.unzer.com/de/datenschutz/') - ->setOrderId($orderId) - ->setLogoImage(UNZER_PP_LOGO_URL) - ->setAdditionalAttribute('riskData.threatMetrixId', $threatMetrixId) - ->setAdditionalAttribute('riskData.customerGroup', CustomerGroups::GOOD) - ->setAdditionalAttribute('riskData.confirmedAmount', 99.99) - ->setAdditionalAttribute('riskData.confirmedOrders', 2) - ->setAdditionalAttribute('riskData.registrationLevel', CustomerRegistrationLevel::REGISTERED) - ->setAdditionalAttribute('riskData.registrationDate ', '20160412') - ->setInvoiceId('i' . microtime(true)); - - // ... in order to enable Unzer Instalment you will need to set the effectiveInterestRate as well. - $paypage->setEffectiveInterestRate(4.99); - - // ... a Basket is mandatory for InstallmentSecured - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - if ($transactionType === 'charge') { - $unzer->initPayPageCharge($paypage, $customer, $basket); - } else { - // For demo purpose we set customer address for authorize only to enable instalment payment. - // That way e.g. Invoice secured will display customer form on payment page. - $customer - ->setShippingAddress($address) - ->setBillingAddress($address); - $unzer->initPayPageAuthorize($paypage, $customer, $basket); - } - - $_SESSION['PaymentId'] = $paypage->getPaymentId(); - echo json_encode(['token' => $paypage->getId()]); - die(); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} - -http_response_code(400); -echo json_encode(['merchant' => $merchantMessage, 'customer' => $clientMessage]); diff --git a/examples/EmbeddedPayPage/index.php b/examples/EmbeddedPayPage/index.php deleted file mode 100644 index 0fa9ab302..000000000 --- a/examples/EmbeddedPayPage/index.php +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - - - -
-

Click here to open our test data in new tab.

- -
- -
-
- - -
-
-
-
- - -
-
-
- - -
- - -
- -
-
- - - - diff --git a/examples/ExampleDebugHandler.php b/examples/ExampleDebugHandler.php deleted file mode 100755 index 0b855ff1b..000000000 --- a/examples/ExampleDebugHandler.php +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - -
-

Failure

-

- There has been an error completing the payment. - Merchant message (don\'t show this to the customer): ' . $_SESSION['merchantMessage'] . '

'; - } - if (isset($_SESSION['clientMessage']) && !empty($_SESSION['clientMessage'])) { - echo '

Client message (this is the error message for the customer): ' . $_SESSION['clientMessage'] . '

'; - } - if (isset($_SESSION['ShortId']) && !empty($_SESSION['ShortId'])) { - echo '

Please look for ShortId ' . $_SESSION['ShortId'] . ' in Unzer Insights to see the transaction.

'; - } - if (isset($_SESSION['PaymentId']) && !empty($_SESSION['PaymentId'])) { - echo '

The PaymentId of your transaction is \'' . $_SESSION['PaymentId'] . '\'.

'; - } - ?> -

- start again -
- - diff --git a/examples/Giropay/Constants.php b/examples/Giropay/Constants.php deleted file mode 100644 index 0bbb5fc61..000000000 --- a/examples/Giropay/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge to get the redirectUrl. - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $charge = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the Giropay page of the selected bank - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Giropay/index.php b/examples/Giropay/index.php deleted file mode 100644 index 3b9fb05c3..000000000 --- a/examples/Giropay/index.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/Googlepay/Constants.php b/examples/Googlepay/Constants.php deleted file mode 100644 index 863a4e4fb..000000000 --- a/examples/Googlepay/Constants.php +++ /dev/null @@ -1,9 +0,0 @@ -typeId; -$transactionType = $jsonData->transaction_type ?? 'authorize'; - -// You will need the id of the payment type created in the frontend (index.php) -if (empty($paymentTypeId)) { - echo json_encode(['result' => false]); - return; -} - -$transactionResult = [ - TRANSACTION_STATUS_KEY => 'error', - REDIRECT_URL_KEY => '' -]; - -// Catch API errors, write the message to your log and show the ClientMessage to the client. -try { - // Create an Unzer object using your private key and register a debug handler if you want to. - $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); - $unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - if ($transactionType === 'charge') { - $charge = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'EUR', RETURN_CONTROLLER_URL); - $transaction = $unzer->performCharge($charge, $paymentTypeId); - } else { - $authorize = new \UnzerSDK\Resources\TransactionTypes\Authorization(12.32, 'EUR', RETURN_CONTROLLER_URL); - $transaction = $unzer->performAuthorization($authorize, $paymentTypeId); - } - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - $redirectUrl = $transaction->getRedirectUrl(); - - if (!empty($redirectUrl)) { - $transactionResult[REDIRECT_URL_KEY] = $redirectUrl; - } - - if ($transaction->isSuccess()) { - $transactionResult[TRANSACTION_STATUS_KEY] = 'success'; - echo json_encode($transactionResult); - return; - } - if ($transaction->isPending()) { - $transactionResult[TRANSACTION_STATUS_KEY] = 'pending'; - - echo json_encode($transactionResult); - return; - } -} catch (UnzerApiException $e) { - $_SESSION['merchantMessage'] = $e->getMerchantMessage(); - $_SESSION['clientMessage'] = $e->getClientMessage(); -} catch (RuntimeException $e) { - $_SESSION['merchantMessage'] = $e->getMessage(); -} - -echo json_encode($transactionResult); diff --git a/examples/Googlepay/index.php b/examples/Googlepay/index.php deleted file mode 100644 index 86dc146a1..000000000 --- a/examples/Googlepay/index.php +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - - - -

Click here to open our test data in new tab.
-

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - -
-
- - - - - diff --git a/examples/HostedPayPage/Constants.php b/examples/HostedPayPage/Constants.php deleted file mode 100644 index 22a8644ec..000000000 --- a/examples/HostedPayPage/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // A customer with matching addresses is mandatory for Installment payment type - $address = (new Address()) - ->setName('Max Mustermann') - ->setStreet('Vangerowstr. 18') - ->setCity('Heidelberg') - ->setZip('69155') - ->setCountry('DE'); - - // Create a charge/authorize transaction - $customer = CustomerFactory::createCustomer('Max', 'Mustermann') - ->setSalutation(Salutations::MR) - ->setBirthDate('2000-02-12') - ->setLanguage('de') - ->setEmail('test@test.com'); - - // These are the mandatory parameters for the payment page ... - $paypage = new Paypage(119.00, 'EUR', RETURN_CONTROLLER_URL); - - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - // Just for example purpose. Make sure to generate a unique ID. - $threatMetrixId = 'php-sdk-example_' . $orderId; - - - // ... however you can customize the Payment Page using additional parameters. - $paypage->setShopName('My Test Shop') - ->setShopDescription('Best shop in the whole world!') - ->setTagline('Try and stop us from being awesome!') - ->setOrderId('OrderNr' . $orderId) - ->setTermsAndConditionUrl('https://www.unzer.com/en/') - ->setPrivacyPolicyUrl('https://www.unzer.com/de/datenschutz/') - ->setImprintUrl('https://www.unzer.com/de/impressum') - ->setHelpUrl('https://www.unzer.com/de/support') - ->setContactUrl('https://www.unzer.com/en/ueber-unzer') - ->setFullPageImage(UNZER_PP_FULL_PAGE_IMAGE_URL) - ->setLogoImage(UNZER_PP_LOGO_URL) - ->setAdditionalAttribute('riskData.threatMetrixId', $threatMetrixId) - ->setAdditionalAttribute('riskData.customerGroup', CustomerGroups::GOOD) - ->setAdditionalAttribute('riskData.confirmedAmount', 99.99) - ->setAdditionalAttribute('riskData.confirmedOrders', 2) - ->setAdditionalAttribute('riskData.registrationLevel', CustomerRegistrationLevel::REGISTERED) - ->setAdditionalAttribute('riskData.registrationDate ', '20160412') - ->setInvoiceId('i' . microtime(true)); - - // ... in order to enable Unzer Instalment you will need to set the effectiveInterestRate as well. - $paypage->setEffectiveInterestRate(4.99); - - // ... a Basket is mandatory for InstallmentSecured - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - if ($transactionType === 'charge') { - $unzer->initPayPageCharge($paypage, $customer, $basket); - } else { - // For demo purpose we set customer address for authorize only to enable instalment payment. - // That way e.g. Invoice secured will display customer form on payment page. - $customer - ->setShippingAddress($address) - ->setBillingAddress($address); - $unzer->initPayPageAuthorize($paypage, $customer, $basket); - } - - $_SESSION['PaymentId'] = $paypage->getPaymentId(); - - // Redirect to the paypage - redirect($paypage->getRedirectUrl()); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/HostedPayPage/index.php b/examples/HostedPayPage/index.php deleted file mode 100644 index d69db6146..000000000 --- a/examples/HostedPayPage/index.php +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Click here to open our test data in new tab.

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
- - - -
- -
-
- - - diff --git a/examples/IDeal/Constants.php b/examples/IDeal/Constants.php deleted file mode 100644 index 9278d8207..000000000 --- a/examples/IDeal/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge to get the redirectUrl. - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $charge = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the iDeal page of the selected bank - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/IDeal/index.php b/examples/IDeal/index.php deleted file mode 100644 index 82809c44f..000000000 --- a/examples/IDeal/index.php +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
-
- -
-
- - - - diff --git a/examples/InstallmentSecured/Constants.php b/examples/InstallmentSecured/Constants.php deleted file mode 100644 index 6607fcdb2..000000000 --- a/examples/InstallmentSecured/Constants.php +++ /dev/null @@ -1,13 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Use the quote or order id from your shop - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - /** @var InstallmentSecured $paymentType */ - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - // A customer with matching addresses is mandatory for Installment payment type - $address = (new Address()) - ->setName('Linda Heideich') - ->setStreet('Vangerowstr. 18') - ->setCity('Heidelberg') - ->setZip('69155') - ->setCountry('DE'); - $customer = CustomerFactory::createCustomer('Linda', 'Heideich') - ->setBirthDate('2000-02-12') - ->setBillingAddress($address) - ->setShippingAddress($address) - ->setEmail('linda.heideich@test.de'); - - // A Basket is mandatory for Installment Secured payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - // initialize the payment - $authorize = $unzer->authorize( - $paymentType->getTotalPurchaseAmount(), - 'EUR', - $paymentType, - CONTROLLER_URL, - $customer, - $orderId, - null, - $basket - ); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['PaymentId'] = $authorize->getPaymentId(); - - // Redirect to the success or failure depending on the state of the transaction - if ($authorize->isSuccess()) { - redirect(CONFIRM_URL); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $authorize->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/InstallmentSecured/PlaceOrderController.php b/examples/InstallmentSecured/PlaceOrderController.php deleted file mode 100644 index da9b1fb1d..000000000 --- a/examples/InstallmentSecured/PlaceOrderController.php +++ /dev/null @@ -1,65 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $payment = $unzer->fetchPayment($paymentId); - $charge = $payment->charge(); - - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the success or failure depending on the state of the transaction - if ($charge->isSuccess()) { - redirect(SUCCESS_URL); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/InstallmentSecured/confirm.php b/examples/InstallmentSecured/confirm.php deleted file mode 100644 index a78076b5a..000000000 --- a/examples/InstallmentSecured/confirm.php +++ /dev/null @@ -1,115 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $payment = $unzer->fetchPayment($paymentId); - - $PDFLink = $payment->getAuthorization()->getPDFLink(); - /** @var InstallmentSecured $type */ - $type = $payment->getPaymentType(); - $totalAmount = $type->getTotalAmount(); - $totalPurchaseAmount = $type->getTotalPurchaseAmount(); - $totalInterestAmount = $type->getTotalInterestAmount(); - $currency = $payment->getAmount()->getCurrency(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); - redirect(FAILURE_URL, $merchantMessage, $clientMessage); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); - redirect(FAILURE_URL, $merchantMessage, $clientMessage); -} -?> - - - - - - Unzer UI Examples - - - - - - - - - -
-

- - - Confirm instalment plan - Download the instalment plant information and confirm your order... - -

-
- -
-
-
- Total Purchase Amount -
-
- -
- Total Interest Amount -
-
- -
- Total Amount -
-
-
-
- Please download your rate plan here
-
-
Place order
-
- - - diff --git a/examples/InstallmentSecured/index.php b/examples/InstallmentSecured/index.php deleted file mode 100644 index d147a5a0a..000000000 --- a/examples/InstallmentSecured/index.php +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
- -
-
-
- -
-
- - - - - diff --git a/examples/Invoice/Constants.php b/examples/Invoice/Constants.php deleted file mode 100644 index 8cedc05e7..000000000 --- a/examples/Invoice/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - /** @var Invoice $invoice */ - $invoice = $unzer->createPaymentType(new Invoice()); - - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - $transaction = $invoice->charge(12.99, 'EUR', CONTROLLER_URL, $customer, $orderId); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['ShortId'] = $transaction->getShortId(); - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['additionalPaymentInformation'] = - sprintf( - "Please transfer the amount of %f %s to the following account:

" - . "Holder: %s
" - . "IBAN: %s
" - . "BIC: %s

" - . "Please use only this identification number as the descriptor:
" - . "%s", - $transaction->getAmount(), - $transaction->getCurrency(), - $transaction->getHolder(), - $transaction->getIban(), - $transaction->getBic(), - $transaction->getDescriptor() - ); - - - // To avoid redundant code this example redirects to the general ReturnController which contains the code example to handle payment results. - redirect(RETURN_CONTROLLER_URL); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Invoice/index.php b/examples/Invoice/index.php deleted file mode 100644 index 0a35d4bac..000000000 --- a/examples/Invoice/index.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -
-
- -
-
- - - diff --git a/examples/InvoiceSecured/Constants.php b/examples/InvoiceSecured/Constants.php deleted file mode 100644 index 824ced2b1..000000000 --- a/examples/InvoiceSecured/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - // A Basket is mandatory for Invoice Secured payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - $transaction = $unzer->charge(119.0, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['ShortId'] = $transaction->getShortId(); - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['additionalPaymentInformation'] = - sprintf( - "Please transfer the amount of %f %s to the following account:

" - . "Holder: %s
" - . "IBAN: %s
" - . "BIC: %s

" - . "Please use only this identification number as the descriptor:
" - . "%s", - $transaction->getAmount(), - $transaction->getCurrency(), - $transaction->getHolder(), - $transaction->getIban(), - $transaction->getBic(), - $transaction->getDescriptor() - ); - - // To avoid redundant code this example redirects to the general ReturnController which contains the code example to handle payment results. - redirect(RETURN_CONTROLLER_URL); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -// Write the merchant message to your log. -// Show the client message to the customer (it is localized). -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/InvoiceSecured/index.php b/examples/InvoiceSecured/index.php deleted file mode 100644 index 30ee37307..000000000 --- a/examples/InvoiceSecured/index.php +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
-
- -
-
- - - - - diff --git a/examples/Klarna/Constants.php b/examples/Klarna/Constants.php deleted file mode 100644 index b3f45b3d5..000000000 --- a/examples/Klarna/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - // A Basket is mandatory for Invoice Secured payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - // A customer is mandatory for Klarna payment type - $address = (new Address()) - ->setName('Max Universum') - ->setStreet('Hugo-Junkers-Str. 4') - ->setZip('60386') - ->setCity('Frankfurt am Main') - ->setCountry('DE') - ->setState('DE-BO') - ->setShippingType(ShippingTypes::EQUALS_BILLING); - - $customer = CustomerFactory::createCustomer('Peter', 'Universum') - ->setSalutation(Salutations::MR) - ->setCompany('Unzer GmbH') - ->setBirthDate('1989-12-24') - ->setEmail('peter.universum@universum-group.de') - ->setMobile('+49172123456') - ->setPhone('+4962216471100') - ->setBillingAddress($address) - ->setLanguage('de'); - - $transactionData = [119.00, 'EUR', RETURN_CONTROLLER_URL]; - $additionalTransactionData = [ - 'termsAndConditionUrl' => 'https://www.unzer.com/de/', - 'privacyPolicyUrl' => 'https://www.unzer.com/de/' - ]; - - // Create a authorize transaction to get the redirectUrl. - $authorizationInstance = (new Authorization(...$transactionData)) - ->setAdditionalTransactionData((object)$additionalTransactionData); - $transaction = $unzer->performAuthorization($authorizationInstance, $paymentTypeId, $customer, null, $basket); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - $_SESSION['isAuthorizeTransaction'] = true; - - // Redirect to the Klarna page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Klarna/index.php b/examples/Klarna/index.php deleted file mode 100644 index 047c0bb72..000000000 --- a/examples/Klarna/index.php +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Click here to open our test data in new tab.

- -
- -
-
-
- -
-
- - - - diff --git a/examples/PayPal/Constants.php b/examples/PayPal/Constants.php deleted file mode 100755 index 17a496a80..000000000 --- a/examples/PayPal/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(12.32) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(12.32) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - // Create a charge/authorize transaction to get the redirectUrl. - if ($transactionType === 'charge') { - $charge = new Charge(12.32, 'EUR', RETURN_CONTROLLER_URL); - if ($useExpressCheckout) { - $charge->setCheckoutType('express', $paymentType); - } - $transaction = $unzer->performCharge($charge, $paymentType, null, null, $basket); - } else { - $authorize = new Authorization(12.32, 'EUR', RETURN_CONTROLLER_URL); - if ($useExpressCheckout) { - $authorize->setCheckoutType('express', $paymentType); - } - $transaction = $unzer->performAuthorization($authorize, $paymentType, null, null, $basket); - } - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the PayPal page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PayPal/index.php b/examples/PayPal/index.php deleted file mode 100755 index 0fb4842b2..000000000 --- a/examples/PayPal/index.php +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example data:

- -Attention: We recommend to create your own PayPal test account here. - -

Click here to open our test data in new tab.

- -
- -
- -
-
- - -
-
-
-
- - -
-
-
- - -

PayPal

-
-
-
- -
- -

PayPal Express

-
-
- - - - diff --git a/examples/PayPalRecurring/Constants.php b/examples/PayPalRecurring/Constants.php deleted file mode 100644 index 9ca9757a6..000000000 --- a/examples/PayPalRecurring/Constants.php +++ /dev/null @@ -1,13 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $recurring = $unzer->activateRecurringPayment($paymentTypeId, MY_RETURN_CONTROLLER_URL); - - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentTypeId'] = $paymentTypeId; - $_SESSION['ShortId'] = $recurring->getShortId(); - - // Redirect to the 3ds page or to success depending on the state of the transaction - if (empty($recurring->getRedirectUrl()) && $recurring->isSuccess()) { - redirect(SUCCESS_URL); - } elseif (!empty($recurring->getRedirectUrl()) && $recurring->isPending()) { - redirect($recurring->getRedirectUrl()); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $recurring->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PayPalRecurring/ReturnController.php b/examples/PayPalRecurring/ReturnController.php deleted file mode 100644 index 14fbe87fc..000000000 --- a/examples/PayPalRecurring/ReturnController.php +++ /dev/null @@ -1,62 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Redirect to success if the payment has been successfully completed or is still in handled. - /** @var Card $paymentType */ - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - if ($paymentType->isRecurring()) { - redirect(SUCCESS_URL); - } - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} - -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PayPalRecurring/index.php b/examples/PayPalRecurring/index.php deleted file mode 100644 index 596034ba4..000000000 --- a/examples/PayPalRecurring/index.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example data:

- -Attention: We recommend to create your own PayPal test account here. - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/PayU/Constants.php b/examples/PayU/Constants.php deleted file mode 100644 index e8717edaf..000000000 --- a/examples/PayU/Constants.php +++ /dev/null @@ -1,13 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge transaction to get the redirectUrl. - $transaction = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'PLN', RETURN_CONTROLLER_URL); - $unzer->performCharge($transaction, $paymentTypeId); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the PayU page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PayU/index.php b/examples/PayU/index.php deleted file mode 100644 index ab5072b07..000000000 --- a/examples/PayU/index.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/PaylaterDirectDebit/Constants.php b/examples/PaylaterDirectDebit/Constants.php deleted file mode 100644 index a8a77f2d1..000000000 --- a/examples/PaylaterDirectDebit/Constants.php +++ /dev/null @@ -1,9 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Use the quote or order id from your shop - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - /** @var PaylaterDirectDebit $paymentType */ - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - // A customer with matching addresses is mandatory for Direct Debit payment type - $address = (new Address()) - ->setName('Linda Heideich') - ->setStreet('Vangerowstr. 18') - ->setCity('Heidelberg') - ->setZip('69155') - ->setCountry('DE'); - $customer = CustomerFactory::createCustomer('Linda', 'Heideich') - ->setBirthDate('2000-02-12') - ->setBillingAddress($address) - ->setShippingAddress($address) - ->setEmail('linda.heideich@test.de'); - - // A Basket is mandatory for Paylater Direct Debit payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross($orderAmount) - ->setVat(19) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $currency = 'EUR'; - $basket = new Basket($orderId); - $basket->setTotalValueGross($orderAmount) - ->addBasketItem($basketItem) - ->setCurrencyCode($currency); - - $riskData = (new RiskData()) - ->setThreatMetrixId($threatMetrixId) - ->setCustomerGroup(CustomerGroups::GOOD) - ->setConfirmedAmount(99.99) - ->setConfirmedOrders(2) - ->setRegistrationLevel(CustomerRegistrationLevel::REGISTERED) - ->setRegistrationDate('20160412'); - - // initialize the payment - $authorize = (new Authorization($orderAmount, $currency, RETURN_CONTROLLER_URL)) - ->setRiskData($riskData); - - $unzer->performAuthorization( - $authorize, - $paymentType, - $customer, - null, - $basket - ); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['PaymentId'] = $authorize->getPaymentId(); - $_SESSION['ShortId'] = $authorize->getShortId(); - $_SESSION['additionalPaymentInformation'] = sprintf("Descriptor: %s", $authorize->getDescriptor()); - - // Redirect to the success or failure depending on the state of the transaction - if ($authorize->isSuccess()) { - redirect(SUCCESS_URL); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $authorize->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PaylaterDirectDebit/index.php b/examples/PaylaterDirectDebit/index.php deleted file mode 100644 index 430c41294..000000000 --- a/examples/PaylaterDirectDebit/index.php +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.
-

- - -
-
- -
- -
- -
-
- - - - - diff --git a/examples/PaylaterInstallment/Constants.php b/examples/PaylaterInstallment/Constants.php deleted file mode 100644 index dd238d23f..000000000 --- a/examples/PaylaterInstallment/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Use the quote or order id from your shop - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - /** @var \UnzerSDK\Resources\PaymentTypes\PaylaterInstallment $paymentType */ - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - // A customer with matching addresses is mandatory for Installment payment type - $address = (new Address()) - ->setName('Linda Heideich') - ->setStreet('Vangerowstr. 18') - ->setCity('Heidelberg') - ->setZip('69155') - ->setCountry('DE'); - $customer = CustomerFactory::createCustomer('Linda', 'Heideich') - ->setBirthDate('2000-02-12') - ->setBillingAddress($address) - ->setShippingAddress($address) - ->setEmail('linda.heideich@test.de'); - - // A Basket is mandatory for Paylater Installment payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross($orderAmount) - ->setVat(19) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $currency = 'EUR'; - $basket = new Basket($orderId); - $basket->setTotalValueGross($orderAmount) - ->addBasketItem($basketItem) - ->setCurrencyCode($currency); - - $riskData = (new RiskData()) - ->setThreatMetrixId($threatMetrixId) - ->setCustomerGroup(CustomerGroups::GOOD) - ->setConfirmedAmount(99.99) - ->setConfirmedOrders(2) - ->setRegistrationLevel(CustomerRegistrationLevel::REGISTERED) - ->setRegistrationDate('20160412'); - - // initialize the payment - $authorize = (new Authorization($orderAmount, $currency, RETURN_CONTROLLER_URL)) - ->setRiskData($riskData); - - $unzer->performAuthorization( - $authorize, - $paymentType, - $customer, - null, - $basket - ); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['PaymentId'] = $authorize->getPaymentId(); - $_SESSION['ShortId'] = $authorize->getShortId(); - $_SESSION['additionalPaymentInformation'] = sprintf("Descriptor: %s", $authorize->getDescriptor()); - - // Redirect to the success or failure depending on the state of the transaction - if ($authorize->isSuccess()) { - redirect(SUCCESS_URL); - } - - // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $authorize->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PaylaterInstallment/index.php b/examples/PaylaterInstallment/index.php deleted file mode 100644 index 886ecae26..000000000 --- a/examples/PaylaterInstallment/index.php +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.
-

- -
-
-
-
- -
-
- - -
- - - - - diff --git a/examples/PaylaterInvoice/Constants.php b/examples/PaylaterInvoice/Constants.php deleted file mode 100644 index 5bad530f6..000000000 --- a/examples/PaylaterInvoice/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - // A Basket is mandatory for Invoice Secured payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR') - ->setOrderId($orderId); - - $riskData = (new RiskData()) - ->setThreatMetrixId($threatMetrixId) - ->setCustomerGroup(CustomerGroups::GOOD) - ->setConfirmedAmount(99.99) - ->setConfirmedOrders(2) - ->setRegistrationLevel(CustomerRegistrationLevel::REGISTERED) - ->setRegistrationDate('20160412'); - - $authorization = (new Authorization(119.00, 'EUR', CONTROLLER_URL)) - ->setRiskData($riskData); - - $paymentType = $unzer->fetchPaymentType($paymentTypeId); - - $transaction = $unzer->performAuthorization($authorization, $paymentType, $customerId, null, $basket); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['ShortId'] = $transaction->getShortId(); - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['isAuthorizeTransaction'] = true; - $_SESSION['additionalPaymentInformation'] = - sprintf( - "Please transfer the amount of %f %s to the following account:

" - . "Holder: %s
" - . "IBAN: %s
" - . "BIC: %s

" - . "Please use only this identification number as the descriptor:
" - . "%s", - $transaction->getAmount(), - $transaction->getCurrency(), - $transaction->getHolder(), - $transaction->getIban(), - $transaction->getBic(), - $transaction->getDescriptor() - ); - - // To avoid redundant code this example redirects to the general ReturnController which contains the code example to handle payment results. - redirect(RETURN_CONTROLLER_URL); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -// Write the merchant message to your log. -// Show the client message to the customer (it is localized). -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PaylaterInvoice/index.php b/examples/PaylaterInvoice/index.php deleted file mode 100644 index c00162c65..000000000 --- a/examples/PaylaterInvoice/index.php +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
- -
-
-
-
- -
-
- - - - - diff --git a/examples/Pending.php b/examples/Pending.php deleted file mode 100644 index 311a19c25..000000000 --- a/examples/Pending.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - -
-

Pending

-

- The payment transaction has been completed, however it has the state pending.
- The status of the payment is not definite at the moment.
- You can create the Order in your shop but should set its status to pending payment. -

-

- Please use the webhook feature to be informed about later changes of the payment. - You should ship only if the status changes to success. - Please look for ShortId ' . $_SESSION['ShortId'] . ' in Unzer Insights to see the transaction.

'; - } - if (isset($_SESSION['PaymentId']) && !empty($_SESSION['PaymentId'])) { - echo '

The PaymentId of your transaction is \'' . $_SESSION['PaymentId'] . '\'.

'; - } - ?> -

- start again -
- - diff --git a/examples/PostFinanceCard/Constants.php b/examples/PostFinanceCard/Constants.php deleted file mode 100644 index 36f6f9779..000000000 --- a/examples/PostFinanceCard/Constants.php +++ /dev/null @@ -1,13 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge transaction to get the redirectUrl. - $transaction = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'CHF', RETURN_CONTROLLER_URL); - $unzer->performCharge($transaction, $paymentTypeId); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the PostFinance page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PostFinanceCard/index.php b/examples/PostFinanceCard/index.php deleted file mode 100644 index d5cdfe117..000000000 --- a/examples/PostFinanceCard/index.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/PostFinanceEfinance/Constants.php b/examples/PostFinanceEfinance/Constants.php deleted file mode 100644 index f8fa1bebd..000000000 --- a/examples/PostFinanceEfinance/Constants.php +++ /dev/null @@ -1,13 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge transaction to get the redirectUrl. - $transaction = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'CHF', RETURN_CONTROLLER_URL); - $unzer->performCharge($transaction, $paymentTypeId); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the PostFinance page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PostFinanceEfinance/index.php b/examples/PostFinanceEfinance/index.php deleted file mode 100644 index cf121b87d..000000000 --- a/examples/PostFinanceEfinance/index.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/Prepayment/Constants.php b/examples/Prepayment/Constants.php deleted file mode 100644 index 2f0965beb..000000000 --- a/examples/Prepayment/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - /** @var Prepayment $prepayment */ - $prepayment = $unzer->createPaymentType(new Prepayment()); - - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - $transaction = $prepayment->charge(12.99, 'EUR', CONTROLLER_URL, $customer, $orderId); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['ShortId'] = $transaction->getShortId(); - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['additionalPaymentInformation'] = - sprintf( - "Please transfer the amount of %f %s to the following account:

" - . "Holder: %s
" - . "IBAN: %s
" - . "BIC: %s

" - . "Please use only this identification number as the descriptor:
" - . "%s", - $transaction->getAmount(), - $transaction->getCurrency(), - $transaction->getHolder(), - $transaction->getIban(), - $transaction->getBic(), - $transaction->getDescriptor() - ); - - // To avoid redundant code this example redirects to the general ReturnController which contains the code example to handle payment results. - redirect(RETURN_CONTROLLER_URL); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Prepayment/index.php b/examples/Prepayment/index.php deleted file mode 100644 index 87ea973f8..000000000 --- a/examples/Prepayment/index.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -
-
- -
-
- - - diff --git a/examples/Przelewy24/Constants.php b/examples/Przelewy24/Constants.php deleted file mode 100644 index cb238dd72..000000000 --- a/examples/Przelewy24/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge to get the redirectUrl. - $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); - $charge = $unzer->charge(12.99, 'PLN', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the P24 page of the selected bank - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Przelewy24/index.php b/examples/Przelewy24/index.php deleted file mode 100644 index 40368426b..000000000 --- a/examples/Przelewy24/index.php +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
-
- -
-
- - - - diff --git a/examples/ReturnController.php b/examples/ReturnController.php deleted file mode 100644 index 43951c907..000000000 --- a/examples/ReturnController.php +++ /dev/null @@ -1,128 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Redirect to success if the payment has been successfully completed. - $payment = $unzer->fetchPayment($paymentId); - $transaction = $payment->getInitialTransaction(); - - // Ensure that shortId is also set in case of payment pages. - if ($transaction !== null) { - $_SESSION['ShortId'] = $_SESSION['ShortId'] ?? $transaction->getShortId(); - } - - if ($payment->isCompleted()) { - // The payment process has been successful. - // You show the success page. - // Goods can be shipped. - $redirectUrl = SUCCESS_URL; - } - - if ($payment->isCreate()) { - // The payment is in create state, meaning the customer clicked the "Back to Merchant" button. - // The Payment page was not used for a payment yet. - // It is still active and could be used by the customer for the current payment. - $_SESSION['paypageId'] = $payment->getPayPage()->getRedirectUrl(); - $redirectUrl = CREATE_URL; - } - - if ($payment->isPending()) { - if ($transaction->isSuccess() || $transaction->isResumed()) { - if ($transaction instanceof Authorization) { - // Payment is ready to be captured. - // Goods can be shipped later AFTER charge. - } else { - // Payment is not done yet (e.g. Prepayment) - // Goods can be shipped later after incoming payment (event). - } - - // In any case: - // * You can show the success page. - // * You can set order status to pending payment - $redirectUrl = SUCCESS_URL; - } elseif ($transaction->isPending()) { - // In cases of a redirect to an external service (e.g. 3D secure, PayPal, etc) it sometimes takes time for - // the payment to update it's status after redirect into shop. - // In this case the payment and the transaction are pending at first and change to cancel or success later. - - // Use the webhooks feature to stay informed about changes of payment and transaction (e.g. cancel, success) - // then you can handle the states as shown above in transaction->isSuccess() branch. - $redirectUrl = PENDING_URL; - - // The initial transaction of invoice types will not change to success but stay pending. - $paymentType = $payment->getPaymentType(); - if ($paymentType instanceof Prepayment || $paymentType->isInvoiceType()) { - // Awaiting payment by the customer. - // Goods can be shipped immediately except for Prepayment type. - $redirectUrl = SUCCESS_URL; - } - } - } - - // If the payment is neither success nor pending something went wrong. - // In this case do not create the order or cancel it if you already did. - // Redirect to an error page in your shop and show a message if you want. - - // Check the result message of the initial transaction to find out what went wrong. - if ($transaction instanceof AbstractTransactionType) { - // For better debugging log the error message in your error log - $merchantMessage = $transaction->getMessage()->getMerchant(); - $clientMessage = $transaction->getMessage()->getCustomer(); - } -} catch (UnzerApiException $e) { - // Write the merchant message to your log. - // Show the client message to the customer (it is localized). - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect($redirectUrl, $merchantMessage, $clientMessage); diff --git a/examples/SepaDirectDebitSecured/Constants.php b/examples/SepaDirectDebitSecured/Constants.php deleted file mode 100644 index ed51a8f61..000000000 --- a/examples/SepaDirectDebitSecured/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $orderId = 'o' . str_replace(['0.', ' '], '', microtime(false)); - - // A Basket is mandatory for SEPA direct debit secured payment type - $basketItem = (new BasketItem()) - ->setAmountPerUnitGross(119.00) - ->setVat(19.00) - ->setQuantity(1) - ->setBasketItemReferenceId('item1') - ->setTitle('Hat'); - - $basket = new Basket($orderId); - $basket->setTotalValueGross(119.00) - ->addBasketItem($basketItem) - ->setCurrencyCode('EUR'); - - $transaction = $unzer->charge(119.0, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket); - - // You'll need to remember the shortId to show it on the success or failure page - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the success or failure depending on the state of the transaction - $payment = $transaction->getPayment(); - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - - // To avoid redundant code this example redirects to the general ReturnController which contains the code example to handle payment results. - redirect(RETURN_CONTROLLER_URL); - -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/SepaDirectDebitSecured/index.php b/examples/SepaDirectDebitSecured/index.php deleted file mode 100644 index d3186a6ea..000000000 --- a/examples/SepaDirectDebitSecured/index.php +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
- -
-
- -
-
-
- -
-
- - - - - diff --git a/examples/Sofort/Constants.php b/examples/Sofort/Constants.php deleted file mode 100644 index bd909cfb5..000000000 --- a/examples/Sofort/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge transaction to get the redirectUrl. - $transaction = $unzer->charge(12.32, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $transaction->getPaymentId(); - $_SESSION['ShortId'] = $transaction->getShortId(); - - // Redirect to the Sofort page - if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { - redirect($transaction->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $transaction->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Sofort/index.php b/examples/Sofort/index.php deleted file mode 100644 index 67c98e1ad..000000000 --- a/examples/Sofort/index.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/Success.php b/examples/Success.php deleted file mode 100755 index 94a2475a9..000000000 --- a/examples/Success.php +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -
- -

Success

-

The order has been successfully placed.

- - Please look for ShortId ' . $shortId . ' in Unzer Insights to see the transaction.

'; - $paylaterTransactionMessage = '

Please use the "descriptor" to look for the transaction in the Unzer Pay Later Merchant Portal.

'; - echo preg_match('/[\d]{4}.[\d]{4}.[\d]{4}/', $shortId) ? $defaultTransactionMessage : $paylaterTransactionMessage; - } - - $isManageable = false; - if ($paymentId !== null) { - echo '

The PaymentId of your transaction is \'' . $paymentId . '\'.

'; - $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); - $payment = $unzer->fetchPayment($paymentId); - $isManageable = $payment->getPaymentType()->supportsDirectPaymentCancel() || $payment->getAuthorization() !== null; - } - - if ($paymentTypeId !== null) { - echo '

The TypeId for the recurring payment is \'' . $paymentTypeId . '\'. You can use it - now for subsequent transactions.

-
- -
-
- -
-
-
'; - } - - if ($isManageable) { - echo '

As a merchant you can charge or cancel the Payment here: Manage Payment

'; - } - ?> - start again -
- - diff --git a/examples/Webhooks/Constants.php b/examples/Webhooks/Constants.php deleted file mode 100755 index 488b84b06..000000000 --- a/examples/Webhooks/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $resource = $unzer->fetchResourceFromEvent(file_get_contents('php://input')); - $unzer->debugLog('Fetched resource from Event: ' . $resource->jsonSerialize()); -} catch (UnzerApiException $e) { - $unzer->debugLog('Error: ' . $e->getMessage()); -} catch (RuntimeException $e) { - $unzer->debugLog('Error: ' . $e->getMessage()); -} diff --git a/examples/Webhooks/fetchAll.php b/examples/Webhooks/fetchAll.php deleted file mode 100644 index 2e636ebc0..000000000 --- a/examples/Webhooks/fetchAll.php +++ /dev/null @@ -1,80 +0,0 @@ -'. - '
' . $title . '
'. - '

' . nl2br($text) . '

'. - '
'; -} - -function printError($text) -{ - printMessage('error', 'Error', $text); -} - -function printInfo($title, $text) -{ - printMessage('info', $title, $text); -} - -?> - - - - - - Unzer UI Examples - - - - - - - -
-

- - - Webhook registration - -

- - setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $webhooks = $unzer->fetchAllWebhooks(); - } catch (UnzerApiException $e) { - printError($e->getMessage()); - $unzer->debugLog('Error: ' . $e->getMessage()); - } catch (RuntimeException $e) { - printError($e->getMessage()); - $unzer->debugLog('Error: ' . $e->getMessage()); - } - - printInfo('Back to the payment selection', 'Now Perform payments >> HERE << to trigger events!'); - ?> -
- - diff --git a/examples/Webhooks/index.php b/examples/Webhooks/index.php deleted file mode 100755 index e8f9921b4..000000000 --- a/examples/Webhooks/index.php +++ /dev/null @@ -1,97 +0,0 @@ -'. - '
' . $title . '
'. - '

' . nl2br($text) . '

'. - ''; -} - -function printError($text) -{ - printMessage('error', 'Error', $text); -} - -function printSuccess($title, $text) -{ - printMessage('success', $title, $text); -} - -function printInfo($title, $text) -{ - printMessage('info', $title, $text); -} - -?> - - - - - - Unzer UI Examples - - - - - - - -
-

- - - Webhook registration - -

- - setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $webhooks = $unzer->registerMultipleWebhooks(CONTROLLER_URL, [WebhookEvents::ALL]); - - foreach ($webhooks as $webhook) { - /** @var Webhook $webhook */ - printSuccess( - 'Event registered', - 'Event: ' . $webhook->getEvent() . '
' . - 'URL: ' . $webhook->getUrl() . '
' - ); - } - - printInfo('You are ready to trigger events', 'Now Perform payments >> HERE << to trigger events!'); - - } catch (UnzerApiException $e) { - printError($e->getMessage()); - $unzer->debugLog('Error: ' . $e->getMessage()); - } catch (RuntimeException $e) { - printError($e->getMessage()); - $unzer->debugLog('Error: ' . $e->getMessage()); - } - ?> -
- - diff --git a/examples/Webhooks/removeAll.php b/examples/Webhooks/removeAll.php deleted file mode 100755 index b6d269a04..000000000 --- a/examples/Webhooks/removeAll.php +++ /dev/null @@ -1,90 +0,0 @@ -'. - '
' . $title . '
'. - '

' . nl2br($text) . '

'. - ''; -} - -function printError($text) -{ - printMessage('error', 'Error', $text); -} - -function printSuccess($title, $text) -{ - printMessage('success', $title, $text); -} - -function printInfo($title, $text) -{ - printMessage('info', $title, $text); -} - -?> - - - - - - Unzer UI Examples - - - - - - - -
-

- - - Webhook registration - -

- - setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - $unzer->deleteAllWebhooks(); - printSuccess( - 'De-registered all existing events for the given private key', - 'Unsubscribed all events registered for the private key: "' . UNZER_PAPI_PRIVATE_KEY . '".' - ); - - } catch (UnzerApiException $e) { - printError($e->getMessage()); - $unzer->debugLog('Error: ' . $e->getMessage()); - } catch (RuntimeException $e) { - printError($e->getMessage()); - $unzer->debugLog('Error: ' . $e->getMessage()); - } - - printInfo('Back to the payment selection', 'Now Perform payments >> HERE << to trigger events!'); - ?> -
- - diff --git a/examples/Wechatpay/Constants.php b/examples/Wechatpay/Constants.php deleted file mode 100755 index 3f0f256a1..000000000 --- a/examples/Wechatpay/Constants.php +++ /dev/null @@ -1,12 +0,0 @@ -setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - - // Create a charge to get the redirectUrl. - $charge = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); - - // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); - - // Redirect to the WeChatPay page of the selected bank - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); - } - - // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); -} catch (UnzerApiException $e) { - $merchantMessage = $e->getMerchantMessage(); - $clientMessage = $e->getClientMessage(); -} catch (RuntimeException $e) { - $merchantMessage = $e->getMessage(); -} -redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/Wechatpay/index.php b/examples/Wechatpay/index.php deleted file mode 100755 index 43d16d52a..000000000 --- a/examples/Wechatpay/index.php +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - Unzer UI Examples - - - - - - - -

Example data:

- - -

Click here to open our test data in new tab.

- -
-
-
- -
-
- - - - diff --git a/examples/_enableExamples.php b/examples/_enableExamples.php deleted file mode 100755 index ccc844f65..000000000 --- a/examples/_enableExamples.php +++ /dev/null @@ -1,43 +0,0 @@ -'. - '
' . $title . '
'. - '

' . nl2br($text) . '

'. - ''; -} -?> - - - - - - Unzer UI Examples - - - - - - - - - - -
-

- - - Payment Implementation Examples - Choose the Payment Type you want to evaluate ... - -

- - support@unzer.com' - ); - } - ?> - -
-
-
-
Apple Pay
-
- You can try authorize and charge transactions. - Please make sure to provide the path to the certificates for this payment type. - Notes: -
    -
  • This payment type is available for Apple devices only.
  • -
  • Please refer to this page to learn all about the requirements for Apple Pay.
  • -
-
-
-
- Try -
-
-
-
-
Card
-
- You can try authorize, charge and payout transactions with or without 3Ds. - This example submits email via customer resource. -
-
-
- Try -
-
-
-
-
Card (extended)
-
- Including email and holder fields. - Adding more information to the card can improve risk acceptance. - This example submits email via payment type resource. -
-
-
- Try -
-
-
-
-
Card Recurring
-
- You can set a Card type to recurring in order to register it and charge later as well as implement recurring payments. -
-
-
- Try -
-
-
-
-
- EPS -
-
-
-
-
- Try -
-
-
-
-
- iDeal -
-
-
-
-
- Try -
-
-
-
-
- Giropay -
-
-
-
-
- Try -
-
-
-
-
- Google Pay -
-
-
-
-
- Try -
-
-
-
-
- Alipay -
-
-
-
-
- Try -
-
-
-
-
- WeChat Pay -
-
-
-
-
- Try -
-
-
-
-
- Przelewy24 (P24) -
-
-
-
-
- Try -
-
-
-
-
- Prepayment -
-
-
-
-
- Try -
-
-
-
-
- Invoice (deprecated) -
-
-
-
-
- Try -
-
-
-
-
- Unzer Invoice -
-
- With "paylater-invoice" type. -
-
-
- Documentation -
-
- Try -
-
-
-
-
- Unzer Invoice (deprecated) -
-
- With "invoice-secured" type. -
-
-
- Try -
-
-
-
-
- Klarna -
-
-
- Try -
-
-
-
-
- PayPal -
-
- You can try authorize and direct charge. -
-
-
- Try -
-
-
-
-
- PayPal Recurring -
-
- You can set a PayPal type to recurring in order to register it and charge later as well as implement recurring payments. -
-
-
- Try -
-
-
-
-
- PayU -
-
-
-
-
- Try -
-
-
-
-
- Sofort -
-
-
-
-
- Try -
-
-
-
-
- Unzer Direct Debit (deprecated) -
-
-
-
-
- Try -
-
-
-
-
- Paylater Direct Debit -
-
-
-
-
- Try -
-
-
-
-
- Paylater Installment -
-
-
-
-
- Try -
-
-
-
-
- Installment Secured (deprecated) -
-
-
-
-
- Try -
-
-
-
-
- Unzer Bank Transfer (PIS) -
-
-
-
-
- Try -
-
-
-
-
- Post Finance Card -
-
-
-
-
- Try -
-
-
-
-
- Post Finance eFinance -
-
-
-
-
- Try -
-
-
-
-
- Hosted Payment Page -
-
- This example shows how to use the Payment Page hosted externally. - The customer will be redirected to a Payment Page on a Unzer - server and redirected to a given RedirectUrl. -
-
-
- Documentation -
-
- Try -
-
-
-
-
- Embedded Payment Page -
-
- This example shows how to use the embedded Payment Page. - The Payment Page will be shown as an Overlay in your own shop. -
-
-
- Documentation -
-
- Try -
-
-
-
-
- Bancontact -
-
-
-
-
- Try -
-
-
-
- -
-

- - - Webhook Implementation Examples - Enable or disable webhooks ... - -

-
-
-
-
- Register Webhooks -
-
- Enable a log output in ExampleDebugHandler to see the events coming in. -
-
-
- Try -
-
-
-
-
- Delete all Webhooks -
-
- Delete all Webhooks corresponding to this key pair. -
-
-
- Try -
-
-
-
-
- Fetch all Webhooks -
-
- Fetch all Webhooks corresponding to this key pair. -
-
-
- Try -
-
-
-
- - - diff --git a/examples/log/.gitkeep b/examples/log/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/Constants/IdStrings.php b/src/Constants/IdStrings.php index 4634335b5..e6489ea9f 100755 --- a/src/Constants/IdStrings.php +++ b/src/Constants/IdStrings.php @@ -25,16 +25,9 @@ class IdStrings public const BANCONTACT = 'bct'; public const CARD = 'crd'; public const EPS = 'eps'; - public const GIROPAY = 'gro'; public const GOOGLE_PAY = 'gop'; public const CLICK_TO_PAY = 'ctp'; - public const HIRE_PURCHASE_DIRECT_DEBIT = 'hdd'; public const IDEAL = 'idl'; - public const INSTALLMENT_SECURED = 'ins'; - public const INVOICE = 'ivc'; - public const INVOICE_FACTORING = 'ivf'; - public const INVOICE_GUARANTEED = 'ivg'; - public const INVOICE_SECURED = 'ivs'; public const KLARNA = 'kla'; public const PAYLATER_DIRECT_DEBIT = 'pdd'; public const PAYLATER_INVOICE = 'piv'; @@ -48,9 +41,6 @@ class IdStrings public const PREPAYMENT = 'ppy'; public const PRZELEWY24 = 'p24'; public const SEPA_DIRECT_DEBIT = 'sdd'; - public const SEPA_DIRECT_DEBIT_GUARANTEED = 'ddg'; - public const SEPA_DIRECT_DEBIT_SECURED = 'dds'; - public const SOFORT = 'sft'; public const TWINT = 'twt'; public const WECHATPAY = 'wcp'; public const WERO = 'wro'; @@ -70,15 +60,8 @@ class IdStrings self::BANCONTACT, self::CARD, self::EPS, - self::GIROPAY, self::GOOGLE_PAY, - self::HIRE_PURCHASE_DIRECT_DEBIT, self::IDEAL, - self::INSTALLMENT_SECURED, - self::INVOICE, - self::INVOICE_FACTORING, - self::INVOICE_GUARANTEED, - self::INVOICE_SECURED, self::KLARNA, self::PAYLATER_DIRECT_DEBIT, self::PAYLATER_INVOICE, @@ -92,9 +75,6 @@ class IdStrings self::PREPAYMENT, self::PRZELEWY24, self::SEPA_DIRECT_DEBIT, - self::SEPA_DIRECT_DEBIT_GUARANTEED, - self::SEPA_DIRECT_DEBIT_SECURED, - self::SOFORT, self::TWINT, self::WECHATPAY, self::WERO, diff --git a/src/Interfaces/PaymentServiceInterface.php b/src/Interfaces/PaymentServiceInterface.php index ad05a505e..62ae4e60a 100644 --- a/src/Interfaces/PaymentServiceInterface.php +++ b/src/Interfaces/PaymentServiceInterface.php @@ -15,7 +15,6 @@ use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; -use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaylaterInstallmentPlans; use UnzerSDK\Resources\Payment; @@ -68,49 +67,6 @@ public function performAuthorization( */ public function updateAuthorization($payment, Authorization $authorization): Authorization; - /** - * Performs an Authorization transaction and returns the resulting Authorization resource. - * - * @param float $amount The amount to authorize. - * @param string $currency The currency of the amount. - * @param string|BasePaymentType $paymentType The PaymentType object or the id of the PaymentType to use. - * @param string $returnUrl The URL used to return to the shop if the process requires leaving it. - * @param Customer|string|null $customer The Customer object or the id of the customer resource to reference. - * @param string|null $orderId A custom order id which can be set by the merchant. - * @param Metadata|null $metadata The Metadata object containing custom information for the payment. - * @param Basket|null $basket The Basket object corresponding to the payment. - * The Basket object will be created automatically if it does not exist - * yet (i.e. has no id). - * @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is - * optional and will be ignored if not applicable. - * @param string|null $invoiceId The external id of the invoice. - * @param string|null $referenceText A reference text for the payment. - * @param string|null $recurrenceType Recurrence type used for recurring payment. - * - * @return Authorization The resulting object of the Authorization resource. - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @deprecated since 1.2.0.0 please use performAuthorization() instead. - * @see performAuthorization - * - */ - public function authorize( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer = null, - $orderId = null, - $metadata = null, - $basket = null, - $card3ds = null, - $invoiceId = null, - $referenceText = null, - $recurrenceType = null - ): Authorization; - /** * Performs a Charge transaction and returns the resulting Charge resource. * @@ -150,50 +106,6 @@ public function performCharge( */ public function updateCharge($payment, Charge $charge): Charge; - /** - * Performs a Charge transaction and returns the resulting Charge resource. - * - * @param float $amount The amount to charge. - * @param string $currency The currency of the amount. - * @param string|BasePaymentType $paymentType The PaymentType object or the id of the PaymentType to use. - * @param string $returnUrl The URL used to return to the shop if the process requires leaving it. - * @param Customer|string|null $customer The Customer object or the id of the customer resource to reference. - * @param string|null $orderId A custom order id which can be set by the merchant. - * @param Metadata|null $metadata The Metadata object containing custom information for the payment. - * @param Basket|null $basket The Basket object corresponding to the payment. - * The Basket object will be created automatically if it does not exist - * yet (i.e. has no id). - * @param bool|null $card3ds Enables 3ds channel for credit cards if available. This parameter is - * optional and will be ignored if not applicable. - * @param string|null $invoiceId The external id of the invoice. - * @param string|null $paymentReference A reference text for the payment. - * @param string|null $recurrenceType Recurrence type used for recurring payment. - * See \UnzerSDK\Constants\RecurrenceTypes to find all supported types. - * - * @return Charge The resulting object of the Charge resource. - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @deprecated since 1.2.0.0 please use performCharge() instead. - * @see performCharge - * - */ - public function charge( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer = null, - $orderId = null, - $metadata = null, - $basket = null, - $card3ds = null, - $invoiceId = null, - $paymentReference = null, - $recurrenceType = null - ): Charge; - /** * Performs a Charge transaction for a previously authorized payment. * To perform a full charge of the authorized amount leave the amount null. @@ -211,53 +123,6 @@ public function performChargeOnPayment( Charge $charge ): Charge; - /** - * Performs a Charge transaction for the Authorization of the given Payment object. - * To perform a full charge of the authorized amount leave the amount null. - * - * @param string|Payment $payment The Payment object the Authorization to charge belongs to. - * @param float|null $amount The amount to charge. - * @param string|null $orderId The order id from the shop. - * @param string|null $invoiceId The invoice id from the shop. - * - * @return Charge The resulting object of the Charge resource. - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @deprecated since 1.2.0.0 please use performChargeOnPayment() instead. - * - */ - public function chargeAuthorization( - $payment, - ?float $amount = null, - ?string $orderId = null, - ?string $invoiceId = null - ): Charge; - - /** - * Performs a Charge transaction for a specific Payment and returns the resulting Charge object. - * - * @param Payment|string $payment The Payment object to be charged. - * @param float|null $amount The amount to charge. - * @param string|null $orderId The order id from the shop. - * @param string|null $invoiceId The invoice id from the shop. - * - * @return Charge The resulting Charge object. - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @deprecated since 1.2.0.0 please use performChargeOnPayment() instead. - * - */ - public function chargePayment( - $payment, - ?float $amount = null, - ?string $orderId = null, - ?string $invoiceId = null - ): Charge; - /** * Performs a Payout transaction and returns the resulting Payout resource. * @@ -362,26 +227,6 @@ public function initPayPageAuthorize( ?Metadata $metadata = null ): Paypage; - /** - * Returns an InstallmentPlans object containing all available instalment plans. - * - * @param float $amount The amount to be charged via FlexiPay Rate. - * @param string $currency The currency code of the transaction. - * @param float $effectiveInterest The effective interest rate. - * @param DateTime|null $orderDate The date the order took place, is set to today if left empty. - * - * @return InstalmentPlans|AbstractUnzerResource The object containing all possible instalment plans. - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - */ - public function fetchInstallmentPlans( - float $amount, - string $currency, - float $effectiveInterest, - ?DateTime $orderDate = null - ): InstalmentPlans; - /** * Returns an InstallmentPlans object containing all available instalment plan options. * diff --git a/src/Resources/Basket.php b/src/Resources/Basket.php index 3397f908d..deea01a75 100755 --- a/src/Resources/Basket.php +++ b/src/Resources/Basket.php @@ -18,118 +18,18 @@ class Basket extends AbstractUnzerResource { use BasketV2Properties; - /** - * @var float $amountTotalGross - * - * @deprecated since 1.1.5.0 @see $totalValueGross. - */ - protected $amountTotalGross = 0.0; - - /** - * @var float $amountTotalDiscount - * - * @deprecated since 1.1.5.0 @see Please set $amountDiscountPerUnitGross for each element of $basketItems instead. - */ - protected $amountTotalDiscount = 0.0; - - /** - * @var float $amountTotalVat - * - * @deprecated since 1.1.5.0 Please set the $vat in percent for each element of $basketItems instead, if not already happened. The actual amount is not required anymore. - */ - protected $amountTotalVat = 0.0; - - /** - * Basket constructor. - * - * @deprecated since 1.1.5.0 Please call constructor without parameters and use setter functions instead. - * - * @param float $amountTotalGross - * @param string $currencyCode - * @param string $orderId - * @param array $basketItems - */ public function __construct( string $orderId = '', - float $amountTotalGross = 0.0, + float $totalValueGross = 0.0, string $currencyCode = 'EUR', array $basketItems = [] ) { - $this->currencyCode = $currencyCode; - $this->orderId = $orderId; - $this->setAmountTotalGross($amountTotalGross); + $this->orderId = $orderId; + $this->currencyCode = $currencyCode; + $this->setTotalValueGross($totalValueGross); $this->setBasketItems($basketItems); } - /** - * @return float - * - * @deprecated since 1.1.5.0 @see getTotalValueGross(). - */ - public function getAmountTotalGross(): float - { - return $this->amountTotalGross; - } - - /** - * @param float $amountTotalGross - * - * @return Basket - * @deprecated since 1.1.5.0 @see setTotalValueGross(). - * - */ - public function setAmountTotalGross(float $amountTotalGross): Basket - { - $this->amountTotalGross = $amountTotalGross; - return $this; - } - - /** - * @return float - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - public function getAmountTotalDiscount(): float - { - return $this->amountTotalDiscount; - } - - /** - * @param float $amountTotalDiscount - * - * @return Basket - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - * - */ - public function setAmountTotalDiscount(float $amountTotalDiscount): Basket - { - $this->amountTotalDiscount = $amountTotalDiscount; - return $this; - } - - /** - * @return float - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - public function getAmountTotalVat(): float - { - return $this->amountTotalVat; - } - - /** - * @param float $amountTotalVat - * - * @return Basket - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - * - */ - public function setAmountTotalVat(float $amountTotalVat): Basket - { - $this->amountTotalVat = $amountTotalVat; - return $this; - } - /** * {@inheritDoc} */ diff --git a/src/Resources/EmbeddedResources/BasketItem.php b/src/Resources/EmbeddedResources/BasketItem.php index feaa2b346..4d3537135 100755 --- a/src/Resources/EmbeddedResources/BasketItem.php +++ b/src/Resources/EmbeddedResources/BasketItem.php @@ -14,178 +14,4 @@ class BasketItem extends AbstractUnzerResource { use BasketV2ItemProperties; - - /** - * @var float $amountDiscount - * - * @deprecated since 1.1.5.0 @see $amountDiscountPerUnitGross. - */ - protected $amountDiscount = 0.0; - - /** - * @var float $amountGross - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - protected $amountGross = 0.0; - - /** - * @var float $amountVat - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - protected $amountVat = 0.0; - - /** - * @var float $amountPerUnit - * - * @deprecated since 1.1.5.0 @see amountPerUnitGross - */ - protected $amountPerUnit = 0.0; - - /** - * @var float $amountNet - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - protected $amountNet = 0.0; - - /** - * BasketItem constructor. - * - * @param string $title - * @param float $amountNet - * @param float $amountPerUnit - * @param int $quantity - * @deprecated since 1.1.5.0 Please call constructor without parameters and use setter functions instead. - * - */ - public function __construct( - string $title = '', - float $amountNet = 0.0, - float $amountPerUnit = 0.0, - int $quantity = 1 - ) - { - $this->title = $title; - $this->quantity = $quantity; - $this->setAmountNet($amountNet); - $this->setAmountPerUnit($amountPerUnit); - } - - /** - * @return float - * - * @deprecated since 1.1.5.0 @see $getAmountDiscountPerUnitGross. - */ - public function getAmountDiscount(): float - { - return $this->amountDiscount; - } - - /** - * @param float $amountDiscount - * - * @return BasketItem - * @deprecated since 1.1.5.0 @see $setAmountDiscountPerUnitGross. - * - */ - public function setAmountDiscount(float $amountDiscount): BasketItem - { - $this->amountDiscount = $amountDiscount; - return $this; - } - - /** - * @return float - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - public function getAmountGross(): float - { - return $this->amountGross; - } - - /** - * @param float $amountGross - * - * @return BasketItem - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - * - */ - public function setAmountGross(float $amountGross): BasketItem - { - $this->amountGross = $amountGross; - return $this; - } - - - /** - * @return float - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - public function getAmountVat(): float - { - return $this->amountVat; - } - - /** - * @param float $amountVat - * - * @return BasketItem - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - * - */ - public function setAmountVat(float $amountVat): BasketItem - { - $this->amountVat = $amountVat; - return $this; - } - - /** - * @return float - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - public function getAmountPerUnit(): float - { - return $this->amountPerUnit; - } - - /** - * @param float $amountPerUnit - * - * @return BasketItem - * @deprecated since 1.1.5.0 @see setAmountPerUnitGross - * - */ - public function setAmountPerUnit(float $amountPerUnit): BasketItem - { - $this->amountPerUnit = $amountPerUnit; - return $this; - } - - /** - * @return float - * - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - */ - public function getAmountNet(): float - { - return $this->amountNet; - } - - /** - * @param float $amountNet - * - * @return BasketItem - * @deprecated since 1.1.5.0 Property is redundant and is no longer needed. - * - */ - public function setAmountNet(float $amountNet): BasketItem - { - $this->amountNet = $amountNet; - return $this; - } } diff --git a/src/Resources/EmbeddedResources/Paypage/Urls.php b/src/Resources/EmbeddedResources/Paypage/Urls.php index 5796b00b2..35cf3b86c 100644 --- a/src/Resources/EmbeddedResources/Paypage/Urls.php +++ b/src/Resources/EmbeddedResources/Paypage/Urls.php @@ -11,10 +11,6 @@ class Urls extends AbstractUnzerResource protected ?string $imprint = null; protected ?string $help = null; protected ?string $contact = null; - /** @deprecated Use Style::$favicon instead. - * @see Style::$favicon - */ - protected ?string $favicon = null; protected ?string $returnSuccess = null; protected ?string $returnPending = null; protected ?string $returnFailure = null; @@ -76,17 +72,6 @@ public function setContact(?string $contact): Urls return $this; } - public function getFavicon(): ?string - { - return $this->favicon; - } - - public function setFavicon(?string $favicon): Urls - { - $this->favicon = $favicon; - return $this; - } - public function getReturnSuccess(): ?string { return $this->returnSuccess; diff --git a/src/Resources/InstalmentPlans.php b/src/Resources/InstalmentPlans.php deleted file mode 100644 index fce247801..000000000 --- a/src/Resources/InstalmentPlans.php +++ /dev/null @@ -1,201 +0,0 @@ -amount = $amount; - $this->currency = $currency; - $this->effectiveInterest = $effectiveInterest; - $this->setOrderDate($orderDate); - } - - /** - * @return float - */ - public function getAmount(): float - { - return $this->amount; - } - - /** - * @param float $amount - * - * @return InstalmentPlans - */ - public function setAmount(float $amount): InstalmentPlans - { - $this->amount = $amount; - return $this; - } - - /** - * @return string - */ - public function getCurrency(): string - { - return $this->currency; - } - - /** - * @param string $currency - * - * @return InstalmentPlans - */ - public function setCurrency(string $currency): InstalmentPlans - { - $this->currency = $currency; - return $this; - } - - /** - * @return float - */ - public function getEffectiveInterest(): float - { - return $this->effectiveInterest; - } - - /** - * @param float $effectiveInterest - * - * @return InstalmentPlans - */ - public function setEffectiveInterest(float $effectiveInterest): InstalmentPlans - { - $this->effectiveInterest = $effectiveInterest; - return $this; - } - - /** - * @return stdClass[] - */ - public function getPlans(): array - { - return $this->plans; - } - - /** - * @param stdClass[] $plans - * - * @return InstalmentPlans - */ - protected function setPlans(array $plans): InstalmentPlans - { - $this->plans = $plans; - return $this; - } - - /** - * @return string|null - */ - public function getOrderDate(): ?string - { - return $this->orderDate; - } - - /** - * @param string|DateTime|null $orderDate - * - * @return InstalmentPlans - */ - public function setOrderDate($orderDate): InstalmentPlans - { - $this->orderDate = $orderDate instanceof DateTime ? $orderDate->format('Y-m-d') : $orderDate; - return $this; - } - - /** - * Returns the parameter array containing the values for the query string. - * - * @return array - */ - protected function getQueryArray(): array - { - $parameters = []; - $parameters['amount'] = $this->getAmount(); - $parameters['currency'] = $this->getCurrency(); - $parameters['effectiveInterest'] = $this->getEffectiveInterest(); - if ($this->getOrderDate() !== null) { - $parameters['orderDate'] = $this->getOrderDate(); - } - return $parameters; - } - - /** - * Returns the query string for this resource. - * - * @return string - */ - protected function getQueryString(): string - { - return '?' . http_build_query($this->getQueryArray()); - } - - /** - * {@inheritDoc} - */ - public function getResourcePath(string $httpMethod = HttpAdapterInterface::REQUEST_GET): string - { - return 'plans' . $this->getQueryString(); - } - - /** - * {@inheritDoc} - */ - public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void - { - parent::handleResponse($response, $method); - - if (isset($response->entity)) { - $plans = []; - foreach ($response->entity as $plan) { - $instalment = new InstalmentPlan(); - $instalment->handleResponse($plan); - $plans[] = $instalment; - } - $this->setPlans($plans); - } - } -} diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 80c49a1fb..a33397923 100755 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -566,39 +566,6 @@ public function setBasket(?Basket $basket): Payment return $this; } - /** - * Retrieves a Cancellation object of this payment by its Id. - * I. e. refunds (charge cancellations) and reversals (authorize cancellations). - * Fetches the Authorization if it has not been fetched before and the lazy flag is not set. - * Returns null if the Authorization does not exist. - * - * @param string $cancellationId The id of the Cancellation object to be retrieved. - * @param bool $lazy Enables lazy loading if set to true which results in the object not being updated - * via API and possibly containing just the meta data known from the Payment object - * response. - * - * @return Cancellation|null The retrieved Cancellation object. - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @deprecated since 3.2.0 Please use getCancellation() method of a Charge or Authorization object instead. - */ - public function getCancellation(string $cancellationId, bool $lazy = false): ?Cancellation - { - /** @var Cancellation $cancellation */ - foreach ($this->getCancellations() as $cancellation) { - if ($cancellation->getId() === $cancellationId) { - if (!$lazy) { - $this->getResource($cancellation); - } - return $cancellation; - } - } - - return null; - } - /** * Return an array containing all Cancellations of this Payment object * I. e. refunds (charge cancellations) and reversals (authorize cancellations). @@ -898,7 +865,7 @@ public function cancelAuthorizationAmount(?float $amount = null): ?Cancellation */ public function charge(?float $amount = null): Charge { - return $this->getUnzerObject()->chargePayment($this, $amount); + return $this->getUnzerObject()->performChargeOnPayment($this, new Charge($amount)); } /** diff --git a/src/Resources/PaymentTypes/Giropay.php b/src/Resources/PaymentTypes/Giropay.php deleted file mode 100755 index 975fea636..000000000 --- a/src/Resources/PaymentTypes/Giropay.php +++ /dev/null @@ -1,11 +0,0 @@ -iban = $iban; - $this->bic = $bic; - $this->accountHolder = $accountHolder; - $this->setOrderDate($orderDate); - $this->setInvoiceDate($invoiceDate); - $this->setInvoiceDueDate($invoiceDueDate); - $this->selectInstalmentPlan($selectedPlan); - } - - /** - * Updates the plan of this object with the information from the given instalment plan. - * - * @param InstalmentPlan|null $plan - * - * @return $this - */ - public function selectInstalmentPlan(?InstalmentPlan $plan): self - { - if ($plan instanceof InstalmentPlan) { - $this->handleResponse((object)$plan->expose()); - } - return $this; - } - - /** - * @return string|null - */ - public function getIban(): ?string - { - return $this->iban; - } - - /** - * @param string|null $iban - * - * @return $this - */ - public function setIban(?string $iban): self - { - $this->iban = $iban; - return $this; - } - - /** - * @return string|null - */ - public function getBic(): ?string - { - return $this->bic; - } - - /** - * @param string|null $bic - * - * @return $this - */ - public function setBic(?string $bic): self - { - $this->bic = $bic; - return $this; - } - - /** - * @return string|null - */ - public function getAccountHolder(): ?string - { - return $this->accountHolder; - } - - /** - * @param string|null $accountHolder - * - * @return $this - */ - public function setAccountHolder(?string $accountHolder): self - { - $this->accountHolder = $accountHolder; - return $this; - } -} diff --git a/src/Resources/PaymentTypes/Invoice.php b/src/Resources/PaymentTypes/Invoice.php deleted file mode 100755 index 771739660..000000000 --- a/src/Resources/PaymentTypes/Invoice.php +++ /dev/null @@ -1,21 +0,0 @@ -traitActivateRecurring($returnUrl, $recurrenceType); + return $this->getUnzerObject()->activateRecurringPayment($this, $returnUrl, $recurrenceType); } } diff --git a/src/Resources/PaymentTypes/SepaDirectDebitSecured.php b/src/Resources/PaymentTypes/SepaDirectDebitSecured.php deleted file mode 100644 index 46fe05404..000000000 --- a/src/Resources/PaymentTypes/SepaDirectDebitSecured.php +++ /dev/null @@ -1,96 +0,0 @@ -iban = $iban; - } - - /** - * @return string|null - */ - public function getIban(): ?string - { - return $this->iban; - } - - /** - * @param string|null $iban - * - * @return $this - */ - public function setIban(?string $iban): self - { - $this->iban = $iban; - return $this; - } - - /** - * @return string|null - */ - public function getBic(): ?string - { - return $this->bic; - } - - /** - * @param string|null $bic - * - * @return $this - */ - public function setBic(?string $bic): self - { - $this->bic = $bic; - return $this; - } - - /** - * @return string|null - */ - public function getHolder(): ?string - { - return $this->holder; - } - - /** - * @param string|null $holder - * - * @return $this - */ - public function setHolder(?string $holder): self - { - $this->holder = $holder; - return $this; - } -} diff --git a/src/Resources/PaymentTypes/Sofort.php b/src/Resources/PaymentTypes/Sofort.php deleted file mode 100755 index 5f24082b5..000000000 --- a/src/Resources/PaymentTypes/Sofort.php +++ /dev/null @@ -1,12 +0,0 @@ -getUnzerObject()->chargeAuthorization($payment, $amount); + return $this->getUnzerObject()->performChargeOnPayment($payment, new Charge($amount)); } } diff --git a/src/Resources/TransactionTypes/Cancellation.php b/src/Resources/TransactionTypes/Cancellation.php index 51f0d86e0..ea9c1084a 100755 --- a/src/Resources/TransactionTypes/Cancellation.php +++ b/src/Resources/TransactionTypes/Cancellation.php @@ -5,7 +5,6 @@ use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Resources\Payment; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; use function in_array; /** @@ -140,21 +139,6 @@ public function setAmountVat(?float $amountVat): Cancellation return $this; } - /** - * {@inheritDoc} - */ - public function expose() - { - $exposeArray = parent::expose(); - $payment = $this->getPayment(); - if (isset($exposeArray['amount']) - && $payment instanceof Payment && $payment->getPaymentType() instanceof InstallmentSecured) { - $exposeArray['amountGross'] = $exposeArray['amount']; - unset($exposeArray['amount']); - } - return $exposeArray; - } - /** * {@inheritDoc} */ diff --git a/src/Resources/V2/BasketItemProperties.php b/src/Resources/V2/BasketItemProperties.php index fb5dc95c0..654641b5e 100644 --- a/src/Resources/V2/BasketItemProperties.php +++ b/src/Resources/V2/BasketItemProperties.php @@ -36,29 +36,6 @@ trait BasketItemProperties /** @var string|null $type */ protected $type; - /** - * BasketItem constructor. - * - * @param string $title - * @param float $amountNet - * @param float $amountPerUnit - * @param int $quantity - * @deprecated since 1.1.5.0 Please call constructor without parameters and use setter functions instead. - * - */ - public function __construct( - string $title = '', - float $amountNet = 0.0, - float $amountPerUnit = 0.0, - int $quantity = 1 - ) - { - $this->title = $title; - $this->quantity = $quantity; - $this->setAmountPerUnitGross($amountNet); - $this->setAmountPerUnit($amountPerUnit); - } - /** * @return string|null */ diff --git a/src/Resources/V2/Paypage.php b/src/Resources/V2/Paypage.php index d7a7b4fae..22c65b165 100644 --- a/src/Resources/V2/Paypage.php +++ b/src/Resources/V2/Paypage.php @@ -416,7 +416,9 @@ public function expose() $exposeArray = parent::expose(); $expiresAtKey = 'expiresAt'; if (isset($exposeArray[$expiresAtKey])) { - $exposeArray['expiresAt'] = $this->getExpiresAt()->format(DateTime::ATOM); + $exposeArray['expiresAt'] = (clone $this->getExpiresAt()) + ->setTimezone(new \DateTimeZone('UTC')) + ->format('Y-m-d\TH:i:s.v\Z'); } return $exposeArray; } diff --git a/src/Resources/V3/Basket.php b/src/Resources/V3/Basket.php index 8c18c0122..e1a91a4c3 100644 --- a/src/Resources/V3/Basket.php +++ b/src/Resources/V3/Basket.php @@ -18,19 +18,6 @@ */ class Basket extends BasketV2 { - public function __construct( - string $orderId = '', - float $totalValueGross = 0.0, - string $currencyCode = 'EUR', - array $basketItems = [] - ) - { - $this->orderId = $orderId; - $this->setTotalValueGross($totalValueGross); - $this->currencyCode = $currencyCode; - $this->setBasketItems($basketItems); - } - public function getApiVersion(): string { return ApiVersions::V3; diff --git a/src/Services/HttpService.php b/src/Services/HttpService.php index 68bcdc0c7..9b5533041 100755 --- a/src/Services/HttpService.php +++ b/src/Services/HttpService.php @@ -80,37 +80,6 @@ public function setEnvironmentService(EnvironmentService $environmentService): H return $this; } - /** - * send post request to payment server - * - * @param string|null $uri uri of the target system - * @param AbstractUnzerResource|null $resource - * @param string $httpMethod - * @param string|null $apiVersion - * - * @return string - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * @deprecated use sendRequest() instead. - */ - public function send( - ?string $uri = null, - ?AbstractUnzerResource $resource = null, - string $httpMethod = HttpAdapterInterface::REQUEST_GET, - ?string $apiVersion = null - ): string - { - if (!$resource instanceof AbstractUnzerResource) { - throw new RuntimeException('Transfer object is empty!'); - } - $unzerObj = $resource->getUnzerObject(); - - $apiRequest = (new ApiRequest($uri, $resource, $httpMethod, $unzerObj, $apiVersion ?? $resource->getApiVersion())); - - return $this->sendRequest($apiRequest); - } - /** * send post request to payment server * diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index e05dd4ccd..b80d65c3d 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -11,12 +11,10 @@ use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; -use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaylaterInstallmentPlans; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment; use UnzerSDK\Resources\PaymentTypes\Paypage; use UnzerSDK\Resources\TransactionTypes\Authorization; @@ -111,43 +109,6 @@ public function updateAuthorization($payment, Authorization $authorization): Aut return $authorization; } - /** - * {@inheritDoc} - */ - public function authorize( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer = null, - $orderId = null, - $metadata = null, - $basket = null, - $card3ds = null, - $invoiceId = null, - $referenceText = null, - $recurrenceType = null - ): Authorization { - $payment = $this->createPayment($paymentType); - $paymentType = $payment->getPaymentType(); - - /** @var Authorization $authorization */ - $authorization = (new Authorization($amount, $currency, $returnUrl)) - ->setOrderId($orderId) - ->setInvoiceId($invoiceId) - ->setPaymentReference($referenceText); - if ($card3ds !== null) { - $authorization->setCard3ds($card3ds); - } - $payment->setAuthorization($authorization)->setCustomer($customer)->setMetadata($metadata)->setBasket($basket); - - if ($recurrenceType !== null) { - $authorization->setRecurrenceType($recurrenceType); - } - $this->performAuthorization($authorization, $paymentType, $customer, $metadata, $basket); - return $authorization; - } - /** * {@inheritDoc} */ @@ -179,76 +140,6 @@ public function updateCharge($payment, Charge $charge): Charge return $charge; } - /** - * {@inheritDoc} - */ - public function charge( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer = null, - $orderId = null, - $metadata = null, - $basket = null, - $card3ds = null, - $invoiceId = null, - $paymentReference = null, - $recurrenceType = null - ): Charge { - $payment = $this->createPayment($paymentType); - $paymentType = $payment->getPaymentType(); - - /** @var Charge $charge */ - $charge = (new Charge($amount, $currency, $returnUrl)) - ->setOrderId($orderId) - ->setInvoiceId($invoiceId) - ->setPaymentReference($paymentReference); - if ($card3ds !== null) { - $charge->setCard3ds($card3ds); - } - $payment->addCharge($charge)->setCustomer($customer)->setMetadata($metadata)->setBasket($basket); - - if ($recurrenceType !== null) { - $charge->setRecurrenceType($recurrenceType); - } - - return $this->performCharge($charge, $paymentType, $customer, $metadata, $basket); - } - - /** - * {@inheritDoc} - */ - public function chargeAuthorization( - $payment, - ?float $amount = null, - ?string $orderId = null, - ?string $invoiceId = null - ): Charge { - return $this->chargePayment($payment, $amount, $orderId, $invoiceId); - } - - /** - * {@inheritDoc} - */ - public function chargePayment( - $payment, - ?float $amount = null, - ?string $orderId = null, - ?string $invoiceId = null - ): Charge { - $charge = new Charge($amount); - - if ($orderId !== null) { - $charge->setOrderId($orderId); - } - if ($invoiceId !== null) { - $charge->setInvoiceId($invoiceId); - } - - return $this->performChargeOnPayment($payment, $charge); - } - /** * {@inheritDoc} */ @@ -323,22 +214,6 @@ public function initPayPageAuthorize( return $this->initPayPage($paypage, TransactionTypes::AUTHORIZATION, $customer, $basket, $metadata); } - /** - * {@inheritDoc} - */ - public function fetchInstallmentPlans( - float $amount, - string $currency, - float $effectiveInterest, - ?DateTime $orderDate = null - ): InstalmentPlans { - $ins = (new InstallmentSecured(null, null, null))->setParentResource($this->unzer); - $plans = (new InstalmentPlans($amount, $currency, $effectiveInterest, $orderDate))->setParentResource($ins); - /** @var InstalmentPlans $plans */ - $plans = $this->unzer->getResourceService()->fetchResource($plans); - return $plans; - } - /** * {@inheritDoc} */ diff --git a/src/Services/ResourceService.php b/src/Services/ResourceService.php index 90b095782..588506420 100755 --- a/src/Services/ResourceService.php +++ b/src/Services/ResourceService.php @@ -28,12 +28,8 @@ use UnzerSDK\Resources\PaymentTypes\Card; use UnzerSDK\Resources\PaymentTypes\Clicktopay; use UnzerSDK\Resources\PaymentTypes\EPS; -use UnzerSDK\Resources\PaymentTypes\Giropay; use UnzerSDK\Resources\PaymentTypes\Googlepay; use UnzerSDK\Resources\PaymentTypes\Ideal; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; -use UnzerSDK\Resources\PaymentTypes\Invoice; -use UnzerSDK\Resources\PaymentTypes\InvoiceSecured; use UnzerSDK\Resources\PaymentTypes\Klarna; use UnzerSDK\Resources\PaymentTypes\OpenbankingPis; use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit; @@ -48,8 +44,6 @@ use UnzerSDK\Resources\PaymentTypes\Prepayment; use UnzerSDK\Resources\PaymentTypes\Przelewy24; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\SepaDirectDebitSecured; -use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\Resources\PaymentTypes\Twint; use UnzerSDK\Resources\PaymentTypes\Wechatpay; use UnzerSDK\Resources\PaymentTypes\Wero; @@ -62,6 +56,7 @@ use UnzerSDK\Resources\TransactionTypes\Sca; use UnzerSDK\Resources\TransactionTypes\Shipment; use UnzerSDK\Resources\V2\Customer as CustomerV2; +use UnzerSDK\Apis\ApiRequest; use UnzerSDK\Resources\V2\Paypage as PaypageV2; use UnzerSDK\Resources\V3\Basket as BasketV3; use UnzerSDK\Traits\CanRecur; @@ -132,7 +127,9 @@ public function send( $appendId = $httpMethod !== HttpAdapterInterface::REQUEST_POST; $uri = $resource->getUri($appendId, $httpMethod); - $responseJson = $resource->getUnzerObject()->getHttpService()->send($uri, $resource, $httpMethod, $apiVersion); + $unzerObject = $resource->getUnzerObject(); + $apiRequest = new ApiRequest($uri, $resource, $httpMethod, $unzerObject, $apiVersion ?? Unzer::API_VERSION); + $responseJson = $unzerObject->getHttpService()->sendRequest($apiRequest); return !empty($responseJson) ? json_decode($responseJson, false) : new stdClass(); } @@ -902,30 +899,15 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType case IdStrings::EPS: $paymentType = new EPS(); break; - case IdStrings::GIROPAY: - $paymentType = new Giropay(); - break; case IdStrings::GOOGLE_PAY: $paymentType = new Googlepay(); break; case IdStrings::CLICK_TO_PAY: $paymentType = new Clicktopay(); break; - case IdStrings::HIRE_PURCHASE_DIRECT_DEBIT: - case IdStrings::INSTALLMENT_SECURED: - $paymentType = new InstallmentSecured(); - break; case IdStrings::IDEAL: $paymentType = new Ideal(); break; - case IdStrings::INVOICE: - $paymentType = new Invoice(); - break; - case IdStrings::INVOICE_FACTORING: - case IdStrings::INVOICE_GUARANTEED: - case IdStrings::INVOICE_SECURED: - $paymentType = new InvoiceSecured(); - break; case IdStrings::KLARNA: $paymentType = new Klarna(); break; @@ -962,13 +944,6 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType case IdStrings::SEPA_DIRECT_DEBIT: $paymentType = new SepaDirectDebit(null); break; - case IdStrings::SEPA_DIRECT_DEBIT_GUARANTEED: - case IdStrings::SEPA_DIRECT_DEBIT_SECURED: - $paymentType = new SepaDirectDebitSecured(null); - break; - case IdStrings::SOFORT: - $paymentType = new Sofort(); - break; case IdStrings::TWINT: $paymentType = new Twint(); break; diff --git a/src/Traits/CanAuthorize.php b/src/Traits/CanAuthorize.php index c037f19d3..66999431b 100755 --- a/src/Traits/CanAuthorize.php +++ b/src/Traits/CanAuthorize.php @@ -57,20 +57,15 @@ public function authorize( $recurrenceType = null ): Authorization { if ($this instanceof UnzerParentInterface) { - return $this->getUnzerObject()->authorize( - $amount, - $currency, - $this, - $returnUrl, - $customer, - $orderId, - $metadata, - $basket, - $card3ds, - $invoiceId, - $paymentReference, - $recurrenceType - ); + $authorization = (new Authorization($amount, $currency, $returnUrl)) + ->setOrderId($orderId) + ->setCard3ds($card3ds) + ->setInvoiceId($invoiceId) + ->setPaymentReference($paymentReference); + if ($recurrenceType !== null) { + $authorization->setRecurrenceType($recurrenceType); + } + return $this->getUnzerObject()->performAuthorization($authorization, $this, $customer, $metadata, $basket); } throw new RuntimeException( diff --git a/src/Traits/CanDirectCharge.php b/src/Traits/CanDirectCharge.php index cffaefa3d..7d32fa9fc 100755 --- a/src/Traits/CanDirectCharge.php +++ b/src/Traits/CanDirectCharge.php @@ -57,20 +57,15 @@ public function charge( $recurrenceType = null ): Charge { if ($this instanceof UnzerParentInterface) { - return $this->getUnzerObject()->charge( - $amount, - $currency, - $this, - $returnUrl, - $customer, - $orderId, - $metadata, - $basket, - $card3ds, - $invoiceId, - $paymentReference, - $recurrenceType - ); + $charge = (new Charge($amount, $currency, $returnUrl)) + ->setOrderId($orderId) + ->setCard3ds($card3ds) + ->setInvoiceId($invoiceId) + ->setPaymentReference($paymentReference); + if ($recurrenceType !== null) { + $charge->setRecurrenceType($recurrenceType); + } + return $this->getUnzerObject()->performCharge($charge, $this, $customer, $metadata, $basket); } throw new RuntimeException( diff --git a/src/Traits/CanRecur.php b/src/Traits/CanRecur.php index 23e05fb60..2d7cdd1e7 100644 --- a/src/Traits/CanRecur.php +++ b/src/Traits/CanRecur.php @@ -8,39 +8,11 @@ namespace UnzerSDK\Traits; -use UnzerSDK\Exceptions\UnzerApiException; -use UnzerSDK\Resources\AbstractUnzerResource; -use UnzerSDK\Resources\Recurring; -use RuntimeException; - trait CanRecur { /** @var bool $recurring */ private $recurring = false; - /** - * Activates recurring payment for the payment type. - * - * @param string $returnUrl The URL to which the customer gets redirected in case of a 3ds transaction - * @param null|mixed $recurrenceType Recurrence type used for recurring payment. - * - * @return Recurring - * - * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. - * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. - * - * @deprecated since 1.3.0.0 Please set the recurrence type in your Charge/Authorize object using `setRecurrenceType` - * before performing the transaction request. - * - */ - public function activateRecurring($returnUrl, $recurrenceType = null): Recurring - { - if ($this instanceof AbstractUnzerResource) { - return $this->getUnzerObject()->activateRecurringPayment($this, $returnUrl, $recurrenceType); - } - throw new RuntimeException('Error: Recurring can not be enabled on this type.'); - } - /** * @return bool */ diff --git a/src/Unzer.php b/src/Unzer.php index 23f2366b5..32084d8b0 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -20,7 +20,6 @@ use UnzerSDK\Resources\Config; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; -use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Keypair; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaylaterInstallmentPlans; @@ -106,7 +105,10 @@ class Unzer implements */ public function __construct(string $key, ?string $locale = '') { - $this->setKey($key); + if (!PrivateKeyValidator::validate($key) && !PublicKeyValidator::validate($key)) { + throw new RuntimeException('Illegal key: Use a valid private or public key with this SDK!'); + } + $this->key = $key; $this->setLocale($locale); $this->resourceService = new ResourceService($this); @@ -126,27 +128,6 @@ public function getKey(): string return $this->key; } - /** - * Sets your private or public key used to connect to the API. - * - * @param string $key The private or public key. - * - * @return Unzer This Unzer object. - * - * @throws RuntimeException Throws a RuntimeException when the key is invalid. - * - * @deprecated public access will be removed. Please create a new instance with a different keypair instead. - */ - public function setKey(string $key): Unzer - { - if (!PrivateKeyValidator::validate($key) && !PublicKeyValidator::validate($key)) { - throw new RuntimeException('Illegal key: Use a valid private or public key with this SDK!'); - } - - $this->key = $key; - return $this; - } - /** * Returns the set customer locale. This will be set as a request header field. * @@ -696,40 +677,6 @@ public function updateAuthorization($payment, Authorization $authorization): Aut return $this->paymentService->updateAuthorization($payment, $authorization); } - /** - * {@inheritDoc} - */ - public function authorize( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer = null, - $orderId = null, - $metadata = null, - $basket = null, - $card3ds = null, - $invoiceId = null, - $referenceText = null, - $recurrenceType = null - ): Authorization - { - return $this->paymentService->authorize( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer, - $orderId, - $metadata, - $basket, - $card3ds, - $invoiceId, - $referenceText, - $recurrenceType - ); - } - /** * {@inheritDoc} */ @@ -749,66 +696,6 @@ public function updateCharge($payment, Charge $charge): Charge return $this->paymentService->updateCharge($payment, $charge); } - /** - * {@inheritDoc} - */ - public function charge( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer = null, - $orderId = null, - $metadata = null, - $basket = null, - $card3ds = null, - $invoiceId = null, - $paymentReference = null, - $recurrenceType = null - ): Charge - { - return $this->paymentService->charge( - $amount, - $currency, - $paymentType, - $returnUrl, - $customer, - $orderId, - $metadata, - $basket, - $card3ds, - $invoiceId, - $paymentReference, - $recurrenceType - ); - } - - /** - * {@inheritDoc} - */ - public function chargeAuthorization( - $payment, - ?float $amount = null, - ?string $orderId = null, - ?string $invoiceId = null - ): Charge - { - return $this->paymentService->chargeAuthorization($payment, $amount, $orderId, $invoiceId); - } - - /** - * {@inheritDoc} - */ - public function chargePayment( - $payment, - ?float $amount = null, - ?string $orderId = null, - ?string $invoiceId = null - ): Charge - { - return $this->paymentService->chargePayment($payment, $amount, $orderId, $invoiceId); - } - public function performChargeOnPayment($payment, Charge $charge): Charge { return $this->paymentService->performChargeOnPayment($payment, $charge); @@ -1167,20 +1054,6 @@ public function initPayPageAuthorize( return $this->paymentService->initPayPageAuthorize($paypage, $customer, $basket, $metadata); } - /** - * {@inheritDoc} - */ - public function fetchInstallmentPlans( - float $amount, - string $currency, - float $effectiveInterest, - ?DateTime $orderDate = null - ): InstalmentPlans - { - return $this->paymentService - ->fetchInstallmentPlans($amount, $currency, $effectiveInterest, $orderDate); - } - public function fetchPaylaterInstallmentPlans(InstallmentPlansQuery $plansRequest): PaylaterInstallmentPlans { return $this->getPaymentService()->fetchPaylaterInstallmentPlans($plansRequest); diff --git a/test/BaseIntegrationTest.php b/test/BaseIntegrationTest.php index b9d2263ab..57b8611e6 100644 --- a/test/BaseIntegrationTest.php +++ b/test/BaseIntegrationTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\Helper\TestEnvironmentService; use PHPUnit\Runner\BaseTestRunner; +use UnzerSDK\Unzer; class BaseIntegrationTest extends BasePaymentTest { @@ -69,7 +70,9 @@ protected function createPaylaterInvoiceAuthorization(): Authorization */ protected function useNon3dsKey(): void { - $this->getUnzerObject()->setKey(TestEnvironmentService::getTestPrivateKey(true)); + $this->unzer = (new Unzer(TestEnvironmentService::getTestPrivateKey(true))) + ->setDebugHandler(self::getDebugHandler()) + ->setDebugMode(true); } /** @@ -77,6 +80,8 @@ protected function useNon3dsKey(): void */ protected function useLegacyKey(): void { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); + $this->unzer = (new Unzer(TestEnvironmentService::getLegacyTestPrivateKey())) + ->setDebugHandler(self::getDebugHandler()) + ->setDebugMode(true); } } diff --git a/test/BasePaymentTest.php b/test/BasePaymentTest.php index c96bd0d58..c835020fe 100755 --- a/test/BasePaymentTest.php +++ b/test/BasePaymentTest.php @@ -174,12 +174,12 @@ public function createBasket(): Basket { $orderId = 'b' . self::generateRandomId(); $basket = new Basket($orderId, 119.0, 'EUR'); - $basket->setAmountTotalVat(19.0); - $basket->setNote('This basket is creatable!'); - $basketItem = (new BasketItem('myItem', 100.0, 100.0, 1)) + $basketItem = (new BasketItem()) + ->setTitle('myItem') + ->setAmountPerUnitGross(119.0) + ->setQuantity(1) ->setBasketItemReferenceId('refId') - ->setAmountVat(19.0) - ->setAmountGross(119.0) + ->setVat(19.0) ->setImageUrl('https://hpp-images.s3.amazonaws.com/7/bsk_0_6377B5798E5C55C6BF8B5BECA59529130226E580B050B913EAC3606DA0FF4F68.jpg'); $basket->addBasketItem($basketItem); $this->unzer->createBasket($basket); @@ -254,9 +254,11 @@ protected function createCardObject(string $cardNumber = '4711100000000000'): Ca */ public function createCardAuthorization($amount = 100.0): Authorization { - $card = $this->unzer->createPaymentType($this->createCardObject()); - $orderId = microtime(true); - return $this->unzer->authorize($amount, 'EUR', $card, self::RETURN_URL, null, $orderId, null, null, false); + $card = $this->unzer->createPaymentType($this->createCardObject()); + $authorization = (new Authorization($amount, 'EUR', self::RETURN_URL)) + ->setOrderId((string)microtime(true)) + ->setCard3ds(false); + return $this->unzer->performAuthorization($authorization, $card); } /** @@ -267,9 +269,11 @@ public function createCardAuthorization($amount = 100.0): Authorization public function createPaypalAuthorization(): Authorization { /** @var Paypal $paypal */ - $paypal = $this->unzer->createPaymentType(new Paypal()); - $orderId = microtime(true); - return $this->unzer->authorize(100.0, 'EUR', $paypal, self::RETURN_URL, null, $orderId, null, null, false); + $paypal = $this->unzer->createPaymentType(new Paypal()); + $authorization = (new Authorization(100.0, 'EUR', self::RETURN_URL)) + ->setOrderId((string)microtime(true)) + ->setCard3ds(false); + return $this->unzer->performAuthorization($authorization, $paypal); } /** @@ -281,8 +285,9 @@ public function createPaypalAuthorization(): Authorization */ public function createCharge($amount = 100.0): Charge { - $card = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - return $this->unzer->charge($amount, 'EUR', $card, self::RETURN_URL); + $sepa = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); + $charge = new Charge($amount, 'EUR', self::RETURN_URL); + return $this->unzer->performCharge($charge, $sepa); } /** @@ -354,8 +359,6 @@ public function validKeysDataProvider(): array public function invalidKeysDataProvider(): array { return [ - 'public sandbox key' => ['s-pub-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n'], - 'public production key' => ['p-pub-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n'], 'invalid environment' => ['t-priv-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n'], 'invalid key type' => ['s-xyz-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n'], 'invalid format 1' => ['spriv-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n'], diff --git a/test/Fixtures/jsonData/sofortResponseWithIban.json b/test/Fixtures/jsonData/sofortResponseWithIban.json deleted file mode 100644 index 5ddb27161..000000000 --- a/test/Fixtures/jsonData/sofortResponseWithIban.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "s-sft-123", - "method": "sofort", - "recurring": false, - "geoLocation": { - "clientIp": "111.111.111.111", - "countryIsoA2": "DE" - }, - "iban": "DE-IBAN", - "bic": "test-bin", - "holder": "holder" -} \ No newline at end of file diff --git a/test/integration/ExceptionTest.php b/test/integration/ExceptionTest.php index 062a47a29..9f9de5785 100755 --- a/test/integration/ExceptionTest.php +++ b/test/integration/ExceptionTest.php @@ -14,7 +14,8 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; -use UnzerSDK\Resources\PaymentTypes\Giropay; +use UnzerSDK\Resources\PaymentTypes\EPS; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; class ExceptionTest extends BaseIntegrationTest @@ -27,12 +28,12 @@ class ExceptionTest extends BaseIntegrationTest */ public function apiExceptionShouldHoldClientMessage(): void { - $giropay = $this->unzer->createPaymentType(new Giropay()); + $eps = $this->unzer->createPaymentType(new EPS()); $firstClientMessage = ''; $secondClientMessage = ''; try { - $this->unzer->authorize(1.0, 'EUR', $giropay, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $eps); } catch (UnzerApiException $e) { $this->assertInstanceOf(UnzerApiException::class, $e); $this->assertEquals(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED, $e->getCode()); @@ -44,7 +45,7 @@ public function apiExceptionShouldHoldClientMessage(): void try { $this->unzer->setLocale('de-DE'); - $this->unzer->authorize(1.0, 'EUR', $giropay, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $eps); } catch (UnzerApiException $e) { $this->assertInstanceOf(UnzerApiException::class, $e); $this->assertEquals(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED, $e->getCode()); diff --git a/test/integration/PaymentCancelTest.php b/test/integration/PaymentCancelTest.php index b889c0a42..ebb68ede2 100644 --- a/test/integration/PaymentCancelTest.php +++ b/test/integration/PaymentCancelTest.php @@ -12,10 +12,8 @@ namespace UnzerSDK\test\integration; use UnzerSDK\Constants\CancelReasonCodes; -use UnzerSDK\Resources\PaymentTypes\Invoice; -use UnzerSDK\Resources\PaymentTypes\InvoiceSecured; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; -use UnzerSDK\test\Helper\TestEnvironmentService; class PaymentCancelTest extends BaseIntegrationTest { @@ -83,12 +81,12 @@ public function fullCancelOnPaymentWithAuthorizeAndMultipleChargesShouldBePossib $this->assertTrue($payment->isPending()); $this->assertAmounts($payment, 123.44, 0.0, 123.44, 0.0); - $charge1 = $payment->charge(100.44); + $charge1 = $this->unzer->performChargeOnPayment($payment, new Charge(100.44)); $this->assertTrue($payment->isPartlyPaid()); $this->assertAmounts($payment, 23.0, 100.44, 123.44, 0.0); $payment = $this->unzer->fetchPayment($authorization->getPaymentId()); - $charge2 = $payment->charge(23.00); + $charge2 = $this->unzer->performChargeOnPayment($payment, new Charge(23.00)); $this->assertTrue($payment->isCompleted()); $this->assertAmounts($payment, 0.0, 123.44, 123.44, 0.0); @@ -144,12 +142,12 @@ public function partialCancelOnMultipleChargedAuthorization($amount, $numberCanc $authorization = $this->createCardAuthorization($authorizeAmount); $payment = $this->unzer->fetchPayment($authorization->getPaymentId()); - $payment->charge(23.00); + $this->unzer->performChargeOnPayment($payment, new Charge(23.00)); $this->assertTrue($payment->isPartlyPaid()); $this->assertAmounts($payment, 100.44, 23.0, $authorizeAmount, 0.0); $payment = $this->unzer->fetchPayment($authorization->getPaymentId()); - $payment->charge(100.44); + $this->unzer->performChargeOnPayment($payment, new Charge(100.44)); $this->assertTrue($payment->isCompleted()); $this->assertAmounts($payment, 0.0, $authorizeAmount, $authorizeAmount, 0.0); @@ -226,7 +224,7 @@ public function fullCancelOnFullyChargedAuthorize($amount): void $this->assertTrue($payment->isPending()); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - $payment->charge(); + $this->unzer->performChargeOnPayment($payment, new Charge()); $this->assertTrue($payment->isCompleted()); $this->assertAmounts($payment, 0.0, 100.0, 100.0, 0.0); @@ -253,7 +251,7 @@ public function fullCancelOnPartlyChargedAuthorizeShouldBePossible($amount): voi $this->assertTrue($payment->isPending()); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - $payment->charge(50.0); + $this->unzer->performChargeOnPayment($payment, new Charge(50.0)); $this->assertTrue($payment->isPartlyPaid()); $this->assertAmounts($payment, 50.0, 50.0, 100.0, 0.0); @@ -294,7 +292,7 @@ public function partCancelOnPartlyChargedAuthorizeWithAmountLtCharged(): void $this->assertTrue($payment->isPending()); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - $payment->charge(25.0); + $this->unzer->performChargeOnPayment($payment, new Charge(25.0)); $this->assertTrue($payment->isPartlyPaid()); $this->assertAmounts($payment, 75.0, 25.0, 100.0, 0.0); @@ -317,7 +315,7 @@ public function partCancelOnPartlyChargedAuthorizeWithAmountGtCharged(): void $this->assertTrue($payment->isPending()); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - $payment->charge(40.0); + $this->unzer->performChargeOnPayment($payment, new Charge(40.0)); $this->assertTrue($payment->isPartlyPaid()); $this->assertAmounts($payment, 60.0, 40.0, 100.0, 0.0); @@ -327,127 +325,6 @@ public function partCancelOnPartlyChargedAuthorizeWithAmountGtCharged(): void $this->assertAmounts($payment, 0.0, 20.0, 40.0, 20.0); } - /** - * Verify full cancel on initial iv charge (reversal) - * PHPLIB-228 - Case 13 - * - * @test - * - * @dataProvider fullCancelDataProvider - * - * @param float $amount - */ - public function fullCancelOnInitialInvoiceCharge($amount): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $charge = $invoice->charge(100.0, 'EUR', self::RETURN_URL); - $payment = $this->unzer->fetchPayment($charge->getPaymentId()); - $this->assertTrue($payment->isPending()); - $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - - $this->assertCount(1, $payment->cancelAmount($amount)); - $this->assertTrue($payment->isCanceled()); - $this->assertAmounts($payment, 0.0, 0.0, 0.0, 0.0); - } - - /** - * Verify part cancel on initial iv charge (reversal) - * PHPLIB-228 - Case 14 - * - * @test - */ - public function partCancelOnInitialInvoiceChargeShouldBePossible(): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $charge = $invoice->charge(100.0, 'EUR', self::RETURN_URL); - $payment = $this->unzer->fetchPayment($charge->getPaymentId()); - $this->assertTrue($payment->isPending()); - $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - - $this->assertCount(1, $payment->cancelAmount(50.0)); - $this->assertTrue($payment->isPending()); - $this->assertAmounts($payment, 50.0, 0.0, 50.0, 0.0); - } - - /** - * Verify part cancel on initial ivs charge (reversal) - * - * @test - */ - public function partCancelOnInitialInvoiceSecuredChargeShouldCancelMaxUnpaidAmount(): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $invoiceId = 'i' . self::generateRandomId(); - $charge = $invoiceSecured->charge(100.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket, null, $invoiceId); - $charge->getPayment()->ship(); - $paymentId = $charge->getPaymentId(); - - $this->assertTrue($charge->isPending()); // Set your break point here. - $payment = $this->unzer->fetchPayment($charge->getPaymentId()); - if (count($payment->getCharges()) !== 2) { - $testDescription = 'This test needs assistance: - To perform this test properly, first set a breakpoint after charge, before the payment gets fetched. - Then perform a receipt manually over 60€ on the "reservation". - After that this test can be continued'; - $this->markTestSkipped($testDescription); - } - $this->assertTrue($payment->isCompleted()); - $this->assertAmounts($payment, 0, 100, 100.0, 0); - - $this->assertCount(2, $payment->cancelAmount(50.0)); - $this->assertTrue($payment->isCompleted()); - $this->assertAmounts($payment, 0, 50.0, 100.0, 50.0); - } - - /** - * Verify skip cancel on initial ivs charge - * - * @test - */ - public function fullCancelOnPaidInvoiceSecuredPaymentShouldBePossible(): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $invoiceId = 'i' . self::generateRandomId(); - $charge = $invoiceSecured->charge(100.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket, null, $invoiceId); - $charge->getPayment()->ship(); - $paymentId = $charge->getPaymentId(); - - $this->assertTrue($charge->isPending()); // Set your break point here. - $payment = $this->unzer->fetchPayment($charge->getPaymentId()); - if (count($payment->getCharges()) !== 2) { - $testDescription = 'This test needs assistance: - To perform this test properly, first set a breakpoint after charge, before the payment gets fetched. - Then perform a receipt manually over 100€ on the "reservation". - After that this test can be continued'; - $this->markTestSkipped($testDescription); - } - $this->assertTrue($payment->isCompleted()); - $this->assertAmounts($payment, 0, 100.0, 100.0, 0); - - $cancellations = $payment->cancelAmount(); - $this->assertCount(1, $cancellations); - $this->assertTrue($payment->isCompleted()); - $this->assertAmounts($payment, 0, 0, 100.0, 100.0); - } - /** * Verify cancelling more than was charged. * PHPLIB-228 - Case 15 @@ -480,12 +357,12 @@ public function secondCancelExceedsRemainderOfPartlyCancelledCharge(): void $this->assertTrue($payment->isPending()); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); - $payment->charge(50.0); + $this->unzer->performChargeOnPayment($payment, new Charge(50.0)); $this->assertTrue($payment->isPartlyPaid()); $this->assertAmounts($payment, 50.0, 50.0, 100.0, 0.0); $payment = $this->unzer->fetchPayment($authorization->getPaymentId()); - $payment->charge(50.0); + $this->unzer->performChargeOnPayment($payment, new Charge(50.0)); $this->assertTrue($payment->isCompleted()); $this->assertAmounts($payment, 0.0, 100.0, 100.0, 0.0); @@ -509,7 +386,7 @@ public function cancellationShouldWorkWithAllParametersSet(): void { $authorization = $this->createCardAuthorization(119.0); $payment = $authorization->getPayment(); - $payment->charge(); + $this->unzer->performChargeOnPayment($payment, new Charge()); $cancellations = $payment->cancelAmount(59.5, CancelReasonCodes::REASON_CODE_CREDIT, 'Reference text!', 50.0, 9.5); $this->assertCount(1, $cancellations); } diff --git a/test/integration/PaymentTest.php b/test/integration/PaymentTest.php index b21ef766f..546755c43 100755 --- a/test/integration/PaymentTest.php +++ b/test/integration/PaymentTest.php @@ -56,7 +56,7 @@ public function fullChargeShouldBePossibleOnPaymentObject(): void $this->assertTrue($payment->isPending()); /** @var Charge $charge */ - $charge = $payment->charge(); + $charge = $this->unzer->performChargeOnPayment($payment, new Charge()); $paymentNew = $charge->getPayment(); // verify payment has been updated properly @@ -78,7 +78,7 @@ public function paymentShouldBeFetchableWithCharges(): void $this->assertNotNull($payment->getAuthorization()); $this->assertNotNull($payment->getAuthorization()->getId()); - $charge = $payment->charge(); + $charge = $this->unzer->performChargeOnPayment($payment, new Charge()); $fetchedPayment = $this->unzer->fetchPayment($charge->getPayment()->getId()); $this->assertNotNull($fetchedPayment->getCharges()); $this->assertCount(1, $fetchedPayment->getCharges()); @@ -101,7 +101,7 @@ public function partialChargeAfterAuthorization(): void { $authorization = $this->createCardAuthorization(); $fetchedPayment = $this->unzer->fetchPayment($authorization->getPayment()->getId()); - $charge = $fetchedPayment->charge(10.0); + $charge = $this->unzer->performChargeOnPayment($fetchedPayment, new Charge(10.0)); $this->assertNotNull($charge); $this->assertEquals('s-chg-1', $charge->getId()); $this->assertEquals('10.0', $charge->getAmount()); @@ -116,7 +116,7 @@ public function authorizationShouldBePossibleOnUnzerObject(): void { /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $this->unzer->authorize(100.0, 'EUR', $paypal, self::RETURN_URL); + $authorize = $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $paypal); $this->assertNotNull($authorize); $this->assertNotEmpty($authorize->getId()); } @@ -129,8 +129,11 @@ public function authorizationShouldBePossibleOnUnzerObject(): void public function paymentChargeOnAuthorizeShouldBePossibleUsingPaymentId(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.00, 'EUR', $card, 'http://unzer.com', null, null, null, null, false); - $charge = $this->unzer->chargePayment($authorization->getPaymentId()); + $authorization = $this->unzer->performAuthorization( + (new Authorization(100.00, 'EUR', 'http://unzer.com'))->setCard3ds(false), + $card + ); + $charge = $this->unzer->performChargeOnPayment($authorization->getPaymentId(), new Charge()); $this->assertNotEmpty($charge->getId()); } @@ -143,8 +146,16 @@ public function paymentChargeOnAuthorizeShouldBePossibleUsingPaymentId(): void public function paymentChargeOnAuthorizeShouldTakeResourceIds(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.00, 'EUR', $card, 'http://unzer.com', null, null, null, null, false); - $charge = $this->unzer->chargePayment($authorization->getPaymentId(), null, 'o' . self::generateRandomId(), 'i' . self::generateRandomId()); + $authorization = $this->unzer->performAuthorization( + (new Authorization(100.00, 'EUR', 'http://unzer.com'))->setCard3ds(false), + $card + ); + $orderId = 'o' . self::generateRandomId(); + $invoiceId = 'i' . self::generateRandomId(); + $charge = $this->unzer->performChargeOnPayment( + $authorization->getPaymentId(), + (new Charge())->setOrderId($orderId)->setInvoiceId($invoiceId) + ); $this->assertNotEmpty($charge->getId()); } @@ -158,7 +169,7 @@ public function chargePaymentShouldThrowErrorOnNonPaymentId(): void { $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_PAYMENT_NOT_FOUND); - $this->unzer->chargePayment('s-crd-xlj0qhdiw40k'); + $this->unzer->performChargeOnPayment('s-crd-xlj0qhdiw40k', new Charge()); } /** @@ -170,7 +181,12 @@ public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet(): void { $orderId = str_replace(' ', '', microtime()); $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorization = $this->unzer->authorize(100.00, 'EUR', $paypal, 'https://unzer.com', null, $orderId, null, null, false); + $authorization = $this->unzer->performAuthorization( + (new Authorization(100.00, 'EUR', 'https://unzer.com')) + ->setOrderId($orderId) + ->setCard3ds(false), + $paypal + ); $payment = $authorization->getPayment(); $fetchedPayment = $this->unzer->fetchPaymentByOrderId($orderId); @@ -189,12 +205,18 @@ public function shouldAllowNonUniqueOrderId(): void /** @var Card $card */ $card = $this->unzer->createPaymentType($this->createCardObject()); - $card->charge(1023, 'EUR', self::RETURN_URL, null, $orderId); + $this->unzer->performCharge( + (new Charge(1023, 'EUR', self::RETURN_URL))->setOrderId($orderId), + $card + ); try { /** @var Card $card2 */ $card2 = $this->unzer->createPaymentType($this->createCardObject()); - $card2->charge(1023, 'EUR', self::RETURN_URL, null, $orderId); + $this->unzer->performCharge( + (new Charge(1023, 'EUR', self::RETURN_URL))->setOrderId($orderId), + $card2 + ); $this->assertTrue(true); } catch (UnzerApiException $e) { $this->assertTrue(false, "No exception expected here. ({$e->getMerchantMessage()})"); @@ -212,12 +234,18 @@ public function shouldAllowNonUniqueInvoiceId(): void /** @var Card $card */ $card = $this->unzer->createPaymentType($this->createCardObject()); - $card->charge(1023, 'EUR', self::RETURN_URL, null, null, null, null, null, $invoiceId); + $this->unzer->performCharge( + (new Charge(1023, 'EUR', self::RETURN_URL))->setInvoiceId($invoiceId), + $card + ); try { /** @var Card $card2 */ $card2 = $this->unzer->createPaymentType($this->createCardObject()); - $card2->charge(1023, 'EUR', self::RETURN_URL, null, null, null, null, null, $invoiceId); + $this->unzer->performCharge( + (new Charge(1023, 'EUR', self::RETURN_URL))->setInvoiceId($invoiceId), + $card2 + ); $this->assertTrue(true); } catch (UnzerApiException $e) { $this->assertTrue(false, "No exception expected here. ({$e->getMerchantMessage()})"); diff --git a/test/integration/PaymentTypes/AlipayTest.php b/test/integration/PaymentTypes/AlipayTest.php index 5f4ec9c72..a047d780f 100755 --- a/test/integration/PaymentTypes/AlipayTest.php +++ b/test/integration/PaymentTypes/AlipayTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\Alipay; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; @@ -54,7 +55,7 @@ public function alipayShouldBeCreatableAndFetchable(): Alipay */ public function alipayShouldBeAbleToCharge(Alipay $alipay): Charge { - $charge = $alipay->charge(100.0, 'EUR', self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $alipay); $this->assertNotNull($charge); $this->assertNotEmpty($charge->getId()); $this->assertNotEmpty($charge->getRedirectUrl()); @@ -76,6 +77,6 @@ public function alipayShouldNotBeAuthorizable(Alipay $alipay): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(100.0, 'EUR', $alipay, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $alipay); } } diff --git a/test/integration/PaymentTypes/ApplepayTest.php b/test/integration/PaymentTypes/ApplepayTest.php index 5a7a613a0..f318cb1b6 100644 --- a/test/integration/PaymentTypes/ApplepayTest.php +++ b/test/integration/PaymentTypes/ApplepayTest.php @@ -12,6 +12,8 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\Applepay; +use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; class ApplepayTest extends BaseIntegrationTest @@ -54,7 +56,7 @@ public function applepayShouldBeChargeable(): void { $applepay = $this->createApplepayObject(); $this->unzer->createPaymentType($applepay); - $charge = $applepay->charge(100.0, 'EUR', self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $applepay); $this->assertNotNull($charge->getId()); $this->assertNull($charge->getRedirectUrl()); } @@ -70,7 +72,7 @@ public function applepayCanBeAuthorized(): void { $applepay = $this->createApplepayObject(); $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(1.0, 'EUR', self::RETURN_URL); + $authorization = $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $applepay); // verify authorization has been created $this->assertNotNull($authorization->getId()); @@ -103,7 +105,7 @@ public function applepayCanPerformChargeAndCreatesPaymentObject(): void /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $charge = $applepay->charge(1.0, 'EUR', self::RETURN_URL, null, null, null, null, false); + $charge = $this->unzer->performCharge((new Charge(1.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); // verify charge has been created $this->assertNotNull($charge->getId()); @@ -134,14 +136,14 @@ public function fullChargeAfterAuthorize(): void $applepay = $this->createApplepayObject(); $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(1.0, 'EUR', self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(1.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $payment = $authorization->getPayment(); // pre-check to verify changes due to fullCharge call $this->assertAmounts($payment, 1.0, 0.0, 1.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId()); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge()); $paymentNew = $charge->getPayment(); // verify payment has been updated properly @@ -161,33 +163,26 @@ public function partialChargeAfterAuthorization(): void $applepay = $this->createApplepayObject(); /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $authorization = $this->unzer->authorize( - 100.0, - 'EUR', - $applepay, - self::RETURN_URL, - null, - null, - null, - null, - false + $authorization = $this->unzer->performAuthorization( + (new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), + $applepay ); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 20); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(20)); $payment1 = $charge->getPayment(); $this->assertAmounts($payment1, 80.0, 20.0, 100.0, 0.0); $this->assertTrue($payment1->isPartlyPaid()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 20); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(20)); $payment2 = $charge->getPayment(); $this->assertAmounts($payment2, 60.0, 40.0, 100.0, 0.0); $this->assertTrue($payment2->isPartlyPaid()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 60); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(60)); $payment3 = $charge->getPayment(); $this->assertAmounts($payment3, 00.0, 100.0, 100.0, 0.0); $this->assertTrue($payment3->isCompleted()); @@ -205,19 +200,19 @@ public function exceptionShouldBeThrownWhenChargingMoreThenAuthorized(): void $applepay = $this->createApplepayObject(); /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(100.0000, 'EUR', self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0000, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 50); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(50)); $payment1 = $charge->getPayment(); $this->assertAmounts($payment1, 50.0, 50.0, 100.0, 0.0); $this->assertTrue($payment1->isPartlyPaid()); $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_CHARGED_AMOUNT_HIGHER_THAN_EXPECTED); - $this->unzer->chargeAuthorization($payment->getId(), 70); + $this->unzer->performChargeOnPayment($payment->getId(), new Charge(70)); } /** @@ -231,7 +226,7 @@ public function applepayAuthorizeCanBeCanceled(): void { /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($this->createApplepayObject()); - $authorize = $applepay->authorize(100.0, 'EUR', self::RETURN_URL, null, null, null, null, false); + $authorize = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $cancel = $authorize->cancel(); $this->assertNotNull($cancel); @@ -250,18 +245,18 @@ public function partialAndFullChargeAfterAuthorization(): void $applepay = $this->createApplepayObject(); /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(100.0000, 'EUR', self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0000, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 20); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(20)); $payment1 = $charge->getPayment(); $this->assertAmounts($payment1, 80.0, 20.0, 100.0, 0.0); $this->assertTrue($payment1->isPartlyPaid()); - $charge = $this->unzer->chargeAuthorization($payment->getId()); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge()); $payment2 = $charge->getPayment(); $this->assertAmounts($payment2, 0.0, 100.0, 100.0, 0.0); $this->assertTrue($payment2->isCompleted()); @@ -279,7 +274,7 @@ public function authorizationShouldBeFetchable(): void $applepay = $this->createApplepayObject(); /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(100.0000, 'EUR', self::RETURN_URL); + $authorization = $this->unzer->performAuthorization(new Authorization(100.0000, 'EUR', self::RETURN_URL), $applepay); $payment = $authorization->getPayment(); $fetchedAuthorization = $this->unzer->fetchAuthorization($payment->getId()); @@ -295,7 +290,7 @@ public function fullCancelAfterCharge(): void { $applepay = $this->createApplepayObject(); $this->unzer->createPaymentType($applepay); - $charge = $applepay->charge(100.0, 'EUR', self::RETURN_URL, null, null, null, null, false); + $charge = $this->unzer->performCharge((new Charge(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $payment = $charge->getPayment(); $this->assertAmounts($payment, 0.0, 100.0, 100.0, 0.0); @@ -319,17 +314,17 @@ public function fullCancelOnFullyChargedPayment(): void /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(100.0000, 'EUR', self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0000, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $payment->charge(10.0); + $this->unzer->performChargeOnPayment($payment, new Charge(10.0)); $this->assertAmounts($payment, 90.0, 10.0, 100.0, 0.0); $this->assertTrue($payment->isPartlyPaid()); - $payment->charge(90.0); + $this->unzer->performChargeOnPayment($payment, new Charge(90.0)); $this->assertAmounts($payment, 0.0, 100.0, 100.0, 0.0); $this->assertTrue($payment->isCompleted()); @@ -352,13 +347,13 @@ public function fullCancelOnPartlyPaidAuthWithCanceledCharges(): void /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($applepay); - $authorization = $applepay->authorize(100.0000, 'EUR', self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0000, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $payment = $authorization->getPayment(); - $payment->charge(10.0); + $this->unzer->performChargeOnPayment($payment, new Charge(10.0)); $this->assertAmounts($payment, 90.0, 10.0, 100.0, 0.0); - $charge = $payment->charge(10.0); + $charge = $this->unzer->performChargeOnPayment($payment, new Charge(10.0)); $this->assertAmounts($payment, 80.0, 20.0, 100.0, 0.0); $this->assertTrue($payment->isPartlyPaid()); @@ -381,7 +376,7 @@ public function applepayChargeCanBeCanceled(): void { /** @var Applepay $applepay */ $applepay = $this->unzer->createPaymentType($this->createApplepayObject()); - $charge = $applepay->charge(100.0, 'EUR', self::RETURN_URL, null, null, null, null, false); + $charge = $this->unzer->performCharge((new Charge(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $applepay); $cancel = $charge->cancel(); $this->assertNotNull($cancel); diff --git a/test/integration/PaymentTypes/BancontactTest.php b/test/integration/PaymentTypes/BancontactTest.php index f5466c68d..538c9ad21 100644 --- a/test/integration/PaymentTypes/BancontactTest.php +++ b/test/integration/PaymentTypes/BancontactTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\Bancontact; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; class BancontactTest extends BaseIntegrationTest @@ -46,7 +47,7 @@ public function bancontactShouldThrowExceptionOnAuthorize(): void $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); $bancontact = $this->unzer->createPaymentType(new Bancontact()); - $this->unzer->authorize(100.0, 'EUR', $bancontact, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $bancontact); } /** diff --git a/test/integration/PaymentTypes/CardTest.php b/test/integration/PaymentTypes/CardTest.php index 1bd4eb756..bad06e495 100755 --- a/test/integration/PaymentTypes/CardTest.php +++ b/test/integration/PaymentTypes/CardTest.php @@ -19,6 +19,7 @@ use UnzerSDK\Resources\EmbeddedResources\CardTransactionData; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\Card; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Services\ValueService; use UnzerSDK\test\BaseIntegrationTest; @@ -91,7 +92,7 @@ public function cardShouldUseEmail($email, $expected) // ensure the fetched card object contains the email address. $fetchedCard = $this->unzer->fetchPaymentType($card->getId()); $this->assertEquals($expected, $fetchedCard->getEmail()); - $card->charge(119.00, 'EUR', 'https://unzer.com'); + $this->unzer->performCharge(new Charge(119.00, 'EUR', 'https://unzer.com'), $card); } /** @@ -114,7 +115,11 @@ public function cardShouldBeChargeableWithRecurrenceType($recurrenceType, $isrec $card = $this->unzer->createPaymentType($card); $this->assertNotTrue($card->isRecurring()); - $chargeResponse = $card->charge('99.99', 'EUR', 'https://unzer.com', null, null, null, null, null, null, null, $recurrenceType); + $charge = new Charge('99.99', 'EUR', 'https://unzer.com'); + if ($recurrenceType !== null) { + $charge->setRecurrenceType($recurrenceType); + } + $chargeResponse = $this->unzer->performCharge($charge, $card); $this->assertEquals($recurrenceType, $chargeResponse->getRecurrenceType()); $fetchedCharge = $this->unzer->fetchChargeById($chargeResponse->getPaymentId(), $chargeResponse->getId()); @@ -145,7 +150,10 @@ public function invalidRecurrenceTypeShouldThrowApiException($recurrenceType): v /** @var Card $card */ $card = $this->unzer->createPaymentType($card); $this->expectException(UnzerApiException::class); - $card->charge('99.99', 'EUR', 'https://unzer.com', null, null, null, null, null, null, null, $recurrenceType); + $this->unzer->performCharge( + (new Charge('99.99', 'EUR', 'https://unzer.com'))->setRecurrenceType($recurrenceType, $card), + $card + ); } /** @@ -179,7 +187,11 @@ public function cardCanBeAuthorizedWithRecurrenceType($recurrenceType): void $card = $this->createCardObject('4711100000000000'); /** @var Card $card */ $card = $this->unzer->createPaymentType($card); - $chargeResponse = $card->authorize('99.99', 'EUR', 'https://unzer.com', null, null, null, null, null, null, null, $recurrenceType); + $authorization = new Authorization('99.99', 'EUR', 'https://unzer.com'); + if ($recurrenceType !== null) { + $authorization->setRecurrenceType($recurrenceType); + } + $chargeResponse = $this->unzer->performAuthorization($authorization, $card); $this->assertEquals($recurrenceType, $chargeResponse->getRecurrenceType()); $fetchedCharge = $this->unzer->fetchAuthorization($chargeResponse->getPayment()); @@ -252,7 +264,7 @@ public function cardWith3dsFlagShouldSetItAlsoInTransactions(): void $card = $this->unzer->createPaymentType($card); $this->assertFalse($card->get3ds()); - $charge = $card->charge(12.34, 'EUR', 'https://docs.unzer.com'); + $charge = $this->unzer->performCharge(new Charge(12.34, 'EUR', 'https://docs.unzer.com'), $card); $this->assertFalse($charge->isCard3ds()); } @@ -296,7 +308,7 @@ public function cardTransactionReturnsLiabilityIndicator($pan): void $card = $this->createCardObject()->setNumber($pan)->set3ds(false); /** @var Card $card */ $card = $this->unzer->createPaymentType($card); - $charge = $card->charge(12.34, 'EUR', 'https://docs.unzer.com'); + $charge = $this->unzer->performCharge(new Charge(12.34, 'EUR', 'https://docs.unzer.com'), $card); // Verify Liability Indicator in response. $this->assertNotNull($charge->getAdditionalTransactionData()); @@ -321,7 +333,7 @@ public function cardCanPerformAuthorizationAndCreatesPayment(): void /** @var Card $card */ $card = $this->unzer->createPaymentType($card); - $authorization = $card->authorize(1.0, 'EUR', self::RETURN_URL); + $authorization = $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $card); // verify authorization has been created $this->assertNotNull($authorization->getId()); @@ -354,7 +366,7 @@ public function cardCanPerformChargeAndCreatesPaymentObject(): void // card recurring is disabled by default $this->assertFalse($card->isRecurring()); - $charge = $card->charge(1.0, 'EUR', self::RETURN_URL, null, null, null, null, false); + $charge = $this->unzer->performCharge((new Charge(1.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $card); // card recurring is activated through charge transaction /** @var Card $fetchedCard */ @@ -418,7 +430,7 @@ public function fullChargeAfterAuthorize(): void $this->assertAmounts($payment, 1.0, 0.0, 1.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId()); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge()); $paymentNew = $charge->getPayment(); // verify payment has been updated properly @@ -436,33 +448,26 @@ public function partialChargeAfterAuthorization(): void $card = $this->createCardObject(); /** @var Card $card */ $card = $this->unzer->createPaymentType($card); - $authorization = $this->unzer->authorize( - 100.0, - 'EUR', - $card, - self::RETURN_URL, - null, - null, - null, - null, - false + $authorization = $this->unzer->performAuthorization( + (new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), + $card ); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 20); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(20)); $payment1 = $charge->getPayment(); $this->assertAmounts($payment1, 80.0, 20.0, 100.0, 0.0); $this->assertTrue($payment1->isPartlyPaid()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 20); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(20)); $payment2 = $charge->getPayment(); $this->assertAmounts($payment2, 60.0, 40.0, 100.0, 0.0); $this->assertTrue($payment2->isPartlyPaid()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 60); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(60)); $payment3 = $charge->getPayment(); $this->assertAmounts($payment3, 00.0, 100.0, 100.0, 0.0); $this->assertTrue($payment3->isCompleted()); @@ -483,14 +488,14 @@ public function exceptionShouldBeThrownWhenChargingMoreThenAuthorized(): void $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 50); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(50)); $payment1 = $charge->getPayment(); $this->assertAmounts($payment1, 50.0, 50.0, 100.0, 0.0); $this->assertTrue($payment1->isPartlyPaid()); $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_CHARGED_AMOUNT_HIGHER_THAN_EXPECTED); - $this->unzer->chargeAuthorization($payment->getId(), 70); + $this->unzer->performChargeOnPayment($payment->getId(), new Charge(70)); } /** @@ -509,12 +514,12 @@ public function partialAndFullChargeAfterAuthorization(): void $this->assertAmounts($payment, 100.0, 0.0, 100.0, 0.0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 20); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(20)); $payment1 = $charge->getPayment(); $this->assertAmounts($payment1, 80.0, 20.0, 100.0, 0.0); $this->assertTrue($payment1->isPartlyPaid()); - $charge = $this->unzer->chargeAuthorization($payment->getId()); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge()); $payment2 = $charge->getPayment(); $this->assertAmounts($payment2, 0.0, 100.0, 100.0, 0.0); $this->assertTrue($payment2->isCompleted()); diff --git a/test/integration/PaymentTypes/EPSTest.php b/test/integration/PaymentTypes/EPSTest.php index 8faa874b9..43f28754b 100755 --- a/test/integration/PaymentTypes/EPSTest.php +++ b/test/integration/PaymentTypes/EPSTest.php @@ -14,6 +14,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\EPS; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; class EPSTest extends BaseIntegrationTest @@ -58,7 +59,7 @@ public function epsShouldThrowExceptionOnAuthorize(EPS $eps): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(1.0, 'EUR', $eps, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $eps); } /** diff --git a/test/integration/PaymentTypes/HirePurchaseTest.php b/test/integration/PaymentTypes/HirePurchaseTest.php deleted file mode 100644 index 5e6a87ce3..000000000 --- a/test/integration/PaymentTypes/HirePurchaseTest.php +++ /dev/null @@ -1,139 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verify, backwards compatibility regarding fetching payment type and map it to invoice secured class. - * - * @test - */ - public function hddTypeShouldBeFetchable(): InstallmentSecured - { - // Mock a hdd Type - $date = $this->getTodaysDateString(); - $requestData = - [ - "iban" => "DE89370400440532013000", - "bic" => "COBADEFFXXX", - "accountHolder" => "Max Mustermann", - "invoiceDueDate" => $date, - "numberOfRates" => 3, - "invoiceDate" => $date, - "dayOfPurchase" => $date, - "orderDate" => $date, - "totalPurchaseAmount" => 119, - "totalInterestAmount" => 0.96, - "totalAmount" => 119.96, - "effectiveInterestRate" => 4.99, - "nominalInterestRate" => 4.92, - "feeFirstRate" => 0, - "feePerRate" => 0, - "monthlyRate" => 39.99, - "lastRate" => 39.98, - ]; - - $payload = json_encode($requestData); - $hddMock = $this->getMockBuilder(InstallmentSecured::class) - ->setMethods(['getUri', 'jsonSerialize']) - ->getMock(); - $hddMock->method('getUri')->willReturn('/types/hire-purchase-direct-debit'); - $hddMock->method('jsonSerialize')->willReturn($payload); - - // When - /** @var InstallmentSecured $hddMock */ - $this->unzer->createPaymentType($hddMock); - $this->assertMatchesRegularExpression('/^s-hdd-[.]*/', $hddMock->getId()); - - // Then - $fetchedType = $this->unzer->fetchPaymentType($hddMock->getId()); - $this->assertInstanceOf(InstallmentSecured::class, $fetchedType); - $this->assertMatchesRegularExpression('/^s-hdd-[.]*/', $fetchedType->getId()); - - return $fetchedType; - } - - /** - * Verify fetched hdd type can be authorized and charged - * - * @test - * - * @depends hddTypeShouldBeFetchable - * - * @param InstallmentSecured $hddType fetched hdd type. - * - * @return AbstractUnzerResource|Charge - * - * @throws UnzerApiException - */ - public function hddTypeAuthorizeAndCharge(InstallmentSecured $hddType) - { - $customer = $this->getMaximumCustomer(); - $basket = $this->createBasket(); - - $auth = $hddType->authorize(119.00, 'EUR', 'https://unzer.com', $customer, null, null, $basket); - $charge = $auth->getPayment()->charge(); - $this->assertNotNull($auth); - $this->assertNotEmpty($auth->getId()); - $this->assertTrue($auth->isSuccess()); - - return $charge; - } - - /** - * Verify fetched hdd payment can be shipped. - * - * @test - * - * @depends hddTypeAuthorizeAndCharge - */ - public function hddTypeShouldBeShippable(Charge $hddCharge) - { - $invoiceId = 'i' . self::generateRandomId(); - $ship = $this->unzer->ship($hddCharge->getPayment(), $invoiceId); - - $this->assertNotNull($ship); - return $hddCharge; - } - - /** - * Verify full cancel of charged HP after shipment. - * - * @test - * - * @depends hddTypeAuthorizeAndCharge - */ - public function hddChargeCanBePartiallyCancledBeforeShipment(Charge $hddCharge): void - { - $payment = $hddCharge->getPayment(); - - $cancel1 = $payment->cancelAmount(66, null, null, 60, 6); - $cancel2 = $payment->cancelAmount(43, null, null, 40, 3); - $this->assertGreaterThan(0, count($cancel1)); - $this->assertGreaterThan(0, count($cancel2)); - } -} diff --git a/test/integration/PaymentTypes/IdealTest.php b/test/integration/PaymentTypes/IdealTest.php index f155904e5..92b5991e6 100755 --- a/test/integration/PaymentTypes/IdealTest.php +++ b/test/integration/PaymentTypes/IdealTest.php @@ -14,6 +14,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\Ideal; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; @@ -50,7 +51,7 @@ public function idealShouldThrowExceptionOnAuthorize(Ideal $ideal): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(1.0, 'EUR', $ideal, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $ideal); } /** diff --git a/test/integration/PaymentTypes/InstallmentSecuredTest.php b/test/integration/PaymentTypes/InstallmentSecuredTest.php deleted file mode 100644 index 07ef3d0b8..000000000 --- a/test/integration/PaymentTypes/InstallmentSecuredTest.php +++ /dev/null @@ -1,323 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verify the following features: - * 1. fetching instalment plans. - * 2. selecting plan - * 3. create ins resource - * 4. fetch ins resource - * 5 test update ins resource - * - * @test - */ - public function instalmentPlanShouldBeSelectable(): void - { - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[1]; - - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann'); - $this->unzer->createPaymentType($ins); - $this->assertArrayContains($selectedPlan->expose(), $ins->expose()); - - $fetchedIns = $this->unzer->fetchPaymentType($ins->getId()); - $this->assertEquals($ins->expose(), $fetchedIns->expose()); - - $ins->setIban('DE89370400440532013000') - ->setBic('COBADEFFXXX') - ->setAccountHolder('Peter Universum') - ->setInvoiceDate($this->getYesterdaysTimestamp()) - ->setInvoiceDueDate($this->getTomorrowsTimestamp()); - $insClone = clone $ins; - $this->unzer->updatePaymentType($ins); - $this->assertEquals($insClone->expose(), $ins->expose()); - } - - /** - * Verify Installment Secured authorization (positive and negative). - * - * @test - * - * @dataProvider CustomerRankingDataProvider - * - * @param $firstname - * @param $lastname - * @param $errorCode - */ - public function installmentSecuredAuthorize($firstname, $lastname, $errorCode): void - { - $hpPlans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99); - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $hpPlans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann'); - $this->unzer->createPaymentType($ins); - - $customer = $this->getCustomer()->setFirstname($firstname)->setLastname($lastname); - $basket = $this->createBasket(); - - try { - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); - if ($errorCode !== null) { - $this->assertTrue(false, 'Expected error for negative ranking test.'); - } - $this->assertNotEmpty($authorize->getId()); - } catch (UnzerApiException $e) { - if ($errorCode !== null) { - $this->assertEquals($errorCode, $e->getCode()); - } else { - $this->assertTrue(false, "No error expected for positive ranking test. ({$e->getCode()})"); - } - } - } - - /** - * Verify fetching instalment plans. - * - * @test - */ - public function instalmentPlanSelectionWithAllFieldsSet(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $this->assertCount($selectedPlan->getNumberOfRates(), $selectedPlan->getInstallmentRates(), 'The number of rates should equal the actual rate count.'); - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - $this->assertArrayContains($selectedPlan->expose(), $ins->expose()); - } - - /** - * Verify charge. - * - * @test - */ - public function verifyChargingAnInitializedInstallmentSecured(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); - $payment = $authorize->getPayment(); - $charge = $payment->charge(); - $this->assertNotNull($charge->getId()); - } - - // - - /** - * Verify charge and ship. - * - * @test - */ - public function verifyShippingAChargedInstallmentSecured(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $this->createBasket()); - $payment = $authorize->getPayment(); - $payment->charge(); - $shipment = $payment->ship(); - $this->assertNotNull($shipment->getId()); - } - - // - - // - - /** - * Verify full cancel of charged HP. - * - * @test - */ - public function verifyChargeAndFullCancelAnInitializedInstallmentSecured(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); - $payment = $authorize->getPayment(); - $payment->charge(); - $cancel = $payment->cancelAmount(); - $this->assertGreaterThan(0, count($cancel)); - } - - /** - * Verify full cancel of charged HP. - * - * @test - */ - public function verifyPartlyCancelChargedInstallmentSecured(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); - $payment = $authorize->getPayment(); - $payment->charge(); - $cancel = $payment->cancelAmount(59.5, null, null, 50.0, 9.5); - $this->assertCount(1, $cancel); - $this->assertTrue($payment->isCompleted()); - } - - /** - * Verify full cancel of charged HP after shipment. - * - * @test - */ - public function verifyChargeAndFullCancelAnInitializedInstallmentSecuredAfterShipment(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); - $payment = $authorize->getPayment(); - - $charge = $payment->charge(); - $invoiceId = 'i' . self::generateRandomId(); - $ship = $this->unzer->ship($charge->getPayment(), $invoiceId); - $this->assertNotNull($ship); - - $cancel = $payment->cancelAmount(); - $this->assertGreaterThan(0, count($cancel)); - } - - /** - * Verify full cancel of charged HP after shipment. - * - * @test - */ - public function verifyPartlyCancelChargedInstallmentSecuredAfterShipment(): void - { - $yesterday = $this->getYesterdaysTimestamp(); - $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); - $this->assertGreaterThan(0, count($plans->getPlans())); - - /** @var InstalmentPlan $selectedPlan */ - $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); - $this->unzer->createPaymentType($ins); - - $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); - $payment = $authorize->getPayment(); - - $charge = $payment->charge(); - $invoiceId = 'i' . self::generateRandomId(); - $ship = $this->unzer->ship($charge->getPayment(), $invoiceId); - $this->assertNotNull($ship); - - $cancel = $payment->cancelAmount(59.5, null, null, 50.0, 9.5); - $this->assertCount(1, $cancel); - $this->assertTrue($payment->isCompleted()); - } - - // - - // - - /** - * @return Customer - */ - public function getCustomer(): Customer - { - $customer = CustomerFactory::createCustomer('Manuel', 'Weißmann'); - $address = (new Address()) - ->setStreet('Hugo-Junckers-Straße 3') - ->setState('DE-BO') - ->setZip('60386') - ->setCity('Frankfurt am Main') - ->setCountry('DE'); - $customer - ->setBillingAddress($address) - ->setBirthDate('2000-12-12') - ->setEmail('manuel-weissmann@unzer.com'); - - return $customer; - } - - // - - // - - /** - * @return array - */ - public function CustomerRankingDataProvider(): array - { - return [ - 'positive' => ['Manuel', 'Weißmann', null], - 'negative #1 - Payment guarantee' => ['Manuel', 'Zeißmann', ApiResponseCodes::SDM_ERROR_CURRENT_INSURANCE_EVENT], - 'positive #2 - Limit exceeded' => ['Manuel', 'Leißmann', ApiResponseCodes::SDM_ERROR_LIMIT_EXCEEDED], - 'positive #3 - Negative trait' => ['Imuel', 'Seißmann', ApiResponseCodes::SDM_ERROR_NEGATIVE_TRAIT_FOUND], - 'positive #4 - Negative increased risk' => ['Jamuel', 'Seißmann', ApiResponseCodes::SDM_ERROR_INCREASED_RISK] - ]; - } - - // -} diff --git a/test/integration/PaymentTypes/InvoiceGuaranteedTest.php b/test/integration/PaymentTypes/InvoiceGuaranteedTest.php deleted file mode 100644 index 54b75d8f0..000000000 --- a/test/integration/PaymentTypes/InvoiceGuaranteedTest.php +++ /dev/null @@ -1,91 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verify, backwards compatibility regarding fetching payment type and map it to invoice secured class. - * - * @test - */ - public function ivgTypeShouldBeFetchable(): InvoiceSecured - { - $ivgMock = $this->getMockBuilder(InvoiceSecured::class)->setMethods(['getUri'])->getMock(); - $ivgMock->method('getUri')->willReturn('/types/invoice-guaranteed'); - - /** @var InvoiceSecured $ivgType */ - $ivgType = $this->unzer->createPaymentType($ivgMock); - $this->assertInstanceOf(InvoiceSecured::class, $ivgType); - $this->assertMatchesRegularExpression('/^s-ivg-[.]*/', $ivgType->getId()); - - $fetchedType = $this->unzer->fetchPaymentType($ivgType->getId()); - $this->assertInstanceOf(InvoiceSecured::class, $fetchedType); - $this->assertMatchesRegularExpression('/^s-ivg-[.]*/', $fetchedType->getId()); - - return $fetchedType; - } - - /** - * Verify fetched ivg type can be charged - * - * @test - * - * @depends ivgTypeShouldBeFetchable - * - * @param InvoiceSecured $ivgType fetched ivg type. - * - * @throws UnzerApiException - */ - public function ivgTypeShouldBeChargable(InvoiceSecured $ivgType) - { - $customer = $this->getMaximumCustomer(); - $charge = $ivgType->charge(100.00, 'EUR', 'https://unzer.com', $customer); - - $this->assertNotNull($charge); - $this->assertNotEmpty($charge->getId()); - $this->assertTrue($charge->isPending()); - - return $charge; - } - - /** - * Verify fetched ivg type can be shipped. - * - * @test - * - * @depends ivgTypeShouldBeChargable - */ - public function ivgTypeShouldBeShippable(Charge $ivgCharge) - { - $invoiceId = 'i' . self::generateRandomId(); - - $ship = $this->unzer->ship($ivgCharge->getPayment(), $invoiceId); - // expect Payment to be pending after shipment. - $this->assertTrue($ship->getPayment()->isPending()); - $this->assertNotNull($ship); - } -} diff --git a/test/integration/PaymentTypes/InvoiceSecuredTest.php b/test/integration/PaymentTypes/InvoiceSecuredTest.php deleted file mode 100644 index f76607ea8..000000000 --- a/test/integration/PaymentTypes/InvoiceSecuredTest.php +++ /dev/null @@ -1,350 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verifies Invoice Secured payment type can be created. - * - * @test - * - * @return InvoiceSecured - */ - public function invoiceSecuredTypeShouldBeCreatableAndFetchable(): InvoiceSecured - { - /** @var InvoiceSecured $invoice */ - $invoice = $this->unzer->createPaymentType(new InvoiceSecured()); - $this->assertInstanceOf(InvoiceSecured::class, $invoice); - $this->assertNotNull($invoice->getId()); - - $fetchedInvoice = $this->unzer->fetchPaymentType($invoice->getId()); - $this->assertInstanceOf(InvoiceSecured::class, $fetchedInvoice); - $this->assertEquals($invoice->getId(), $fetchedInvoice->getId()); - - return $invoice; - } - - /** - * Verify Invoice Secured is not authorizable. - * - * @test - * - * @param InvoiceSecured $invoice - * - * @depends invoiceSecuredTypeShouldBeCreatableAndFetchable - */ - public function verifyInvoiceIsNotAuthorizable(InvoiceSecured $invoice): void - { - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - - $this->unzer->authorize(1.0, 'EUR', $invoice, self::RETURN_URL); - } - - /** - * Verify Invoice Secured needs a customer object - * - * @test - * - * @depends invoiceSecuredTypeShouldBeCreatableAndFetchable - * - * @param InvoiceSecured $invoiceSecured - */ - public function invoiceSecuredShouldRequiresCustomer(InvoiceSecured $invoiceSecured): void - { - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_FACTORING_REQUIRES_CUSTOMER); - $this->unzer->charge(1.0, 'EUR', $invoiceSecured, self::RETURN_URL); - } - - /** - * Verify Invoice Secured is chargeable. - * - * @test - * - * @depends invoiceSecuredTypeShouldBeCreatableAndFetchable - * - * @param InvoiceSecured $invoiceSecured - */ - public function invoiceSecuredRequiresBasket(InvoiceSecured $invoiceSecured): void - { - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_FACTORING_REQUIRES_BASKET); - - $invoiceSecured->charge(1.0, 'EUR', self::RETURN_URL, $customer); - } - - /** - * Verify charge with Invoice Secured throws an error when invalid ip is set. - * - * @test - */ - public function invoiceSecuredRequiresValidClientIpForCharge(): void - { - $clientIp = '123.456.789.123'; - $this->unzer->setClientIp($clientIp); - - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - $this->unzer->setClientIp(null); // Ensure that the invalid ip is only used for type creation. - $this->assertEquals($clientIp, $invoiceSecured->getGeoLocation()->getClientIp()); - - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - $basket = $this->createBasket(); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::CORE_INVALID_IP_NUMBER); - - $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket); - } - - /** - * Verify creating a payment type with client ip header set, will overwrite the clientIp of the API resource. - * - * @test - */ - public function verifySettingClientIpViaHeaderWillOverwriteClientIpOfTypeResource(): void - { - $clientIp = 'xxx.xxx.xxx.xxx'; - $this->unzer->setClientIp($clientIp); - - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - $this->assertEquals($clientIp, $invoiceSecured->getGeoLocation()->getClientIp()); - } - - /** - * Verify Invoice Secured is chargeable. - * - * @test - * - * @depends invoiceSecuredTypeShouldBeCreatableAndFetchable - * - * @param InvoiceSecured $invoiceSecured - * - * @return Charge - */ - public function invoiceSecuredShouldBeChargeable(InvoiceSecured $invoiceSecured): Charge - { - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $charge = $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket); - $this->assertNotNull($charge); - $this->assertNotEmpty($charge->getId()); - $this->assertNotEmpty($charge->getIban()); - $this->assertNotEmpty($charge->getBic()); - $this->assertNotEmpty($charge->getHolder()); - $this->assertNotEmpty($charge->getDescriptor()); - - return $charge; - } - - /** - * Verify Invoice Secured is not shippable on Unzer object. - * - * @test - */ - public function verifyInvoiceSecuredIsNotShippableWoInvoiceIdOnUnzerObject(): void - { - // create payment type - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - // perform charge - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $charge = $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket); - - // perform shipment - $payment = $charge->getPayment(); - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_SHIPPING_REQUIRES_INVOICE_ID); - $this->unzer->ship($payment); - } - - /** - * Verify Invoice Secured is not shippable on payment object. - * - * @test - */ - public function verifyInvoiceSecuredIsNotShippableWoInvoiceIdOnPaymentObject(): void - { - // create payment type - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - // perform charge - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $charge = $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket); - - // perform shipment - $payment = $charge->getPayment(); - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_SHIPPING_REQUIRES_INVOICE_ID); - $payment->ship(); - } - - /** - * Verify Invoice Secured shipment with invoice id on Unzer object. - * - * @test - */ - public function verifyInvoiceSecuredShipmentWithInvoiceIdOnUnzerObject(): void - { - // create payment type - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - // perform charge - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $charge = $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket); - - // perform shipment - $payment = $charge->getPayment(); - $invoiceId = 'i' . self::generateRandomId(); - $shipment = $this->unzer->ship($payment, $invoiceId); - // expect Payment to be completed after shipment. - $this->assertTrue($shipment->getPayment()->isCompleted()); - $this->assertNotNull($shipment->getId()); - $this->assertEquals($invoiceId, $shipment->getInvoiceId()); - } - - /** - * Verify Invoice Secured shipment with invoice id on payment object. - * - * @test - */ - public function verifyInvoiceSecuredShipmentWithInvoiceIdOnPaymentObject(): void - { - // create payment type - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - // perform charge - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $charge = $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket); - - $payment = $charge->getPayment(); - $invoiceId = 'i' . self::generateRandomId(); - $shipment = $payment->ship($invoiceId); - $this->assertNotNull($shipment->getId()); - $this->assertEquals($invoiceId, $shipment->getInvoiceId()); - } - - /** - * Verify Invoice Secured shipment with pre set invoice id - * - * @test - */ - public function verifyInvoiceSecuredShipmentWithPreSetInvoiceId(): void - { - /** @var InvoiceSecured $invoiceSecured */ - $invoiceSecured = $this->unzer->createPaymentType(new InvoiceSecured()); - - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - - $basket = $this->createBasket(); - $invoiceId = 'i' . self::generateRandomId(); - $charge = $invoiceSecured->charge(119.0, 'EUR', self::RETURN_URL, $customer, $basket->getOrderId(), null, $basket, null, $invoiceId); - - $payment = $charge->getPayment(); - $shipment = $this->unzer->ship($payment); - $this->assertNotNull($shipment->getId()); - $this->assertEquals($invoiceId, $shipment->getInvoiceId()); - } - - /** - * Verify Invoice Secured charge can canceled. - * - * @test - * - * @param Charge $charge - * - * @depends invoiceSecuredShouldBeChargeable - */ - public function verifyInvoiceChargeCanBeCanceled(Charge $charge): Charge - { - $cancellation = $charge->cancel(100, CancelReasonCodes::REASON_CODE_CANCEL); - $this->assertNotNull($cancellation); - $this->assertNotNull($cancellation->getId()); - return $charge; - } - - /** - * Verify Invoice Secured charge cancel throws exception if the amount is missing. - * - * @test - * - * @param Charge $charge - * - * @depends verifyInvoiceChargeCanBeCanceled - */ - public function verifyInvoiceChargeCanBeCancelledWoAmount(Charge $charge): void - { - $cancellation = $charge->cancel(null, CancelReasonCodes::REASON_CODE_CANCEL); - - $this->assertNotNull($cancellation); - $this->assertNotNull($cancellation->getId()); - $this->assertEquals(19.0, $cancellation->getAmount()); - } - - /** - * Verify Invoice Secured charge cancel throws exception if the reason is missing. - * - * @test - * - * @param Charge $charge - * - * @depends invoiceSecuredShouldBeChargeable - */ - public function verifyInvoiceChargeCanNotBeCancelledWoReasonCode(Charge $charge): void - { - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_CANCEL_REASON_CODE_IS_MISSING); - $charge->cancel(100.0); - } -} diff --git a/test/integration/PaymentTypes/InvoiceTest.php b/test/integration/PaymentTypes/InvoiceTest.php deleted file mode 100755 index 443b83373..000000000 --- a/test/integration/PaymentTypes/InvoiceTest.php +++ /dev/null @@ -1,145 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verifies invoice payment type can be created. - * - * @test - */ - public function invoiceTypeShouldBeCreatable(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertNotNull($invoice->getId()); - } - - /** - * Verify invoice is not authorizable. - * - * @test - */ - public function verifyInvoiceIsNotAuthorizable(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - - $this->unzer->authorize(1.0, 'EUR', $invoice, self::RETURN_URL); - } - - /** - * Verify invoice is chargeable. - * - * @test - */ - public function verifyInvoiceIsChargeable(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $charge = $this->unzer->charge(20.0, 'EUR', $invoice, self::RETURN_URL); - $this->assertNotNull($charge); - $this->assertNotEmpty($charge->getId()); - } - - /** - * Verify invoice is not shippable. - * - * @test - */ - public function verifyInvoiceIsNotShippable(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $charge = $invoice->charge(1.0, 'EUR', self::RETURN_URL); - $this->assertNotEmpty($charge->getIban()); - $this->assertNotEmpty($charge->getBic()); - $this->assertNotEmpty($charge->getHolder()); - $this->assertNotEmpty($charge->getDescriptor()); - - $payment = $charge->getPayment(); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_SHIP_NOT_ALLOWED); - - $this->unzer->ship($payment); - } - - /** - * Verify invoice charge can be canceled. - * - * @test - */ - public function verifyInvoiceChargeCanBeCanceled(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $charge = $invoice->charge(1.0, 'EUR', self::RETURN_URL); - $cancellation = $charge->cancel(); - $this->assertNotNull($cancellation); - $this->assertNotNull($cancellation->getId()); - $payment = $cancellation->getPayment(); - $this->assertTrue($payment->isCanceled()); - } - - /** - * Verify invoice charge can be canceled. - * - * @test - */ - public function verifyInvoiceChargeCanBePartlyCanceled(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $charge = $invoice->charge(1.0, 'EUR', self::RETURN_URL); - $cancellation = $charge->cancel(0.5); - $this->assertNotNull($cancellation); - $this->assertNotNull($cancellation->getId()); - $payment = $cancellation->getPayment(); - $this->assertTrue($payment->isPending()); - - $cancellation2 = $charge->cancel(0.5); - $this->assertNotNull($cancellation2); - $this->assertNotNull($cancellation2->getId()); - $payment2 = $cancellation2->getPayment(); - $this->assertTrue($payment2->isCanceled()); - } - - /** - * Verify that an invoice object can be fetched from the api. - * - * @test - */ - public function invoiceTypeCanBeFetched(): void - { - /** @var Invoice $invoice */ - $invoice = $this->unzer->createPaymentType(new Invoice()); - $fetchedInvoice = $this->unzer->fetchPaymentType($invoice->getId()); - $this->assertInstanceOf(Invoice::class, $fetchedInvoice); - $this->assertEquals($invoice->getId(), $fetchedInvoice->getId()); - } -} diff --git a/test/integration/PaymentTypes/OpenBankingTest.php b/test/integration/PaymentTypes/OpenBankingTest.php index 8ffbdb02d..ea2cac457 100644 --- a/test/integration/PaymentTypes/OpenBankingTest.php +++ b/test/integration/PaymentTypes/OpenBankingTest.php @@ -14,9 +14,14 @@ use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\OpenbankingPis; use UnzerSDK\test\BaseIntegrationTest; +use UnzerSDK\test\Helper\TestEnvironmentService; class OpenBankingTest extends BaseIntegrationTest { + public function setUp(): void + { + $this->getUnzerObject(TestEnvironmentService::getUnzerOneTestPrivateKey()); + } /** * Verify OpenBanking payment type can be created and fetched. * diff --git a/test/integration/PaymentTypes/PISTest.php b/test/integration/PaymentTypes/PISTest.php index 7646bd81b..593bb5104 100755 --- a/test/integration/PaymentTypes/PISTest.php +++ b/test/integration/PaymentTypes/PISTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\PIS; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; @@ -76,6 +77,6 @@ public function pisShouldNotBeAuthorizable(PIS $pis): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(100.0, 'EUR', $pis, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $pis); } } diff --git a/test/integration/PaymentTypes/PrepaymentTest.php b/test/integration/PaymentTypes/PrepaymentTest.php index 4f89dd961..6f47d3dee 100755 --- a/test/integration/PaymentTypes/PrepaymentTest.php +++ b/test/integration/PaymentTypes/PrepaymentTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\PaymentTypes\Prepayment; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; @@ -53,7 +54,7 @@ public function prepaymentShouldBeCreatableAndFetchable(): AbstractUnzerResource */ public function prepaymentTypeShouldBeChargeable(Prepayment $prepayment): Charge { - $charge = $prepayment->charge(100.0, 'EUR', self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $prepayment); $this->assertNotNull($charge); $this->assertNotNull($charge->getId()); $this->assertNotEmpty($charge->getIban()); @@ -78,7 +79,7 @@ public function prepaymentTypeShouldNotBeAuthorizable(Prepayment $prepayment): v $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(100.0, 'EUR', $prepayment, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $prepayment); } /** @@ -109,7 +110,7 @@ public function prepaymentTypeShouldNotBeShippable(Charge $charge): void */ public function prepaymentChargeCanBeCanceled(Prepayment $prepayment): void { - $charge = $prepayment->charge(100.0, 'EUR', self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $prepayment); $this->assertPending($charge); $cancellation = $charge->cancel(); $this->assertTransactionResourceHasBeenCreated($cancellation); diff --git a/test/integration/PaymentTypes/Przelewy24Test.php b/test/integration/PaymentTypes/Przelewy24Test.php index 37c23745c..16a76da0e 100755 --- a/test/integration/PaymentTypes/Przelewy24Test.php +++ b/test/integration/PaymentTypes/Przelewy24Test.php @@ -16,9 +16,9 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\Przelewy24; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; -use UnzerSDK\test\Helper\TestEnvironmentService; class Przelewy24Test extends BaseIntegrationTest { @@ -84,7 +84,7 @@ public function przelewy24ShouldNotBeAuthorizable(Przelewy24 $przelewy24): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(100.0, 'PLN', $przelewy24, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'PLN', self::RETURN_URL), $przelewy24); } /** @@ -122,7 +122,7 @@ public function przelewy24ShouldThrowExceptionIfCurrencyIsNotSupported($currency */ public function legazyConfigPrzelewy24ShouldThrowExceptionIfCurrencyIsNotSupported($currencyCode): void { - $this->getUnzerObject()->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); + $this->useLegacyKey(); /** @var Przelewy24 $przelewy24 */ $przelewy24 = $this->unzer->createPaymentType(new Przelewy24()); $this->expectException(UnzerApiException::class); diff --git a/test/integration/PaymentTypes/SepaDirectDebitSecuredTest.php b/test/integration/PaymentTypes/SepaDirectDebitSecuredTest.php deleted file mode 100644 index b2d89c4e5..000000000 --- a/test/integration/PaymentTypes/SepaDirectDebitSecuredTest.php +++ /dev/null @@ -1,224 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verify sepa direct debit secured can be created with mandatory fields only. - * - * @test - */ - public function sepaDirectDebitSecuredShouldBeCreatableWithMandatoryFieldsOnly(): void - { - $directDebitSecured = new SepaDirectDebitSecured('DE89370400440532013000'); - /** @var SepaDirectDebitSecured $directDebitSecured */ - $directDebitSecured = $this->unzer->createPaymentType($directDebitSecured); - $this->assertInstanceOf(SepaDirectDebitSecured::class, $directDebitSecured); - $this->assertNotNull($directDebitSecured->getId()); - - /** @var SepaDirectDebitSecured $fetchedDirectDebitSecured */ - $fetchedDirectDebitSecured = $this->unzer->fetchPaymentType($directDebitSecured->getId()); - $this->assertEquals($directDebitSecured->expose(), $fetchedDirectDebitSecured->expose()); - } - - /** - * Verify sepa direct debit secured can be created. - * - * @test - * - * @return SepaDirectDebitSecured - */ - public function sepaDirectDebitSecuredShouldBeCreatable(): SepaDirectDebitSecured - { - $directDebitSecured = (new SepaDirectDebitSecured('DE89370400440532013000'))->setHolder('John Doe')->setBic('COBADEFFXXX'); - /** @var SepaDirectDebitSecured $directDebitSecured */ - $directDebitSecured = $this->unzer->createPaymentType($directDebitSecured); - $this->assertInstanceOf(SepaDirectDebitSecured::class, $directDebitSecured); - $this->assertNotNull($directDebitSecured->getId()); - - /** @var SepaDirectDebitSecured $fetchedDirectDebitSecured */ - $fetchedDirectDebitSecured = $this->unzer->fetchPaymentType($directDebitSecured->getId()); - $this->assertEquals($directDebitSecured->expose(), $fetchedDirectDebitSecured->expose()); - - return $fetchedDirectDebitSecured; - } - - /** - * Verify Sepa Direct Debit Secured needs a basket object - * - * @test - * - * @depends sepaDirectDebitSecuredShouldBeCreatable - * - * @param sepaDirectDebitSecured $sepaDirectDebitSecured - */ - public function sepaDirectDebitSecuredRequiresBasket(SepaDirectDebitSecured $sepaDirectDebitSecured): void - { - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_FACTORING_REQUIRES_BASKET); - $this->unzer->charge(1.0, 'EUR', $sepaDirectDebitSecured, self::RETURN_URL); - } - - /** - * Verify Sepa Direct Debit Secured needs a customer object - * - * @test - * - * @depends sepaDirectDebitSecuredShouldBeCreatable - * - * @param sepaDirectDebitSecured $sepaDirectDebitSecured - */ - public function sepaDirectDebitSecuredRequiresCustomer(SepaDirectDebitSecured $sepaDirectDebitSecured): void - { - $basket = $this->createBasket(); - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_FACTORING_REQUIRES_CUSTOMER); - $this->unzer->charge(1.0, 'EUR', $sepaDirectDebitSecured, self::RETURN_URL, null, null, null, $basket); - } - - /** - * Verify authorization is not allowed for sepa direct debit secured. - * - * @test - * - * @param SepaDirectDebitSecured $directDebitSecured - * - * @depends sepaDirectDebitSecuredShouldBeCreatable - */ - public function directDebitSecuredShouldProhibitAuthorization(SepaDirectDebitSecured $directDebitSecured): void - { - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - - $this->unzer->authorize(1.0, 'EUR', $directDebitSecured, self::RETURN_URL); - } - - /** - * Verify direct debit secured can be charged. - * - * @test - */ - public function directDebitSecuredShouldAllowCharge(): void - { - $directDebitSecured = (new SepaDirectDebitSecured('DE89370400440532013000'))->setBic('COBADEFFXXX'); - $this->unzer->createPaymentType($directDebitSecured); - - $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - $basket = $this->createBasket(); - $charge = $directDebitSecured->charge(100.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); - $this->assertTransactionResourceHasBeenCreated($charge); - } - - /** - * Verify ddg will throw error if addresses do not match. - * - * @test - */ - public function ddgShouldThrowErrorIfAddressesDoNotMatch(): void - { - $directDebitSecured = (new SepaDirectDebitSecured('DE89370400440532013000'))->setBic('COBADEFFXXX'); - $this->unzer->createPaymentType($directDebitSecured); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_ADDRESSES_DO_NOT_MATCH); - - $customer = $this->getMaximumCustomerInclShippingAddress(); - $basket = $this->createBasket(); - $directDebitSecured->charge(100.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); - } - - /** - * Verify, backwards compatibility regarding fetching payment type and map it to direct debit secured class. - * - * @test - */ - public function ddgTypeShouldBeFechable(): SepaDirectDebitSecured - { - // Mock a ddg Type - $ddgMock = $this->getMockBuilder(SepaDirectDebitSecured::class) - ->setMethods(['getUri']) - ->setConstructorArgs(['DE89370400440532013000']) - ->getMock(); - $ddgMock->method('getUri')->willReturn('/types/sepa-direct-debit-guaranteed'); - - // When - /** @var SepaDirectDebitSecured $insType */ - $this->unzer->createPaymentType($ddgMock); - $this->assertMatchesRegularExpression('/^s-ddg-[.]*/', $ddgMock->getId()); - - // Then - $fetchedType = $this->unzer->fetchPaymentType($ddgMock->getId()); - $this->assertInstanceOf(SepaDirectDebitSecured::class, $fetchedType); - $this->assertMatchesRegularExpression('/^s-ddg-[.]*/', $fetchedType->getId()); - - return $fetchedType; - } - - /** - * Verify fetched ddg type can be charged - * - * @test - * - * @depends ddgTypeShouldBeFechable - * - * @param SepaDirectDebitSecured $ddgType fetched ins type. - * - * @throws UnzerApiException - */ - public function ddgTypeCharge(SepaDirectDebitSecured $ddgType) - { - $customer = $this->getMaximumCustomer(); - $basket = $this->createBasket(); - - /** @var Charge $auth */ - $charge = $ddgType->charge(119.00, 'EUR', 'https://unzer.com', $customer, null, null, $basket); - $this->assertNotNull($charge); - $this->assertNotEmpty($charge->getId()); - $this->assertTrue($charge->isSuccess()); - - return $charge; - } - - /** - * Verify fetched ddg payment throws an exception when being shipped. - * - * @test - * - * @depends ddgTypeCharge - * - * @param Charge $ddgCharge - * - * @throws UnzerApiException - */ - public function insTypeShouldNotBeShippable(Charge $ddgCharge) - { - $invoiceId = 'i' . self::generateRandomId(); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::CORE_ERROR_INSURANCE_ALREADY_ACTIVATED); - $this->unzer->ship($ddgCharge->getPayment(), $invoiceId); - } -} diff --git a/test/integration/PaymentTypes/SepaDirectDebitTest.php b/test/integration/PaymentTypes/SepaDirectDebitTest.php index b97268e02..c1e3085cf 100755 --- a/test/integration/PaymentTypes/SepaDirectDebitTest.php +++ b/test/integration/PaymentTypes/SepaDirectDebitTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; class SepaDirectDebitTest extends BaseIntegrationTest @@ -73,7 +74,7 @@ public function authorizeShouldThrowException(): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(1.0, 'EUR', $sdd, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(1.0, 'EUR', self::RETURN_URL), $sdd); } /** diff --git a/test/integration/PaymentTypes/SofortTest.php b/test/integration/PaymentTypes/SofortTest.php deleted file mode 100755 index ebcdd100c..000000000 --- a/test/integration/PaymentTypes/SofortTest.php +++ /dev/null @@ -1,82 +0,0 @@ -unzer->createPaymentType(new Sofort()); - $this->assertInstanceOf(Sofort::class, $sofort); - $this->assertNotNull($sofort->getId()); - - /** @var Sofort $fetchedSofort */ - $fetchedSofort = $this->unzer->fetchPaymentType($sofort->getId()); - $this->assertInstanceOf(Sofort::class, $fetchedSofort); - $this->assertEquals($sofort->expose(), $fetchedSofort->expose()); - $this->assertNotEmpty($fetchedSofort->getGeoLocation()->getClientIp()); - - return $fetchedSofort; - } - - /** - * Verify sofort is chargeable. - * - * @test - * - * @param Sofort $sofort - * - * @return Charge - * - * @depends sofortShouldBeCreatableAndFetchable - */ - public function sofortShouldBeAbleToCharge(Sofort $sofort): Charge - { - $charge = $sofort->charge(100.0, 'EUR', self::RETURN_URL); - $this->assertNotNull($charge); - $this->assertNotEmpty($charge->getId()); - $this->assertNotEmpty($charge->getRedirectUrl()); - - return $charge; - } - - /** - * Verify sofort is not authorizable. - * - * @test - * - * @param Sofort $sofort - * - * @depends sofortShouldBeCreatableAndFetchable - */ - public function sofortShouldNotBeAuthorizable(Sofort $sofort): void - { - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - - $this->unzer->authorize(100.0, 'EUR', $sofort, self::RETURN_URL); - } -} diff --git a/test/integration/PaymentTypes/TwintTest.php b/test/integration/PaymentTypes/TwintTest.php index 9feaf216e..285175958 100755 --- a/test/integration/PaymentTypes/TwintTest.php +++ b/test/integration/PaymentTypes/TwintTest.php @@ -13,6 +13,7 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\Twint; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; @@ -49,7 +50,7 @@ public function typeShouldBeCreatableAndFetchable(): BasePaymentType */ public function twintShouldBeAbleToCharge(BasePaymentType $paymentType): Charge { - $charge = $this->unzer->charge(100.0, 'CHF', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'CHF', self::RETURN_URL), $paymentType); $this->assertNotNull($charge); $this->assertNotEmpty($charge->getId()); $this->assertNotEmpty($charge->getRedirectUrl()); @@ -69,7 +70,7 @@ public function twintShouldNotBeAuthorizable(BasePaymentType $paymentType): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(100.0, 'EUR', $paymentType, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $paymentType); } public function createTypeInstance(): BasePaymentType diff --git a/test/integration/PaymentTypes/WechatpayTest.php b/test/integration/PaymentTypes/WechatpayTest.php index 0cff56fbb..b02bb856f 100755 --- a/test/integration/PaymentTypes/WechatpayTest.php +++ b/test/integration/PaymentTypes/WechatpayTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\PaymentTypes\Wechatpay; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; class WechatpayTest extends BaseIntegrationTest @@ -62,6 +63,6 @@ public function wechatpayShouldNotBeAuthorizable(): void $this->expectException(UnzerApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_TRANSACTION_AUTHORIZE_NOT_ALLOWED); - $this->unzer->authorize(100.0, 'EUR', $wechatpay, self::RETURN_URL); + $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $wechatpay); } } diff --git a/test/integration/PaymentTypes/WeroTest.php b/test/integration/PaymentTypes/WeroTest.php index a7c08e822..6a77f1cad 100644 --- a/test/integration/PaymentTypes/WeroTest.php +++ b/test/integration/PaymentTypes/WeroTest.php @@ -15,9 +15,14 @@ use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; +use UnzerSDK\test\Helper\TestEnvironmentService; class WeroTest extends BaseIntegrationTest { + public function setUp(): void + { + $this->getUnzerObject(TestEnvironmentService::getUnzerOneTestPrivateKey()); + } /** * @test * diff --git a/test/integration/RecurringPaymentTest.php b/test/integration/RecurringPaymentTest.php index abc379a5e..f97f9538e 100644 --- a/test/integration/RecurringPaymentTest.php +++ b/test/integration/RecurringPaymentTest.php @@ -14,82 +14,14 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Constants\RecurrenceTypes; use UnzerSDK\Exceptions\UnzerApiException; -use UnzerSDK\test\Helper\TestEnvironmentService; -use UnzerSDK\Unzer; use UnzerSDK\Resources\PaymentTypes\Card; use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\SepaDirectDebitSecured; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; -use RuntimeException; class RecurringPaymentTest extends BaseIntegrationTest { - /** - * Verify exception is thrown if it is called on a non resource object. - * - * @test - */ - public function exceptionShouldBeThrownIfTheObjectIsNotAResource(): void - { - $resource = new DummyResource(); - - $this->expectException(RuntimeException::class); - $resource->activateRecurring(self::RETURN_URL); - } - - /** - * Verify card with 3ds can activate recurring payments. - * After recurring call the parameters are set. - * - * @test - * - * @deprecated since 1.2.1.0 Get removed with `activateRecurring` method. - */ - public function recurringForCardWith3dsShouldReturnAttributes(): void - { - /** @var Card $card */ - $card = $this->unzer->createPaymentType($this->createCardObject()->set3ds(true)); - $recurring = $card->activateRecurring('https://dev.unzer.com', RecurrenceTypes::SCHEDULED); - $this->assertPending($recurring); - $this->assertEquals('https://dev.unzer.com', $recurring->getReturnUrl()); - $this->assertEquals('scheduled', $recurring->getRecurrenceType($card)); - $this->assertNotEmpty($recurring->getDate()); - - $message = $recurring->getMessage(); - $this->assertEquals(ApiResponseCodes::CORE_TRANSACTION_PENDING, $message->getCode()); - $this->assertNotEmpty($message->getCustomer()); - } - - /** - * Verify card without 3ds can activate recurring payments. - * - * @test - * - * @deprecated since 1.2.1.0 Get removed with `activateRecurring` method. - */ - public function recurringForCardWithout3dsShouldActivateRecurringAtOnce(): void - { - $privateKey = TestEnvironmentService::getTestPrivateKey(true); - if (empty($privateKey)) { - $this->markTestIncomplete('No non 3ds private key set'); - } - $unzer = new Unzer($privateKey); - - $unzer->setDebugMode(true)->setDebugHandler($this->unzer->getDebugHandler()); - - /** @var Card $card */ - $card = $unzer->createPaymentType($this->createCardObject()->set3ds(false)); - $this->assertFalse($card->isRecurring()); - - $recurring = $card->activateRecurring('https://dev.unzer.com'); - $this->assertSuccess($recurring); - - /** @var Card $fetchedCard */ - $fetchedCard = $unzer->fetchPaymentType($card->getId()); - $this->assertTrue($fetchedCard->isRecurring()); - } - /** * Verify paypal can activate recurring payments. * @@ -115,7 +47,7 @@ public function sepaDirectDebitShouldBeAbleToActivateRecurringPayments(): void /** @var SepaDirectDebit $dd */ $dd = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); $this->assertFalse($dd->isRecurring()); - $dd->charge(10.0, 'EUR', self::RETURN_URL); + $this->unzer->performCharge(new Charge(10.0, 'EUR', self::RETURN_URL), $dd); $dd = $this->unzer->fetchPaymentType($dd->getId()); $this->assertTrue($dd->isRecurring()); @@ -124,29 +56,6 @@ public function sepaDirectDebitShouldBeAbleToActivateRecurringPayments(): void $this->unzer->activateRecurringPayment($dd, self::RETURN_URL, RecurrenceTypes::SCHEDULED); } - /** - * Verify sepa direct debit secured can activate recurring payments. - * - * @test - */ - public function sepaDirectDebitSecuredShouldBeAbleToActivateRecurringPayments(): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - /** @var SepaDirectDebitSecured $ddg */ - $ddg = $this->unzer->createPaymentType(new SepaDirectDebitSecured('DE89370400440532013000')); - $this->assertFalse($ddg->isRecurring()); - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - $basket = $this->createBasket(); - $ddg->charge(10.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); - $ddg = $this->unzer->fetchPaymentType($ddg->getId()); - $this->assertTrue($ddg->isRecurring()); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionCode(ApiResponseCodes::API_ERROR_RECURRING_ALREADY_ACTIVE); - $this->unzer->activateRecurringPayment($ddg, self::RETURN_URL); - } - /** * Unsupported recurrence type causes API Exception. 'oneclick' can not be used for recurring request. * @@ -157,6 +66,6 @@ public function activateCardRecurringWithOneclickRecurrenceShouldThrowApiExcepti /** @var Card $card */ $card = $this->unzer->createPaymentType($this->createCardObject()->set3ds(true)); $this->expectException(UnzerApiException::class); - $card->activateRecurring('https://dev.unzer.com', RecurrenceTypes::ONE_CLICK); + $this->unzer->activateRecurringPayment($card, 'https://dev.unzer.com', RecurrenceTypes::ONE_CLICK); } } diff --git a/test/integration/Resources/BasketTest.php b/test/integration/Resources/BasketTest.php deleted file mode 100755 index cef00f304..000000000 --- a/test/integration/Resources/BasketTest.php +++ /dev/null @@ -1,256 +0,0 @@ - - - /** - * Verify basket can be created and fetched. - * - * @test - */ - public function minBasketShouldBeCreatableAndFetchable(): void - { - $orderId = microtime(true); - $basket = new Basket($orderId, 123.4, 'EUR', []); - $basket->setNote('This basket is creatable!'); - $basketItem = new BasketItem('myItem', 1234, 2345, 12); - $basket->addBasketItem($basketItem); - $basketItem = (new BasketItem('title'))->setAmountPerUnit(0.0); - $basket->addBasketItem($basketItem); - $this->assertEmpty($basket->getId()); - - $this->unzer->createBasket($basket); - $this->assertNotEmpty($basket->getId()); - - $fetchedBasket = $this->unzer->fetchBasket($basket->getId()); - $this->assertEquals($basket->expose(), $fetchedBasket->expose()); - $this->assertEquals('This basket is creatable!', $basket->getNote()); - } - - /** - * Verify basket can be created and fetched. - * - * @test - */ - public function maxBasketShouldBeCreatableAndFetchable(): void - { - $basket = new Basket('b' . self::generateRandomId(), 123.4, 'EUR', []); - $basket->setNote('This basket is creatable!'); - $basketItem = (new BasketItem('myItem', 1234, 2345, 12)) - ->setBasketItemReferenceId('refId') - ->setAmountVat(1.24) - ->setVat(19.5) - ->setUnit('ert') - ->setAmountDiscount(1234.9) - ->setImageUrl('https://docs.unzer.com/card/card.png') - ->setSubTitle('This is some subtitle for this item') - ->setType('this is some type'); - $basket->addBasketItem($basketItem); - $this->assertEmpty($basket->getId()); - - $this->unzer->createBasket($basket); - $this->assertNotEmpty($basket->getId()); - - $fetchedBasket = $this->unzer->fetchBasket($basket->getId()); - $this->assertEquals($basket->expose(), $fetchedBasket->expose()); - $this->assertEquals( - $basket->getBasketItemByIndex(0)->expose(), - $fetchedBasket->getBasketItemByIndex(0)->expose() - ); - } - - /** - * Verify basketItem with invalid imageUrl will return an error. - * - * @test - * - * @dataProvider basketItemWithInvalidUrlWillThrowAnErrorDP - * - * @param $expectException - * @param $imageUrl - * @param null $exceptionCode - */ - public function basketItemWithInvalidUrlWillThrowAnError($expectException, $imageUrl, $exceptionCode = null): void - { - $basket = new Basket('b' . self::generateRandomId(), 123.4, 'EUR', []); - $basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setImageUrl($imageUrl); - $basket->addBasketItem($basketItem); - - try { - $this->unzer->createBasket($basket); - $this->assertFalse( - $expectException, - 'Failed asserting that exception of type "UnzerSDK\Exceptions\UnzerApiException" is thrown.' - ); - } catch (UnzerApiException $e) { - $this->assertTrue($expectException); - $this->assertEquals($exceptionCode, $e->getCode()); - $this->assertNotNull($e->getErrorId()); - } - } - - /** - * Verify the Basket can be updated. - * - * @test - */ - public function basketShouldBeUpdateable(): void - { - $orderId = 'o'. self::generateRandomId(); - $basket = new Basket($orderId, 123.4, 'EUR', []); - $basket->setNote('This basket is creatable!'); - $basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId'); - $basket->addBasketItem($basketItem); - $this->unzer->createBasket($basket); - - $fetchedBasket = $this->unzer->fetchBasket($basket->getId()); - $fetchedBasket->setAmountTotalGross(4321); - $fetchedBasket->setAmountTotalDiscount(5432); - $fetchedBasket->setNote('This basket is updateable!'); - $fetchedBasket->getBasketItemByIndex(0)->setTitle('This item can also be updated!'); - $this->unzer->updateBasket($fetchedBasket); - - $this->unzer->fetchBasket($basket); - $this->assertEquals($orderId, $basket->getOrderId()); - $this->assertEquals(4321, $basket->getAmountTotalGross()); - $this->assertEquals(5432, $basket->getAmountTotalDiscount()); - $this->assertEquals('This basket is updateable!', $basket->getNote()); - $this->assertNotEquals($basket->getBasketItemByIndex(0)->expose(), $basketItem->expose()); - } - - /** - * Verify basket can be passed to the payment on authorize. - * - * @test - */ - public function authorizeTransactionsShouldPassAlongTheBasketIdIfSet(): void - { - $this->useLegacyKey(); - - $orderId = 'o'. self::generateRandomId(); - $basket = new Basket($orderId, 123.4, 'EUR', []); - $basket->setNote('This basket is creatable!'); - $basketItem = (new BasketItem('myItem', 123.4, 123.4, 12))->setBasketItemReferenceId('refId'); - $basket->addBasketItem($basketItem); - $this->unzer->createBasket($basket); - $this->assertNotEmpty($basket->getId()); - - /** @var Paypal $paypal */ - $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paypal->authorize(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); - - $fetchedPayment = $this->unzer->fetchPayment($authorize->getPaymentId()); - $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); - } - - /** - * Verify basket can be passed to the payment on charge. - * - * @test - */ - public function chargeTransactionsShouldPassAlongTheBasketIdIfSet(): void - { - $this->useLegacyKey(); - $basket = $this->createBasket(); - $this->assertNotEmpty($basket->getId()); - - $sdd = (new SepaDirectDebit('DE89370400440532013000'))->setBic('COBADEFFXXX'); - $this->unzer->createPaymentType($sdd); - - $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - $charge = $sdd->charge(119.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); - - $fetchedPayment = $this->unzer->fetchPayment($charge->getPaymentId()); - $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); - } - - /** - * Verify basket will be created and passed to the payment on authorize if it does not exist yet. - * - * @test - */ - public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet(): void - { - $this->useLegacyKey(); - - $orderId = 'o'. self::generateRandomId(); - $basket = new Basket($orderId, 123.4, 'EUR', []); - $basket->setNote('This basket is creatable!'); - $basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId'); - $basket->addBasketItem($basketItem); - $this->assertEmpty($basket->getId()); - - /** @var Paypal $paypal */ - $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paypal->authorize(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); - $this->assertNotEmpty($basket->getId()); - - $fetchedPayment = $this->unzer->fetchPayment($authorize->getPaymentId()); - $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); - } - - /** - * Verify basket will be created and passed to the payment on charge if it does not exist yet. - * - * @test - */ - public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet(): void - { - $this->useLegacyKey(); - - $orderId = 'o'. self::generateRandomId(); - $basket = new Basket($orderId, 123.4, 'EUR', []); - $basket->setNote('This basket is creatable!'); - $basket->setAmountTotalVat(10.9); - $basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId'); - $basket->addBasketItem($basketItem); - $this->assertEmpty($basket->getId()); - - /** @var Paypal $paypal */ - $paypal = $this->unzer->createPaymentType(new Paypal()); - $charge = $paypal->charge(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); - $this->assertNotEmpty($basket->getId()); - - $fetchedPayment = $this->unzer->fetchPayment($charge->getPaymentId()); - $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); - } - - // - - // - - /** - * @return array - */ - public function basketItemWithInvalidUrlWillThrowAnErrorDP(): array - { - return [ - 'valid ' => [false, 'https://docs.unzer.com/card/card.png'], - 'valid null' => [false, null], - 'valid empty' => [false, ''], - 'invalid not available' => [true, 'https://files.readme.io/does-not-exist.jpg', ApiResponseCodes::API_ERROR_BASKET_ITEM_IMAGE_INVALID_URL] - ]; - } - - // -} diff --git a/test/integration/Resources/BasketV2Test.php b/test/integration/Resources/BasketV2Test.php index ec9a666d5..40c7f45af 100644 --- a/test/integration/Resources/BasketV2Test.php +++ b/test/integration/Resources/BasketV2Test.php @@ -17,6 +17,8 @@ use UnzerSDK\Resources\EmbeddedResources\BasketItem; use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; +use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; class BasketV2Test extends BaseIntegrationTest @@ -212,7 +214,7 @@ public function authorizeTransactionsShouldPassAlongTheBasketIdIfSet(): void /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paypal->authorize(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); + $authorize = $this->unzer->performAuthorization(new Authorization(123.4, 'EUR', 'https://unzer.com'), $paypal, null, null, $basket); $fetchedPayment = $this->unzer->fetchPayment($authorize->getPaymentId()); $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); @@ -233,7 +235,7 @@ public function chargeTransactionsShouldPassAlongTheBasketIdIfSet(): void $this->unzer->createPaymentType($sdd); $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - $charge = $sdd->charge(119.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); + $charge = $this->unzer->performCharge(new Charge(119.0, 'EUR', self::RETURN_URL), $sdd, $customer, null, $basket); $fetchedPayment = $this->unzer->fetchPayment($charge->getPaymentId()); $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); @@ -261,7 +263,7 @@ public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet(): vo /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paypal->authorize(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); + $authorize = $this->unzer->performAuthorization(new Authorization(123.4, 'EUR', 'https://unzer.com'), $paypal, null, null, $basket); $this->assertNotEmpty($basket->getId()); $fetchedPayment = $this->unzer->fetchPayment($authorize->getPaymentId()); @@ -290,7 +292,7 @@ public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet(): void /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $charge = $paypal->charge(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); + $charge = $this->unzer->performCharge(new Charge(123.4, 'EUR', 'https://unzer.com'), $paypal, null, null, $basket); $this->assertNotEmpty($basket->getId()); $fetchedPayment = $this->unzer->fetchPayment($charge->getPaymentId()); diff --git a/test/integration/Resources/BasketV3Test.php b/test/integration/Resources/BasketV3Test.php index 55f60d993..f3d6ff1f7 100644 --- a/test/integration/Resources/BasketV3Test.php +++ b/test/integration/Resources/BasketV3Test.php @@ -15,6 +15,8 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\EmbeddedResources\BasketItem; use UnzerSDK\Resources\PaymentTypes\Paypal; +use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Resources\V3\Basket; use UnzerSDK\test\BaseIntegrationTest; @@ -220,7 +222,7 @@ public function authorizeTransactionsShouldPassAlongTheBasketIdIfSet(): void /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paypal->authorize(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); + $authorize = $this->unzer->performAuthorization(new Authorization(123.4, 'EUR', 'https://unzer.com'), $paypal, null, null, $basket); $fetchedPayment = $this->unzer->fetchPayment($authorize->getPaymentId()); $this->assertEquals($basket->expose(), $fetchedPayment->getBasket()->expose()); @@ -248,7 +250,7 @@ public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet(): vo /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paypal->authorize(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); + $authorize = $this->unzer->performAuthorization(new Authorization(123.4, 'EUR', 'https://unzer.com'), $paypal, null, null, $basket); $this->assertNotEmpty($basket->getId()); $fetchedPayment = $this->unzer->fetchPayment($authorize->getPaymentId()); @@ -277,7 +279,7 @@ public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet(): void /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $charge = $paypal->charge(123.4, 'EUR', 'https://unzer.com', null, null, null, $basket); + $charge = $this->unzer->performCharge(new Charge(123.4, 'EUR', 'https://unzer.com'), $paypal, null, null, $basket); $this->assertNotEmpty($basket->getId()); $fetchedPayment = $this->unzer->fetchPayment($charge->getPaymentId()); diff --git a/test/integration/Resources/ConfigTest.php b/test/integration/Resources/ConfigTest.php index f2b0212cc..e8076cdcc 100644 --- a/test/integration/Resources/ConfigTest.php +++ b/test/integration/Resources/ConfigTest.php @@ -15,12 +15,9 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Config; use UnzerSDK\Resources\PaymentTypes\Card; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice; use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\SepaDirectDebitSecured; -use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\test\BaseIntegrationTest; class ConfigTest extends BaseIntegrationTest @@ -69,12 +66,9 @@ public function verifyPaymentTypesWithNoConfigThrowExeption($paymentType) public function verifyPaymentTypesWithNoConfigThrowExeptionDp(): array { return [ - 'sofort' => [new Sofort()], 'paypal' => [new Paypal()], 'card' => [new Card(null, null, null)], 'directDebit' => [new SepaDirectDebit(null)], - 'directDebitSecured' => [new SepaDirectDebitSecured(null)], - 'instalment' => [new InstallmentSecured(null)], ]; } } diff --git a/test/integration/Resources/CustomerTest.php b/test/integration/Resources/CustomerTest.php index a8b12ab35..689582e74 100755 --- a/test/integration/Resources/CustomerTest.php +++ b/test/integration/Resources/CustomerTest.php @@ -17,6 +17,7 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\PaymentTypes\Paypal; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; use function microtime; @@ -159,7 +160,7 @@ public function transactionShouldCreateAndReferenceCustomerIfItDoesNotExistYet() /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorization = $paypal->authorize(12.0, 'EUR', self::RETURN_URL, $customer); + $authorization = $this->unzer->performAuthorization(new Authorization(12.0, 'EUR', self::RETURN_URL), $paypal, $customer); $secPayment = $this->unzer->fetchPayment($authorization->getPayment()->getId()); @@ -181,7 +182,7 @@ public function transactionShouldReferenceCustomerIfItExist(): void /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorization = $paypal->authorize(12.0, 'EUR', self::RETURN_URL, $customer); + $authorization = $this->unzer->performAuthorization(new Authorization(12.0, 'EUR', self::RETURN_URL), $paypal, $customer); $secPayment = $this->unzer->fetchPayment($authorization->getPayment()->getId()); @@ -203,7 +204,7 @@ public function transactionShouldReferenceCustomerIfItExistAndItsIdHasBeenPassed /** @var Paypal $paypal */ $paypal = $this->unzer->createPaymentType(new Paypal()); - $authorization = $paypal->authorize(12.0, 'EUR', self::RETURN_URL, $customer->getId()); + $authorization = $this->unzer->performAuthorization(new Authorization(12.0, 'EUR', self::RETURN_URL), $paypal, $customer->getId()); $secPayment = $this->unzer->fetchPayment($authorization->getPayment()->getId()); diff --git a/test/integration/Resources/CustomerV2Test.php b/test/integration/Resources/CustomerV2Test.php index f49d74b88..248499d6c 100755 --- a/test/integration/Resources/CustomerV2Test.php +++ b/test/integration/Resources/CustomerV2Test.php @@ -8,6 +8,7 @@ use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\CustomerFactory; use UnzerSDK\Resources\PaymentTypes\Paypal; +use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\test\BaseIntegrationTest; use function microtime; use function PHPUnit\Framework\assertEquals; @@ -173,7 +174,7 @@ public function transactionShouldCreateAndReferenceCustomerIfItDoesNotExistYet() /** @var Paypal $paypal */ $paypal = $this->getUnzerObject()->createPaymentType(new Paypal()); - $authorization = $paypal->authorize(12.0, 'EUR', self::RETURN_URL, $customer); + $authorization = $this->getUnzerObject()->performAuthorization(new Authorization(12.0, 'EUR', self::RETURN_URL), $paypal, $customer); $secPayment = $this->getUnzerObject()->fetchPayment($authorization->getPayment()->getId()); @@ -195,7 +196,7 @@ public function transactionShouldReferenceCustomerIfItExist(): void /** @var Paypal $paypal */ $paypal = $this->getUnzerObject()->createPaymentType(new Paypal()); - $authorization = $paypal->authorize(12.0, 'EUR', self::RETURN_URL, $customer); + $authorization = $this->getUnzerObject()->performAuthorization(new Authorization(12.0, 'EUR', self::RETURN_URL), $paypal, $customer); $secPayment = $this->getUnzerObject()->fetchPayment($authorization->getPayment()->getId()); @@ -217,7 +218,7 @@ public function transactionShouldReferenceCustomerIfItExistAndItsIdHasBeenPassed /** @var Paypal $paypal */ $paypal = $this->getUnzerObject()->createPaymentType(new Paypal()); - $authorization = $paypal->authorize(12.0, 'EUR', self::RETURN_URL, $customer->getId()); + $authorization = $this->getUnzerObject()->performAuthorization(new Authorization(12.0, 'EUR', self::RETURN_URL), $paypal, $customer->getId()); $secPayment = $this->getUnzerObject()->fetchPayment($authorization->getPayment()->getId()); diff --git a/test/integration/Resources/PaypageV2Test.php b/test/integration/Resources/PaypageV2Test.php index 73c4fd0e9..665760abf 100644 --- a/test/integration/Resources/PaypageV2Test.php +++ b/test/integration/Resources/PaypageV2Test.php @@ -67,6 +67,8 @@ public function createMinimumPaypageTest() $this->assertCreatedPaypage($paypage); + $this->assertNotNull($paypage->getResources()->getMetadataId()); + $this->assertNull($paypage->getType()); $this->assertNull($paypage->getRecurrenceType()); $this->assertNull($paypage->getShopName()); @@ -76,7 +78,6 @@ public function createMinimumPaypageTest() $this->assertNull($paypage->getUrls()); $this->assertNull($paypage->getStyle()); - $this->assertNull($paypage->getResources()); $this->assertNull($paypage->getPaymentMethodsConfigs()); $this->assertNull($paypage->getRisk()); } diff --git a/test/integration/SetMetadataTest.php b/test/integration/SetMetadataTest.php index 3391c1620..3d41f0635 100755 --- a/test/integration/SetMetadataTest.php +++ b/test/integration/SetMetadataTest.php @@ -15,6 +15,8 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaymentTypes\Paypal; +use UnzerSDK\Resources\TransactionTypes\Authorization; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; class SetMetadataTest extends BaseIntegrationTest @@ -65,7 +67,7 @@ public function authorizeShouldCreateMetadata(): void $this->assertEmpty($metadata->getId()); $paypal = $this->unzer->createPaymentType(new Paypal()); - $this->unzer->authorize(1.23, 'EUR', $paypal, 'https://unzer.com', null, null, $metadata); + $this->unzer->performAuthorization(new Authorization(1.23, 'EUR', 'https://unzer.com'), $paypal, null, $metadata); $this->assertNotEmpty($metadata->getId()); } @@ -84,7 +86,7 @@ public function chargeShouldCreateMetadata(): void $this->assertEmpty($metadata->getId()); $paymentType = $this->unzer->createPaymentType(new Paypal()); - $this->unzer->charge(1.23, 'EUR', $paymentType, 'https://unzer.com', null, null, $metadata); + $this->unzer->performCharge(new Charge(1.23, 'EUR', 'https://unzer.com'), $paymentType, null, $metadata); $this->assertNotEmpty($metadata->getId()); } @@ -99,7 +101,7 @@ public function paymentShouldFetchMetadataResourceOnFetch(): void /** @var Paypal $paymentType */ $paymentType = $this->unzer->createPaymentType(new Paypal()); - $authorize = $paymentType->authorize(10.0, 'EUR', 'https://unzer.com', null, null, $metadata); + $authorize = $this->unzer->performAuthorization(new Authorization(10.0, 'EUR', 'https://unzer.com'), $paymentType, null, $metadata); $payment = $authorize->getPayment(); $this->assertSame($metadata, $payment->getMetadata()); diff --git a/test/integration/TransactionTypes/AuthorizationTest.php b/test/integration/TransactionTypes/AuthorizationTest.php index 200097e15..e144a1812 100644 --- a/test/integration/TransactionTypes/AuthorizationTest.php +++ b/test/integration/TransactionTypes/AuthorizationTest.php @@ -31,7 +31,7 @@ class AuthorizationTest extends BaseIntegrationTest public function authorizeWithTypeId(): void { $paymentType = $this->unzer->createPaymentType(new Paypal()); - $authorize = $this->unzer->authorize(100.0, 'EUR', $paymentType->getId(), self::RETURN_URL); + $authorize = $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $paymentType->getId()); $this->assertNotNull($authorize); $this->assertNotEmpty($authorize->getId()); $this->assertNotEmpty($authorize->getUniqueId()); @@ -50,7 +50,7 @@ public function authorizeWithTypeId(): void public function authorizeWithType(): void { $paymentType = $this->unzer->createPaymentType(new Paypal()); - $authorize = $this->unzer->authorize(100.0, 'EUR', $paymentType, self::RETURN_URL); + $authorize = $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $paymentType); $this->assertNotNull($authorize); $this->assertNotNull($authorize->getId()); } @@ -66,7 +66,7 @@ public function authorizationProducesPaymentAndCustomer(): void $customer = $this->getMinimalCustomer(); $this->assertNull($customer->getId()); - $authorize = $this->unzer->authorize(100.0, 'EUR', $paymentType, self::RETURN_URL, $customer); + $authorize = $this->unzer->performAuthorization(new Authorization(100.0, 'EUR', self::RETURN_URL), $paymentType, $customer); $payment = $authorize->getPayment(); $this->assertNotNull($payment); $this->assertNotNull($payment->getId()); @@ -88,7 +88,11 @@ public function authorizationWithCustomerId(): Authorization $paymentType = $this->unzer->createPaymentType(new Paypal()); $customerId = $this->unzer->createCustomer($this->getMinimalCustomer())->getId(); $orderId = microtime(true); - $authorize = $this->unzer->authorize(100.0, 'EUR', $paymentType, self::RETURN_URL, $customerId, $orderId); + $authorize = $this->unzer->performAuthorization( + (new Authorization(100.0, 'EUR', self::RETURN_URL))->setOrderId((string)$orderId), + $paymentType, + $customerId + ); $payment = $authorize->getPayment(); $this->assertNotNull($payment); $this->assertNotNull($payment->getId()); @@ -128,7 +132,7 @@ public function authorizationCanBeFetched(Authorization $authorization): void public function authorizeHasExpectedStates(BasePaymentType $paymentType, $expectedState): void { $paymentType = $this->unzer->createPaymentType($paymentType); - $authorize = $this->unzer->authorize(100.0, 'EUR', $paymentType->getId(), self::RETURN_URL, null, null, null, null, false); + $authorize = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $paymentType->getId()); $stateCheck = 'assert' . ucfirst($expectedState); $this->$stateCheck($authorize); diff --git a/test/integration/TransactionTypes/CancelAfterAuthorizationTest.php b/test/integration/TransactionTypes/CancelAfterAuthorizationTest.php index 4a30030c7..64077027c 100644 --- a/test/integration/TransactionTypes/CancelAfterAuthorizationTest.php +++ b/test/integration/TransactionTypes/CancelAfterAuthorizationTest.php @@ -24,7 +24,7 @@ class CancelAfterAuthorizationTest extends BaseIntegrationTest public function fullCancelOnAuthorization(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.0000, 'EUR', $card, self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $card); /** @var Authorization $fetchedAuthorization */ $fetchedAuthorization = $this->unzer->fetchAuthorization($authorization->getPayment()->getId()); @@ -52,7 +52,7 @@ public function fullCancelOnAuthorization(): void public function partCancelOnPayment(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.0000, 'EUR', $card, self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $card); $payment = $this->unzer->fetchPayment($authorization->getPayment()->getId()); $cancelArray = $payment->cancelAmount(10.0); @@ -70,7 +70,7 @@ public function partCancelOnPayment(): void public function partCancelOnAuthorize(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.0000, 'EUR', $card, self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $card); /** @var Authorization $fetchedAuthorization */ $fetchedAuthorization = $this->unzer->fetchAuthorization($authorization->getPayment()->getId()); @@ -92,7 +92,7 @@ public function partCancelOnAuthorize(): void public function anAuthorizationsFullReversalShallBeFetchable(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.0000, 'EUR', $card, self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $card); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0, 100.0, 0); $this->assertTrue($payment->isPending()); @@ -127,7 +127,7 @@ public function anAuthorizationsFullReversalShallBeFetchable(): void public function anAuthorizationsReversalsShouldBeFetchable(): void { $card = $this->unzer->createPaymentType($this->createCardObject()); - $authorization = $this->unzer->authorize(100.0000, 'EUR', $card, self::RETURN_URL, null, null, null, null, false); + $authorization = $this->unzer->performAuthorization((new Authorization(100.0, 'EUR', self::RETURN_URL))->setCard3ds(false), $card); $payment = $authorization->getPayment(); $this->assertAmounts($payment, 100.0, 0, 100.0, 0); $this->assertTrue($payment->isPending()); diff --git a/test/integration/TransactionTypes/CancelAfterChargeTest.php b/test/integration/TransactionTypes/CancelAfterChargeTest.php index bd0b9b50a..39ef7f16b 100644 --- a/test/integration/TransactionTypes/CancelAfterChargeTest.php +++ b/test/integration/TransactionTypes/CancelAfterChargeTest.php @@ -32,7 +32,7 @@ protected function setUp(): void public function chargeShouldBeFetchable(): Charge { $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0000, 'EUR', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType); $fetchedCharge = $this->unzer->fetchChargeById($charge->getPayment()->getId(), $charge->getId()); $chargeArray = $charge->setCard3ds(false)->expose(); @@ -69,7 +69,7 @@ public function chargeShouldBeFullyRefundable(Charge $charge): void public function chargeShouldBeFullyRefundableWithId(): void { $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0000, 'EUR', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType); $refund = $this->unzer->cancelChargeById($charge->getPayment()->getId(), $charge->getId()); $this->assertNotNull($refund); @@ -84,7 +84,7 @@ public function chargeShouldBeFullyRefundableWithId(): void public function chargeShouldBePartlyRefundableWithId(): void { $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0000, 'EUR', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType); $firstPayment = $this->unzer->fetchPayment($charge->getPayment()->getId()); $this->assertAmounts($firstPayment, 0, 100, 100, 0); @@ -108,7 +108,7 @@ public function chargeShouldBePartlyRefundableWithId(): void public function chargeShouldBePartlyRefundable(): void { $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0000, 'EUR', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType); $firstPayment = $this->unzer->fetchPayment($charge->getPayment()->getId()); $this->assertAmounts($firstPayment, 0, 100, 100, 0); @@ -132,7 +132,7 @@ public function chargeShouldBePartlyRefundable(): void public function cancelShouldAcceptPaymentReferenceParameter(): void { $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0000, 'EUR', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType); $cancel = $charge->cancel(null, null, 'myPaymentReference'); $this->assertEquals('myPaymentReference', $cancel->getPaymentReference()); } diff --git a/test/integration/TransactionTypes/ChargeAfterAuthorizationTest.php b/test/integration/TransactionTypes/ChargeAfterAuthorizationTest.php index 8adfa042a..5ae850a1c 100644 --- a/test/integration/TransactionTypes/ChargeAfterAuthorizationTest.php +++ b/test/integration/TransactionTypes/ChargeAfterAuthorizationTest.php @@ -11,6 +11,7 @@ namespace UnzerSDK\test\integration\TransactionTypes; +use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; class ChargeAfterAuthorizationTest extends BaseIntegrationTest @@ -47,7 +48,7 @@ public function authorizationShouldBeFullyChargeableViaUnzerObject(): void $this->assertAmounts($payment, 100, 0, 100, 0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId()); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge()); $this->unzer->fetchPayment($payment); $this->assertNotNull($charge); $this->assertNotNull($charge->getId()); @@ -67,7 +68,7 @@ public function authorizationShouldBePartlyChargeable(): void $this->assertAmounts($payment, 100, 0, 100, 0); $this->assertTrue($payment->isPending()); - $charge = $this->unzer->chargeAuthorization($payment->getId(), 10); + $charge = $this->unzer->performChargeOnPayment($payment->getId(), new Charge(10)); $this->unzer->fetchPayment($payment); $this->assertNotNull($charge); $this->assertNotNull($charge->getId()); diff --git a/test/integration/TransactionTypes/ChargeTest.php b/test/integration/TransactionTypes/ChargeTest.php index f9f489ad1..c25eb3d9d 100644 --- a/test/integration/TransactionTypes/ChargeTest.php +++ b/test/integration/TransactionTypes/ChargeTest.php @@ -15,11 +15,9 @@ use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\Card; -use UnzerSDK\Resources\PaymentTypes\InvoiceSecured; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; -use UnzerSDK\test\Helper\TestEnvironmentService; class ChargeTest extends BaseIntegrationTest { @@ -32,7 +30,7 @@ public function chargeShouldWorkWithTypeId(): void { $this->useLegacyKey(); $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0, 'EUR', $paymentType->getId(), self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType->getId()); $this->assertTransactionResourceHasBeenCreated($charge); $this->assertInstanceOf(Payment::class, $charge->getPayment()); $this->assertNotEmpty($charge->getPayment()->getId()); @@ -48,7 +46,7 @@ public function chargeShouldWorkWithTypeObject(): void { $this->useLegacyKey(); $paymentType = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); - $charge = $this->unzer->charge(100.0, 'EUR', $paymentType, self::RETURN_URL); + $charge = $this->unzer->performCharge(new Charge(100.0, 'EUR', self::RETURN_URL), $paymentType); $this->assertTransactionResourceHasBeenCreated($charge); $this->assertInstanceOf(Payment::class, $charge->getPayment()); $this->assertNotEmpty($charge->getPayment()->getId()); @@ -168,45 +166,6 @@ public function requestChargeShouldAcceptAllParameters(): void $this->assertEquals($payment->getBasket()->expose(), $fetchedPayment->getBasket()->expose()); } - /** - * Verify charge accepts all parameters. - * - * @test - */ - public function chargeWithCustomerShouldAcceptAllParameters(): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - // prepare test data - /** @var InvoiceSecured $ivg */ - $ivg = $this->unzer->createPaymentType(new InvoiceSecured()); - $customer = $this->getMaximumCustomer(); - $customer->setShippingAddress($customer->getBillingAddress()); - $orderId = 'o'. self::generateRandomId(); - $metadata = (new Metadata())->addMetadata('key', 'value'); - $basket = $this->createBasket(); - $invoiceId = 'i'. self::generateRandomId(); - $paymentReference = 'paymentReference'; - - // perform request - $charge = $ivg->charge(119.0, 'EUR', self::RETURN_URL, $customer, $orderId, $metadata, $basket, null, $invoiceId, $paymentReference); - - // verify the data sent and received match - $payment = $charge->getPayment(); - $this->assertSame($ivg, $payment->getPaymentType()); - $this->assertEquals(119.0, $charge->getAmount()); - $this->assertEquals('EUR', $charge->getCurrency()); - $this->assertEquals(self::RETURN_URL, $charge->getReturnUrl()); - $this->assertSame($customer, $payment->getCustomer()); - $this->assertEquals($orderId, $charge->getOrderId()); - $this->assertSame($metadata, $payment->getMetadata()); - $this->assertSame($basket, $payment->getBasket()); - $this->assertEquals($invoiceId, $charge->getInvoiceId()); - $this->assertEquals($paymentReference, $charge->getPaymentReference()); - - $fetchedCharge = $this->unzer->fetchChargeById($charge->getPaymentId(), $charge->getId()); - $this->assertEquals($charge->setCard3ds(false)->expose(), $fetchedCharge->expose()); - } - /** * Verify checkoutType for not supported type gets ignored by Api. * diff --git a/test/integration/TransactionTypes/PayoutTest.php b/test/integration/TransactionTypes/PayoutTest.php index 5f0c82351..cc7d66d27 100644 --- a/test/integration/TransactionTypes/PayoutTest.php +++ b/test/integration/TransactionTypes/PayoutTest.php @@ -15,11 +15,9 @@ use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\Card; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\SepaDirectDebitSecured; use UnzerSDK\Resources\TransactionTypes\Payout; use UnzerSDK\Services\ResourceService; use UnzerSDK\test\BaseIntegrationTest; -use UnzerSDK\test\Helper\TestEnvironmentService; class PayoutTest extends BaseIntegrationTest { @@ -67,28 +65,6 @@ public function payoutCanBeCalledForSepaDirectDebitType(): void $this->assertAmounts($payment, 0, 0, -100, 0); } - /** - * Verify payout can be performed for sepa direct debit secured payment type. - * - * @test - */ - public function payoutCanBeCalledForSepaDirectDebitSecuredType(): void - { - $this->getUnzerObject()->setKey(TestEnvironmentService::getLegacyTestPrivateKey()); - $sepa = new SepaDirectDebitSecured('DE89370400440532013000'); - $this->unzer->createPaymentType($sepa); - $customer = $this->getMaximumCustomer()->setShippingAddress($this->getBillingAddress()); - $basket = $this->createBasket(); - $payout = $sepa->payout(100.0, 'EUR', self::RETURN_URL, $customer, null, null, $basket); - $this->assertTransactionResourceHasBeenCreated($payout); - - $payment = $payout->getPayment(); - $this->assertInstanceOf(Payment::class, $payment); - $this->assertNotEmpty($payment->getId()); - $this->assertEquals(self::RETURN_URL, $payout->getReturnUrl()); - $this->assertAmounts($payment, 0, 0, -100, 0); - } - /** * Verify Payout transaction is fetched with Payment resource. * diff --git a/test/integration/TransactionTypes/ShipmentTest.php b/test/integration/TransactionTypes/ShipmentTest.php deleted file mode 100644 index b5cea7b36..000000000 --- a/test/integration/TransactionTypes/ShipmentTest.php +++ /dev/null @@ -1,111 +0,0 @@ -getUnzerObject(TestEnvironmentService::getLegacyTestPrivateKey()); - } - - /** - * Verify shipment transaction can be called. - * - * @test - */ - public function shipmentShouldBeCreatableAndFetchable(): void - { - $ivg = new InvoiceSecured(); - $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - - $basket = $this->createBasket(); - $charge = $this->unzer->charge(100.0, 'EUR', $ivg, self::RETURN_URL, $customer, null, null, $basket); - $this->assertNotNull($charge->getId()); - $this->assertNotNull($charge); - - $shipment = $this->unzer->ship($charge->getPayment(), 'i'. self::generateRandomId(), 'i'. self::generateRandomId()); - $this->assertNotNull($shipment->getId()); - $this->assertNotNull($shipment); - - $fetchedShipment = $this->unzer->fetchShipment($shipment->getPayment()->getId(), $shipment->getId()); - $this->assertNotEmpty($fetchedShipment); - $this->assertEquals($shipment->expose(), $fetchedShipment->expose()); - } - - /** - * Verify shipment transaction can be called on the payment object. - * - * @test - */ - public function shipmentCanBeCalledOnThePaymentObject(): void - { - $invoiceSecured = new InvoiceSecured(); - $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - $basket = $this->createBasket(); - $charge = $this->unzer->charge(100.0, 'EUR', $invoiceSecured, self::RETURN_URL, $customer, null, null, $basket); - - $payment = $charge->getPayment(); - $shipment = $payment->ship('i'. self::generateRandomId(), 'o'. self::generateRandomId()); - $this->assertNotNull($shipment); - $this->assertNotEmpty($shipment->getId()); - $this->assertNotEmpty($shipment->getUniqueId()); - $this->assertNotEmpty($shipment->getShortId()); - - $traceId = $shipment->getTraceId(); - $this->assertNotEmpty($traceId); - $this->assertSame($traceId, $shipment->getPayment()->getTraceId()); - - $fetchedShipment = $this->unzer->fetchShipment($shipment->getPayment()->getId(), $shipment->getId()); - $this->assertNotEmpty($fetchedShipment); - $this->assertEquals($shipment->expose(), $fetchedShipment->expose()); - } - - /** - * Verify shipment can be performed with payment object. - * - * @test - */ - public function shipmentShouldBePossibleWithPaymentObject(): void - { - $invoiceSecured = new InvoiceSecured(); - $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - $basket = $this->createBasket(); - $charge = $this->unzer->charge(100.0, 'EUR', $invoiceSecured, self::RETURN_URL, $customer, null, null, $basket); - - $payment = $charge->getPayment(); - $shipment = $this->unzer->ship($payment, 'i'. self::generateRandomId(), 'o'. self::generateRandomId()); - $this->assertNotNull($shipment->getId()); - $this->assertNotNull($shipment); - } - - /** - * Verify transaction status. - * - * @test - */ - public function shipmentStatusIsSetCorrectly(): void - { - $invoiceSecured = new InvoiceSecured(); - $customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress()); - $basket = $this->createBasket(); - $charge = $this->unzer->charge(100.0, 'EUR', $invoiceSecured, self::RETURN_URL, $customer, null, null, $basket); - - $payment = $charge->getPayment(); - $shipment = $this->unzer->ship($payment, 'i'. self::generateRandomId(), 'o'. self::generateRandomId()); - $this->assertSuccess($shipment); - } -} diff --git a/test/unit/Resources/AbstractUnzerResourceTest.php b/test/unit/Resources/AbstractUnzerResourceTest.php index 2212a5c1f..9f30192bb 100644 --- a/test/unit/Resources/AbstractUnzerResourceTest.php +++ b/test/unit/Resources/AbstractUnzerResourceTest.php @@ -17,7 +17,6 @@ use UnzerSDK\Constants\CompanyRegistrationTypes; use UnzerSDK\Constants\Salutations; use UnzerSDK\Constants\TransactionTypes; -use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\PaymentTypes\Applepay; use UnzerSDK\Unzer; use UnzerSDK\Resources\AbstractUnzerResource; @@ -32,12 +31,9 @@ use UnzerSDK\Resources\PaymentTypes\Alipay; use UnzerSDK\Resources\PaymentTypes\Card; use UnzerSDK\Resources\PaymentTypes\EPS; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; use UnzerSDK\Resources\PaymentTypes\Ideal; -use UnzerSDK\Resources\PaymentTypes\Invoice; use UnzerSDK\Resources\PaymentTypes\Paypage; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\SepaDirectDebitSecured; use UnzerSDK\Resources\Recurring; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; @@ -173,27 +169,6 @@ public function fetchPaymentContainsNoTypeNameInUri(AbstractUnzerResource $resou $this->assertEquals($resourcePath, $resource->getUri(false, HttpAdapterInterface::REQUEST_GET)); } - /** - * Verify that installment plans use the correct path for fetching. Special case, fetching Instalmentplans contains - * Installment-secured as parent resource that should appear in resource path. - * - * @test - */ - public function fetchInstalmentPlansShouldUseUriWithTypeName() - { - $unzerMock = $this->getMockBuilder(Unzer::class)->disableOriginalConstructor()->setMethods(['getUri'])->getMock(); - $unzerMock->method('getUri')->willReturn('parent/resource/path/'); - - $installmentSecured = (new InstallmentSecured())->setParentResource($unzerMock); - $instalmentPlans = (new InstalmentPlans(119.0, 'EUR', 4.99)) - ->setParentResource($installmentSecured); - - $this->assertEquals( - 'parent/resource/path/types/installment-secured/plans?amount=119¤cy=EUR&effectiveInterest=4.99', - $instalmentPlans->getUri(false, HttpAdapterInterface::REQUEST_GET) - ); - } - /** * Verify getUri with appendId == true will append the externalId if it is returned and the id is not set. * @@ -433,8 +408,6 @@ public function uriDataProvider(): array 'Alipay' => [new Alipay(), 'parent/resource/path/types/alipay'], 'ApplePay' => [new Applepay('EC_v1', 'data', 'sig', null), 'parent/resource/path/types/applepay'], 'SepaDirectDebit' => [new SepaDirectDebit(''), 'parent/resource/path/types/sepa-direct-debit'], - 'SepaDirectDebitSecured' => [new SepaDirectDebitSecured(''), 'parent/resource/path/types/sepa-direct-debit-secured'], - 'Invoice' => [new Invoice(), 'parent/resource/path/types/invoice'], 'Cancellation' => [new Cancellation(), 'parent/resource/path/cancels'], 'Authorization' => [new Authorization(), 'parent/resource/path/authorize'], 'Shipment' => [new Shipment(), 'parent/resource/path/shipments'], @@ -447,7 +420,6 @@ public function uriDataProvider(): array 'Payout' => [new Payout(), 'parent/resource/path/payouts'], 'PayPage charge' => [new Paypage(123.4567, 'EUR', 'url'), 'parent/resource/path/paypage/charge'], 'PayPage authorize' => [(new Paypage(123.4567, 'EUR', 'url'))->setAction(TransactionTypes::AUTHORIZATION), 'parent/resource/path/paypage/authorize'], - 'InstallmentSecured' => [new InstallmentSecured(), 'parent/resource/path/types/installment-secured'] ]; } @@ -461,10 +433,7 @@ public function fetchUriDataProvider() 'Card' => [new Card('', '03/30'), 'parent/resource/path/types'], 'EPS' => [new EPS(), 'parent/resource/path/types'], 'Ideal' => [new Ideal(), 'parent/resource/path/types'], - 'InstallmentSecured' => [new InstallmentSecured(), 'parent/resource/path/types'], - 'Invoice' => [new Invoice(), 'parent/resource/path/types'], 'SepaDirectDebit' => [new SepaDirectDebit(''), 'parent/resource/path/types'], - 'SepaDirectDebitSecured' => [new SepaDirectDebitSecured(''), 'parent/resource/path/types'], // Other resources Uris should behave as before. 'Customer' => [new Customer(), 'parent/resource/path/customers'], diff --git a/test/unit/Resources/BasketTest.php b/test/unit/Resources/BasketTest.php index fbf4af9b7..64304aaf5 100755 --- a/test/unit/Resources/BasketTest.php +++ b/test/unit/Resources/BasketTest.php @@ -27,27 +27,18 @@ class BasketTest extends BasePaymentTest public function gettersAndSettersShouldWorkProperly(): void { $basket = new Basket(); - $this->assertEquals(0, $basket->getAmountTotalGross()); - $this->assertEquals(0, $basket->getAmountTotalDiscount()); - $this->assertEquals(0, $basket->getAmountTotalVat()); $this->assertEquals(0, $basket->getTotalValueGross()); $this->assertEquals('EUR', $basket->getCurrencyCode()); - $this->assertEquals('', $basket->getNote()); + $this->assertNull($basket->getNote()); $this->assertEquals('', $basket->getOrderId()); $this->assertIsEmptyArray($basket->getBasketItems()); $this->assertNull($basket->getBasketItemByIndex(1)); - $basket->setAmountTotalGross(12.34); $basket->setTotalValueGross(99.99); - $basket->setAmountTotalDiscount(34.56); - $basket->setAmountTotalVat(45.67); $basket->setCurrencyCode('USD'); $basket->setNote('This is something I have to remember!'); $basket->setOrderId('myOrderId'); - $this->assertEquals(12.34, $basket->getAmountTotalGross()); $this->assertEquals(99.99, $basket->getTotalValueGross()); - $this->assertEquals(34.56, $basket->getAmountTotalDiscount()); - $this->assertEquals(45.67, $basket->getAmountTotalVat()); $this->assertEquals('USD', $basket->getCurrencyCode()); $this->assertEquals('This is something I have to remember!', $basket->getNote()); $this->assertEquals('myOrderId', $basket->getOrderId()); @@ -138,7 +129,7 @@ public function referenceIdShouldBeAutomaticallySetToTheArrayIndexIfItIsNotSet() $basketItem4 = new BasketItem(); $this->assertNull($basketItem4->getBasketItemReferenceId()); - $basket2 = new Basket('myOrderId', 123.0, 'EUR', [$basketItem3, $basketItem4]); + $basket2 = new Basket('myOrderId', 0.0, 'EUR', [$basketItem3, $basketItem4]); $this->assertSame($basket2->getBasketItemByIndex(0), $basketItem3); $this->assertSame($basket2->getBasketItemByIndex(1), $basketItem4); $this->assertEquals('0', $basketItem3->getBasketItemReferenceId()); @@ -167,14 +158,10 @@ public function getApiVersionShouldReturnExpectedVersion(Basket $basket, $expect */ public function getApiVersionShouldReturnExpectedVersionDP(): array { - $v1Basket = (new Basket())->setAmountTotalGross(100); $v2Basket = (new Basket())->setTotalValueGross(100); - $mixedBasket = (new Basket())->setAmountTotalGross(100)->setTotalValueGross(100); return [ 'empty basket ' => [new Basket(), Unzer::API_VERSION], - 'minimum v1 basket ' => [$v1Basket, Unzer::API_VERSION], 'minimum v2 basket ' => [$v2Basket, BasePaymentTest::API_VERSION_2], - 'mixed v1/v2 basket ' => [$mixedBasket, BasePaymentTest::API_VERSION_2], ]; } diff --git a/test/unit/Resources/EmbeddedResources/BasketItemTest.php b/test/unit/Resources/EmbeddedResources/BasketItemTest.php index bf5b3b118..a37cb4807 100755 --- a/test/unit/Resources/EmbeddedResources/BasketItemTest.php +++ b/test/unit/Resources/EmbeddedResources/BasketItemTest.php @@ -25,13 +25,8 @@ public function settersAndGettersShouldWork(): void { $basketItem = new BasketItem(); $this->assertEquals(1, $basketItem->getQuantity()); - $this->assertEquals(0, $basketItem->getAmountDiscount()); - $this->assertEquals(0, $basketItem->getAmountGross()); $this->assertEquals(0, $basketItem->getAmountPerUnitGross()); $this->assertEquals(0, $basketItem->getAmountDiscountPerUnitGross()); - $this->assertEquals(0, $basketItem->getAmountPerUnit()); - $this->assertEquals(0, $basketItem->getAmountNet()); - $this->assertEquals(0, $basketItem->getAmountVat()); $this->assertEquals(0, $basketItem->getVat()); $this->assertEquals('', $basketItem->getBasketItemReferenceId()); $this->assertEquals('', $basketItem->getUnit()); @@ -40,11 +35,6 @@ public function settersAndGettersShouldWork(): void $this->assertNull($basketItem->getImageUrl()); $basketItem->setQuantity(2); - $basketItem->setAmountDiscount(9876); - $basketItem->setAmountGross(8765); - $basketItem->setAmountPerUnit(7654); - $basketItem->setAmountNet(6543); - $basketItem->setAmountVat(5432); $basketItem->setVat(6543); $basketItem->setAmountPerUnitGross(5432); $basketItem->setAmountDiscountPerUnitGross(4321); @@ -56,11 +46,6 @@ public function settersAndGettersShouldWork(): void $basketItem->setType('myType'); $this->assertEquals(2, $basketItem->getQuantity()); - $this->assertEquals(9876, $basketItem->getAmountDiscount()); - $this->assertEquals(8765, $basketItem->getAmountGross()); - $this->assertEquals(7654, $basketItem->getAmountPerUnit()); - $this->assertEquals(6543, $basketItem->getAmountNet()); - $this->assertEquals(5432, $basketItem->getAmountVat()); $this->assertEquals(6543, $basketItem->getVat()); $this->assertEquals(5432, $basketItem->getAmountPerUnitGross()); $this->assertEquals(4321, $basketItem->getAmountDiscountPerUnitGross()); diff --git a/test/unit/Resources/InstalmentPlanTest.php b/test/unit/Resources/InstalmentPlanTest.php deleted file mode 100644 index a795539af..000000000 --- a/test/unit/Resources/InstalmentPlanTest.php +++ /dev/null @@ -1,121 +0,0 @@ -assertEquals("plans?amount={$amount}¤cy={$currency}&effectiveInterest={$effectiveInterest}&orderDate=2019-11-13", $plans->getResourcePath()); - } - - /** - * Verify getters and setters. - * - * @test - */ - public function gettersAndSettersShouldWorkAsExpected(): void - { - // when - $instalmentPlans = new InstalmentPlans(1.234, 'EUR', 23.45); - - // then - $this->assertEquals(1.234, $instalmentPlans->getAmount()); - $this->assertEquals('EUR', $instalmentPlans->getCurrency()); - $this->assertEquals(23.45, $instalmentPlans->getEffectiveInterest()); - $this->assertNull($instalmentPlans->getOrderDate()); - - // when - $instalmentPlans->setAmount(2.345) - ->setCurrency('USD') - ->setEffectiveInterest(34.56) - ->setOrderDate($this->getTodaysDateString()); - - // then - $this->assertEquals(2.345, $instalmentPlans->getAmount()); - $this->assertEquals('USD', $instalmentPlans->getCurrency()); - $this->assertEquals(34.56, $instalmentPlans->getEffectiveInterest()); - $this->assertEquals($this->getTodaysDateString(), $instalmentPlans->getOrderDate()); - - // when - $instalmentPlans->setOrderDate($this->getYesterdaysTimestamp()); - - // then - $this->assertEquals($this->getYesterdaysTimestamp()->format('Y-m-d'), $instalmentPlans->getOrderDate()); - - // when - $instalmentPlans->setOrderDate(null); - - // then - $this->assertNull($instalmentPlans->getOrderDate()); - } - - /** - * Verify plans can be retrieved. - * - * @test - */ - public function plansShouldBeRetrievable(): void - { - // when - $instalmentPlans = new InstalmentPlans(1.234, 'EUR', 23.45); - - // then - $this->assertEquals([], $instalmentPlans->getPlans()); - - // when - $plans = [(object)['orderDate' => 'plan 1'], (object)['orderDate' => 'plan 2']]; - $instalmentPlans->handleResponse((object)['entity' => (object)$plans]); - - // then - $plans = $instalmentPlans->getPlans(); - $this->assertCount(2, $plans); - - /** @var InstalmentPlan $plan1 */ - /** @var InstalmentPlan $plan2 */ - [$plan1, $plan2] = $plans; - $this->assertEquals('plan 1', $plan1->getOrderDate()); - $this->assertEquals('plan 2', $plan2->getOrderDate()); - } - - // - - /** - * @return array - */ - public function verifyQueryStringDP(): array - { - return [ - [100, 'EUR', 4.99], - [123.45, 'USD', 1.23] - ]; - } - - // -} diff --git a/test/unit/Resources/KeypairTest.php b/test/unit/Resources/KeypairTest.php index 0abba0609..2cb701da0 100755 --- a/test/unit/Resources/KeypairTest.php +++ b/test/unit/Resources/KeypairTest.php @@ -51,7 +51,7 @@ public function aKeypairShouldBeUpdatedThroughResponseHandling(): void { // when $keypair = new Keypair(); - $paymentTypes = ['przelewy24', 'ideal', 'paypal', 'prepayment', 'invoice', 'sepa-direct-debit-secured', 'card', 'sofort', 'invoice-secured', 'sepa-direct-debit', 'giropay']; + $paymentTypes = ['przelewy24', 'ideal', 'paypal', 'prepayment', 'invoice', 'sepa-direct-debit-secured', 'card', 'invoice-secured', 'sepa-direct-debit']; $testResponse = (object)[ 'publicKey' => 's-pub-1234', 'privateKey' => 's-priv-4321', diff --git a/test/unit/Resources/PaymentTest.php b/test/unit/Resources/PaymentTest.php index 5197acb88..d1342c046 100755 --- a/test/unit/Resources/PaymentTest.php +++ b/test/unit/Resources/PaymentTest.php @@ -21,8 +21,8 @@ use UnzerSDK\Resources\EmbeddedResources\Amount; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\Payment; +use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\Paypage; -use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; @@ -426,7 +426,7 @@ public function setPaymentTypeShouldDoNothingIfThePaymentTypeIsEmpty(): void { $unzerObj = new Unzer('s-priv-123'); $payment = (new Payment())->setParentResource($unzerObj); - $paymentType = (new Sofort())->setId('123'); + $paymentType = (new Paypal())->setId('123'); $payment->setPaymentType($paymentType); $this->assertSame($paymentType, $payment->getPaymentType()); @@ -467,7 +467,7 @@ public function setPaymentTypeShouldFetchResourceIfItIsPassedAsIdString(): void public function setPaymentTypeShouldCreateResourceIfItIsPassedAsObjectWithoutId(): void { $payment = (new Payment())->setId('myPaymentId'); - $paymentType = new Sofort(); + $paymentType = new Paypal(); $resourceServiceMock = $this->getMockBuilder(ResourceService::class) ->disableOriginalConstructor()->setMethods(['createPaymentType'])->getMock(); @@ -531,72 +531,6 @@ public function getCancellationsShouldCollectAllCancellationsOfCorrespondingTran $this->assertEquals($expectedCancellations, $payment->getCancellations()); } - /** - * Verify getCancellation calls getCancellations and returns null if cancellation does not exist. - * - * @deprecated To be removed with Payment::getCancellation() - * - * @test - */ - public function getCancellationShouldCallGetCancellationsAndReturnNullIfNoCancellationExists(): void - { - $paymentMock = $this->getMockBuilder(Payment::class)->setMethods(['getCancellations'])->getMock(); - $paymentMock->expects($this->once())->method('getCancellations')->willReturn([]); - - /** @var Payment $paymentMock */ - $this->assertNull($paymentMock->getCancellation('123')); - } - - /** - * Verify getCancellation returns cancellation if it exists. - * - * @deprecated To be removed with Payment::getCancellation() - * - * @test - */ - public function getCancellationShouldReturnCancellationIfItExists(): void - { - $cancellation1 = (new Cancellation())->setId('cancellation1'); - $cancellation2 = (new Cancellation())->setId('cancellation2'); - $cancellation3 = (new Cancellation())->setId('cancellation3'); - $cancellations = [$cancellation1, $cancellation2, $cancellation3]; - - $paymentMock = $this->getMockBuilder(Payment::class)->setMethods(['getCancellations'])->getMock(); - $paymentMock->expects($this->once())->method('getCancellations')->willReturn($cancellations); - - /** @var Payment $paymentMock */ - $this->assertSame($cancellation2, $paymentMock->getCancellation('cancellation2', true)); - } - - /** - * Verify getCancellation fetches cancellation if it exists and lazy loading is false. - * - * @deprecated To be removed with Payment::getCancellation() - * - * @test - */ - public function getCancellationShouldReturnCancellationIfItExistsAndFetchItIfNotLazy(): void - { - $cancellation = (new Cancellation())->setId('cancellation123'); - - $paymentMock = $this->getMockBuilder(Payment::class)->setMethods(['getCancellations'])->getMock(); - $paymentMock->expects($this->exactly(2))->method('getCancellations')->willReturn([$cancellation]); - - $resourceServiceMock = $this->getMockBuilder(ResourceService::class) - ->disableOriginalConstructor()->setMethods(['getResource'])->getMock(); - /** @noinspection PhpParamsInspection */ - $resourceServiceMock->expects($this->once())->method('getResource')->with($cancellation); - - /** @var ResourceService $resourceServiceMock */ - $unzerObj = (new Unzer('s-priv-123'))->setResourceService($resourceServiceMock); - - /** @var Payment $paymentMock */ - $paymentMock->setParentResource($unzerObj); - - $this->assertSame($cancellation, $paymentMock->getCancellation('cancellation123')); - $this->assertNull($paymentMock->getCancellation('cancellation1234')); - } - /** * Verify Shipments are handled properly. * @@ -1411,30 +1345,6 @@ public function handleResponseShouldAddPayoutFromResponseIfItDoesNotExists(): vo // - /** - * Verify charge will call chargePayment on Unzer object. - * - * @test - */ - public function chargeMethodShouldPropagateToUnzerChargePaymentMethod(): void - { - $payment = new Payment(); - - /** @var Unzer|MockObject $unzerMock */ - $unzerMock = $this->getMockBuilder(Unzer::class)->disableOriginalConstructor()->setMethods(['chargePayment'])->getMock(); - $unzerMock->expects($this->exactly(3))->method('chargePayment') - ->withConsecutive( - [$payment, null, null], - [$payment, 1.1, null], - [$payment, 2.2] - )->willReturn(new Charge()); - $payment->setParentResource($unzerMock); - - $payment->charge(); - $payment->charge(1.1); - $payment->charge(2.2); - } - /** * Verify ship will call ship method on Unzer object. * diff --git a/test/unit/Resources/PaymentTypes/InstallmentSecuredTest.php b/test/unit/Resources/PaymentTypes/InstallmentSecuredTest.php deleted file mode 100644 index bf5741cf3..000000000 --- a/test/unit/Resources/PaymentTypes/InstallmentSecuredTest.php +++ /dev/null @@ -1,191 +0,0 @@ -assertEmpty($ins->getTransactionParams()); - $this->assertNull($ins->getAccountHolder()); - $this->assertNull($ins->getIban()); - $this->assertNull($ins->getBic()); - $this->assertNull($ins->getOrderDate()); - $this->assertNull($ins->getNumberOfRates()); - $this->assertNull($ins->getDayOfPurchase()); - $this->assertNull($ins->getTotalPurchaseAmount()); - $this->assertNull($ins->getTotalInterestAmount()); - $this->assertNull($ins->getTotalAmount()); - $this->assertNull($ins->getEffectiveInterestRate()); - $this->assertNull($ins->getNominalInterestRate()); - $this->assertNull($ins->getFeeFirstRate()); - $this->assertNull($ins->getFeePerRate()); - $this->assertNull($ins->getMonthlyRate()); - $this->assertNull($ins->getLastRate()); - $this->assertEmpty($ins->getInvoiceDate()); - $this->assertEmpty($ins->getInvoiceDueDate()); - - $ins->setAccountHolder(null) - ->setIban(null) - ->setBic(null) - ->setOrderDate(null) - ->setNumberOfRates(null) - ->setDayOfPurchase(null) - ->setTotalPurchaseAmount(null) - ->setTotalInterestAmount(null) - ->setTotalAmount(null) - ->setEffectiveInterestRate(null) - ->setNominalInterestRate(null) - ->setFeeFirstRate(null) - ->setFeePerRate(null) - ->setMonthlyRate(null) - ->setLastRate(null) - ->setInvoiceDate(null) - ->setInvoiceDueDate(null); - - $this->assertEmpty($ins->getTransactionParams()); - $this->assertNull($ins->getAccountHolder()); - $this->assertNull($ins->getIban()); - $this->assertNull($ins->getBic()); - $this->assertNull($ins->getOrderDate()); - $this->assertNull($ins->getNumberOfRates()); - $this->assertNull($ins->getDayOfPurchase()); - $this->assertNull($ins->getTotalPurchaseAmount()); - $this->assertNull($ins->getTotalInterestAmount()); - $this->assertNull($ins->getTotalAmount()); - $this->assertNull($ins->getEffectiveInterestRate()); - $this->assertNull($ins->getNominalInterestRate()); - $this->assertNull($ins->getFeeFirstRate()); - $this->assertNull($ins->getFeePerRate()); - $this->assertNull($ins->getMonthlyRate()); - $this->assertNull($ins->getLastRate()); - $this->assertEmpty($ins->getInvoiceDate()); - $this->assertEmpty($ins->getInvoiceDueDate()); - - $ins->setAccountHolder('My Name') - ->setIban('my IBAN') - ->setBic('my BIC') - ->setOrderDate($this->getYesterdaysTimestamp()->format('Y-m-d')) - ->setNumberOfRates(15) - ->setDayOfPurchase($this->getTodaysDateString()) - ->setTotalPurchaseAmount(119.0) - ->setTotalInterestAmount(0.96) - ->setTotalAmount(119.96) - ->setEffectiveInterestRate(4.99) - ->setNominalInterestRate(4.92) - ->setFeeFirstRate(0) - ->setFeePerRate(0) - ->setMonthlyRate(39.99) - ->setLastRate(39.98) - ->setInvoiceDate($this->getTomorrowsTimestamp()->format('Y-m-d')) - ->setInvoiceDueDate($this->getNextYearsTimestamp()->format('Y-m-d')); - - $this->assertEquals('My Name', $ins->getAccountHolder()); - $this->assertEquals('my IBAN', $ins->getIban()); - $this->assertEquals('my BIC', $ins->getBic()); - $this->assertEquals($this->getYesterdaysTimestamp()->format('Y-m-d'), $ins->getOrderDate()); - $this->assertEquals(15, $ins->getNumberOfRates()); - $this->assertEquals($this->getTodaysDateString(), $ins->getDayOfPurchase()); - $this->assertEquals(119.0, $ins->getTotalPurchaseAmount()); - $this->assertEquals(0.96, $ins->getTotalInterestAmount()); - $this->assertEquals(119.96, $ins->getTotalAmount()); - $this->assertEquals(4.99, $ins->getEffectiveInterestRate()); - $this->assertEquals(4.92, $ins->getNominalInterestRate()); - $this->assertEquals(0, $ins->getFeeFirstRate()); - $this->assertEquals(0, $ins->getFeePerRate()); - $this->assertEquals(39.99, $ins->getMonthlyRate()); - $this->assertEquals(39.98, $ins->getLastRate()); - $this->assertEquals($this->getTomorrowsTimestamp()->format('Y-m-d'), $ins->getInvoiceDate()); - $this->assertEquals($this->getNextYearsTimestamp()->format('Y-m-d'), $ins->getInvoiceDueDate()); - $this->assertEquals(['effectiveInterestRate' => $ins->getEffectiveInterestRate()], $ins->getTransactionParams()); - - // test dates with DateTime objects - $today = new DateTime(); - $ins->setOrderDate($today->add(new DateInterval('P1D'))) - ->setDayOfPurchase($today->add(new DateInterval('P1D'))) - ->setInvoiceDate($today->add(new DateInterval('P1D'))) - ->setInvoiceDueDate($today->add(new DateInterval('P1D'))); - - $today = new DateTime(); - $this->assertEquals($today->add(new DateInterval('P1D'))->format('Y-m-d'), $ins->getOrderDate()); - $this->assertEquals($today->add(new DateInterval('P1D'))->format('Y-m-d'), $ins->getDayOfPurchase()); - $this->assertEquals($today->add(new DateInterval('P1D'))->format('Y-m-d'), $ins->getInvoiceDate()); - $this->assertEquals($today->add(new DateInterval('P1D'))->format('Y-m-d'), $ins->getInvoiceDueDate()); - - // test dates with null - $ins->setOrderDate(null) - ->setDayOfPurchase(null) - ->setInvoiceDate(null) - ->setInvoiceDueDate(null); - - $this->assertNull($ins->getOrderDate()); - $this->assertNull($ins->getDayOfPurchase()); - $this->assertNull($ins->getInvoiceDate()); - $this->assertNull($ins->getInvoiceDueDate()); - } - - /** - * Verify handle response is called with the exposed data of the selected instalment plan. - * - * @test - */ - public function selectedInstalmentPlanDataIsUsedToUpdateInstalmentPlanInformation(): void - { - /** @var InstallmentSecured|MockObject $Mock */ - $Mock = $this->getMockBuilder(InstallmentSecured::class)->setMethods(['handleResponse'])->getMock(); - - /** @var InstalmentPlan|MockObject $instalmentPlanMock */ - $instalmentPlanMock = $this->getMockBuilder(InstalmentPlan::class)->setMethods(['expose'])->getMock(); - - $exposedObject = (object)['data' => 'I am exposed']; - - $instalmentPlanMock->expects($this->once())->method('expose')->willReturn($exposedObject); - /** @noinspection PhpParamsInspection */ - $Mock->expects($this->once())->method('handleResponse')->with($exposedObject); - - $Mock->selectInstalmentPlan($instalmentPlanMock); - } - - /** - * Verify instalment plan fetch can update instalment plan properties. - * - * @test - */ - public function instalmentPlanPropertiesShouldBeUpdateable(): void - { - $plan = new InstalmentPlan(); - $this->assertEmpty($plan->getInstallmentRates()); - - $rates = [ - (object)['title' => 'first Rate'], - (object)['title' => 'second Rate'], - (object)['title' => 'third Rate'] - ]; - $planData = (object)['installmentRates' => $rates]; - - $plan->handleResponse($planData); - $this->assertEquals($rates, $plan->getInstallmentRates()); - } -} diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index 10083bca1..4bf24a542 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -18,7 +18,7 @@ use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\Card; -use UnzerSDK\Resources\PaymentTypes\Giropay; +use UnzerSDK\Resources\PaymentTypes\Ideal; use UnzerSDK\Resources\PaymentTypes\Paypage; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; use UnzerSDK\Services\ResourceService; @@ -129,8 +129,8 @@ public function getterAndSetterWorkAsExpected(): void // other $this->assertEquals([SepaDirectDebit::getResourceName()], $paypage->getExcludeTypes()); - $paypage->setExcludeTypes([Card::getResourceName(), Giropay::getResourceName()]); - $this->assertEquals([Card::getResourceName(), Giropay::getResourceName()], $paypage->getExcludeTypes()); + $paypage->setExcludeTypes([Card::getResourceName(), Ideal::getResourceName()]); + $this->assertEquals([Card::getResourceName(), Ideal::getResourceName()], $paypage->getExcludeTypes()); $this->assertTrue($paypage->isCard3ds()); // SET test values 2 diff --git a/test/unit/Resources/PaymentTypes/SepaDirectDebitSecuredTest.php b/test/unit/Resources/PaymentTypes/SepaDirectDebitSecuredTest.php deleted file mode 100644 index 3d195fd10..000000000 --- a/test/unit/Resources/PaymentTypes/SepaDirectDebitSecuredTest.php +++ /dev/null @@ -1,51 +0,0 @@ -assertNull($sdd->getIban()); - } - - /** - * Verify setter and getter work. - * - * @test - */ - public function getterAndSetterWorkAsExpected(): void - { - $sdd = new SepaDirectDebitSecured('DE89370400440532013000'); - $this->assertEquals('DE89370400440532013000', $sdd->getIban()); - - $sdd->setIban('DE89370400440532013012'); - $this->assertEquals('DE89370400440532013012', $sdd->getIban()); - - $this->assertNull($sdd->getBic()); - $sdd->setBic('RABONL2U'); - $this->assertEquals('RABONL2U', $sdd->getBic()); - - $this->assertNull($sdd->getHolder()); - $sdd->setHolder('Max Mustermann'); - $this->assertEquals('Max Mustermann', $sdd->getHolder()); - } -} diff --git a/test/unit/Resources/PaymentTypes/SofortTest.php b/test/unit/Resources/PaymentTypes/SofortTest.php deleted file mode 100644 index 6006bf79c..000000000 --- a/test/unit/Resources/PaymentTypes/SofortTest.php +++ /dev/null @@ -1,33 +0,0 @@ -assertNull($sofort->getId()); - - $jsonResponse = JsonProvider::getJsonFromFile('sofortResponseWithIban.json'); - $sofort->handleResponse((object)json_decode($jsonResponse, false)); - - $this->assertEquals('s-sft-123', $sofort->getId()); - $this->assertEquals('DE-IBAN', $sofort->getIban()); - $this->assertEquals('test-bin', $sofort->getBic()); - $this->assertEquals('holder', $sofort->getHolder()); - } -} diff --git a/test/unit/Resources/TransactionTypes/AuthorizationTest.php b/test/unit/Resources/TransactionTypes/AuthorizationTest.php index 89ef8233b..6bece491a 100755 --- a/test/unit/Resources/TransactionTypes/AuthorizationTest.php +++ b/test/unit/Resources/TransactionTypes/AuthorizationTest.php @@ -14,7 +14,7 @@ use UnzerSDK\Unzer; use UnzerSDK\Resources\CustomerFactory; use UnzerSDK\Resources\Payment; -use UnzerSDK\Resources\PaymentTypes\Sofort; +use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; @@ -118,7 +118,7 @@ public function getLinkedResourcesShouldThrowExceptionWhenThePaymentTypeIsNotSet public function getLinkedResourceShouldReturnResourcesBelongingToAuthorization(): void { $unzerObj = new Unzer('s-priv-123345'); - $paymentType = (new Sofort())->setId('123'); + $paymentType = (new Paypal())->setId('123'); $customer = CustomerFactory::createCustomer('Max', 'Mustermann')->setId('123'); $payment = new Payment(); $payment->setParentResource($unzerObj)->setPaymentType($paymentType)->setCustomer($customer); @@ -184,18 +184,19 @@ public function chargeShouldCallChargeAuthorizationOnUnzerObject(): void { $unzerMock = $this->getMockBuilder(Unzer::class) ->disableOriginalConstructor() - ->setMethods(['chargeAuthorization']) + ->setMethods(['performChargeOnPayment']) ->getMock(); /** @var Unzer $unzerMock */ $payment = (new Payment())->setParentResource($unzerMock)->setId('myPayment'); $unzerMock->expects($this->exactly(2)) - ->method('chargeAuthorization')->willReturn(new Charge()) + ->method('performChargeOnPayment') + ->willReturn(new Charge()) ->withConsecutive( - [$this->identicalTo($payment), $this->isNull()], - [$this->identicalTo($payment), 321.9] + [$this->identicalTo($payment), $this->callback(static fn(Charge $c) => $c->getAmount() === null)], + [$this->identicalTo($payment), $this->callback(static fn(Charge $c) => $c->getAmount() === 321.9)] ); - $authorization = new Authorization(); + $authorization = new Authorization(); $authorization->setPayment($payment); $authorization->charge(); $authorization->charge(321.9); diff --git a/test/unit/Resources/TransactionTypes/CancellationTest.php b/test/unit/Resources/TransactionTypes/CancellationTest.php index b8023c0d6..e97fc78c3 100755 --- a/test/unit/Resources/TransactionTypes/CancellationTest.php +++ b/test/unit/Resources/TransactionTypes/CancellationTest.php @@ -14,7 +14,6 @@ use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Unzer; use UnzerSDK\Resources\Payment; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\test\BasePaymentTest; use PHPUnit\Framework\MockObject\MockObject; @@ -60,20 +59,4 @@ public function gettersAndSettersShouldWorkProperly(): void $this->assertNull($cancellation->getReasonCode()); } - /** - * Verify expose will translate amount to amountGross if payment type is Installment Secured. - * - * @test - */ - public function exposeWillReplaceAmountWithAmountGross(): void - { - /** @var Cancellation|MockObject $cancelMock */ - $cancelMock = $this->getMockBuilder(Cancellation::class)->setMethods(['getLinkedResources'])->getMock(); - $cancelMock->setAmount('123.4'); - $this->assertEquals(['amount' => 123.4], $cancelMock->expose()); - - $paymentType = (new InstallmentSecured())->setId('id'); - $cancelMock->setPayment((new Payment(new Unzer('s-priv-1234')))->setPaymentType($paymentType)); - $this->assertEquals(['amountGross' => 123.4], $cancelMock->expose()); - } } diff --git a/test/unit/Resources/TransactionTypes/ChargeTest.php b/test/unit/Resources/TransactionTypes/ChargeTest.php index 39ce511a8..aba45fc72 100755 --- a/test/unit/Resources/TransactionTypes/ChargeTest.php +++ b/test/unit/Resources/TransactionTypes/ChargeTest.php @@ -15,7 +15,7 @@ use UnzerSDK\Unzer; use UnzerSDK\Resources\CustomerFactory; use UnzerSDK\Resources\Payment; -use UnzerSDK\Resources\PaymentTypes\Sofort; +use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BasePaymentTest; @@ -164,7 +164,7 @@ public function getLinkedResourcesShouldThrowExceptionWhenThePaymentTypeIsNotSet public function getLinkedResourceShouldReturnResourcesBelongingToCharge(): void { $unzerObj = new Unzer('s-priv-123345'); - $paymentType = (new Sofort())->setId('123'); + $paymentType = (new Paypal())->setId('123'); $customer = CustomerFactory::createCustomer('Max', 'Mustermann')->setId('123'); $payment = new Payment(); $payment->setParentResource($unzerObj)->setPaymentType($paymentType)->setCustomer($customer); diff --git a/test/unit/Resources/TransactionTypes/ChargebackTest.php b/test/unit/Resources/TransactionTypes/ChargebackTest.php index cee991cd6..a1b077b89 100644 --- a/test/unit/Resources/TransactionTypes/ChargebackTest.php +++ b/test/unit/Resources/TransactionTypes/ChargebackTest.php @@ -11,6 +11,7 @@ namespace Resources\TransactionTypes; +use UnzerSDK\Apis\ApiRequest; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice; use UnzerSDK\Resources\TransactionTypes\Charge; @@ -95,11 +96,13 @@ public function fetchChargebackByIdWithoutChargeId(): void // Mock http service $httpServiceMock = $this->getMockBuilder(HttpService::class) - ->disableOriginalConstructor()->onlyMethods(['send'])->getMock(); + ->disableOriginalConstructor()->onlyMethods(['sendRequest'])->getMock(); $httpServiceMock->expects($this->once()) - ->method('send') - ->with('/payments/s-pay-329982/chargebacks/s-cbk-1') + ->method('sendRequest') + ->with($this->callback(static function (ApiRequest $request) { + return $request->getUri() === '/payments/s-pay-329982/chargebacks/s-cbk-1'; + })) ->willReturn($chargebackJson); // Mock Resource service @@ -142,11 +145,13 @@ public function fetchChargebackById($chargeId, $expectedUri): void // Mock http service $httpServiceMock = $this->getMockBuilder(HttpService::class) - ->disableOriginalConstructor()->onlyMethods(['send'])->getMock(); + ->disableOriginalConstructor()->onlyMethods(['sendRequest'])->getMock(); $httpServiceMock->expects($this->once()) - ->method('send') - ->with($expectedUri) + ->method('sendRequest') + ->with($this->callback(static function (ApiRequest $request) use ($expectedUri) { + return $request->getUri() === $expectedUri; + })) ->willReturn($chargebackJson); // Mock Resource service diff --git a/test/unit/Services/HttpServiceTest.php b/test/unit/Services/HttpServiceTest.php index 816b43fe8..5deb25bee 100755 --- a/test/unit/Services/HttpServiceTest.php +++ b/test/unit/Services/HttpServiceTest.php @@ -13,16 +13,11 @@ use RuntimeException; use UnzerSDK\Adapter\CurlAdapter; -use UnzerSDK\Adapter\HttpAdapterInterface; -use UnzerSDK\Exceptions\UnzerApiException; -use UnzerSDK\Interfaces\DebugHandlerInterface; use UnzerSDK\Services\EnvironmentService; use UnzerSDK\Services\HttpService; use UnzerSDK\test\BasePaymentTest; use UnzerSDK\test\unit\DummyResource; use UnzerSDK\Unzer; -use function array_key_exists; -use const PHP_VERSION; class HttpServiceTest extends BasePaymentTest { @@ -63,95 +58,6 @@ public function environmentServiceShouldBeInjectable(): void $this->assertSame($envService, $httpService->getEnvironmentService()); } - /** - * Verify send will throw exception if resource is null. - * - * @test - */ - public function sendShouldThrowExceptionIfResourceIsNotSet(): void - { - $httpService = new HttpService(); - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Transfer object is empty!'); - $httpService->send(); - } - - /** - * Verify send calls methods to setup and send request. - * - * @test - */ - public function sendShouldInitAndSendRequest(): void - { - $httpServiceMock = $this->getMockBuilder(HttpService::class)->setMethods(['getAdapter'])->getMock(); - - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods( - ['init', 'setUserAgent', 'setHeaders', 'execute', 'getResponseCode', 'close'] - )->getMock(); - - $resource = (new DummyResource())->setParentResource(new Unzer('s-priv-MyTestKey')); - /** @noinspection PhpParamsInspection */ - $adapterMock->expects($this->once())->method('init')->with( - $this->callback( - static function ($url) { - return str_replace(['dev-api', 'stg-api'], 'sbx-api', $url) === 'https://sbx-api.unzer.com/v1/my/uri/123'; - } - ), - '{"dummyResource": "JsonSerialized"}', - 'GET' - ); - /** @noinspection PhpParamsInspection */ - $adapterMock->expects($this->once())->method('setUserAgent')->with('UnzerPHP'); - $headers = [ - 'Authorization' => 'Basic cy1wcml2LU15VGVzdEtleTo=', - 'Content-Type' => 'application/json', - 'SDK-VERSION' => Unzer::SDK_VERSION, - 'SDK-TYPE' => Unzer::SDK_TYPE, - 'PHP-VERSION' => PHP_VERSION - ]; - $adapterMock->expects($this->once())->method('setHeaders')->with($headers); - $adapterMock->expects($this->once())->method('execute')->willReturn('myResponseString'); - $adapterMock->expects($this->once())->method('getResponseCode')->willReturn('399'); - - $httpServiceMock->method('getAdapter')->willReturn($adapterMock); - - /** @var HttpService $httpServiceMock*/ - $response = $httpServiceMock->send('/my/uri/123', $resource); - - $this->assertEquals('myResponseString', $response); - } - - /** - * Verify 'Accept-Language' header only set when a locale is defined in the Unzer object. - * - * @test - * - * @dataProvider languageShouldOnlyBeSetIfSpecificallyDefinedDP - * - * @param $locale - */ - public function languageShouldOnlyBeSetIfSpecificallyDefined($locale): void - { - $httpServiceMock = $this->getMockBuilder(HttpService::class)->setMethods(['getAdapter'])->getMock(); - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods(['setHeaders', 'execute'])->getMock(); - $httpServiceMock->method('getAdapter')->willReturn($adapterMock); - - $resource = (new DummyResource())->setParentResource(new Unzer('s-priv-MyTestKey', $locale)); - - /** @noinspection PhpParamsInspection */ - $adapterMock->expects($this->once())->method('setHeaders')->with( - $this->callback( - static function ($headers) use ($locale) { - return $locale === ($headers['Accept-Language'] ?? null); - } - ) - ); - $adapterMock->method('execute')->willReturn('myResponseString'); - - /** @var HttpService $httpServiceMock*/ - $httpServiceMock->send('/my/uri/123', $resource); - } - /** * Verify 'CLIENTIP' header only set when a clientIp is defined in the Unzer object. * @@ -174,279 +80,8 @@ public function clientIpHeaderShouldBeSetProperly($clientIp, $isHeaderExpected): } } - /** - * Verify debugLog logs to debug handler if debug mode and a handler are set. - * - * @test - */ - public function sendShouldLogDebugMessagesIfDebugModeAndHandlerAreSet(): void - { - $httpServiceMock = $this->getMockBuilder(HttpService::class)->setMethods(['getAdapter'])->getMock(); - - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods(['init', 'setUserAgent', 'setHeaders', 'execute', 'getResponseCode', 'close'])->getMock(); - $adapterMock->method('execute')->willReturn('{"response":"myResponseString"}'); - $adapterMock->method('getResponseCode')->willReturnOnConsecutiveCalls('200', '201'); - $httpServiceMock->method('getAdapter')->willReturn($adapterMock); - - $loggerMock = $this->getMockBuilder(DummyDebugHandler::class)->setMethods(['log'])->getMock(); - $loggerMock->expects($this->exactly(7))->method('log')->withConsecutive( - [ $this->callback( - static function ($string) { - return str_replace(['dev-api', 'stg-api'], 'sbx-api', $string) === '(' . (getmypid()) . ') GET: https://sbx-api.unzer.com/v1/my/uri/123'; - } - ) - ], - [ $this->callback( - static function ($string) { - $matches = []; - preg_match('/^(?:\([\d]*\) Headers: )({.*})/', $string, $matches); - $elements = json_decode($matches[1], true); - return array_key_exists('Authorization', $elements) && array_key_exists('Content-Type', $elements) && - array_key_exists('SDK-TYPE', $elements) && array_key_exists('SDK-VERSION', $elements); - } - ) - ], - ['(' . (getmypid()) . ') Response: (200) {"response":"myResponseString"}'], - [ $this->callback( - static function ($string) { - return str_replace(['dev-api', 'stg-api'], 'sbx-api', $string) === '(' . (getmypid()) . ') POST: https://sbx-api.unzer.com/v1/my/uri/123'; - } - ) - ], - [ $this->callback( - static function ($string) { - $matches = []; - preg_match('/^(?:\([\d]*\) Headers: )({.*})/', $string, $matches); - $elements = json_decode($matches[1], true); - return array_key_exists('Authorization', $elements) && array_key_exists('Content-Type', $elements) && - array_key_exists('SDK-TYPE', $elements) && array_key_exists('SDK-VERSION', $elements); - } - ) - ], - ['(' . (getmypid()) . ') Request: {"dummyResource": "JsonSerialized"}'], - ['(' . (getmypid()) . ') Response: (201) {"response":"myResponseString"}'] - ); - - /** @var DebugHandlerInterface $loggerMock */ - $unzer = (new Unzer('s-priv-MyTestKey'))->setDebugMode(true)->setDebugHandler($loggerMock); - $resource = (new DummyResource())->setParentResource($unzer); - - /** @var HttpService $httpServiceMock*/ - $response = $httpServiceMock->send('/my/uri/123', $resource); - $this->assertEquals('{"response":"myResponseString"}', $response); - - $response = $httpServiceMock->send('/my/uri/123', $resource, HttpAdapterInterface::REQUEST_POST); - $this->assertEquals('{"response":"myResponseString"}', $response); - } - - /** - * Verify handleErrors will throw Exception if response string is null. - * - * @test - */ - public function handleErrorsShouldThrowExceptionIfResponseIsEmpty(): void - { - $httpServiceMock = $this->getMockBuilder(HttpService::class)->setMethods(['getAdapter'])->getMock(); - - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods( - ['init', 'setUserAgent', 'setHeaders', 'execute', 'getResponseCode', 'close'] - )->getMock(); - $adapterMock->method('execute')->willReturn(null); - $httpServiceMock->method('getAdapter')->willReturn($adapterMock); - - $resource = (new DummyResource())->setParentResource(new Unzer('s-priv-MyTestKey')); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionMessage('The Request returned a null response!'); - $this->expectExceptionCode('No error code provided'); - - /** @var HttpService $httpServiceMock*/ - $httpServiceMock->send('/my/uri/123', $resource); - } - - /** - * Verify handleErrors will throw Exception if responseCode is greaterOrEqual to 400 or is not a number. - * - * @test - * - * @dataProvider responseCodeProvider - * - * @param string $responseCode - */ - public function handleErrorsShouldThrowExceptionIfResponseCodeIsGoE400($responseCode): void - { - $httpServiceMock = $this->getMockBuilder(HttpService::class)->setMethods(['getAdapter'])->getMock(); - - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods( - ['init', 'setUserAgent', 'setHeaders', 'execute', 'getResponseCode', 'close'] - )->getMock(); - $adapterMock->method('getResponseCode')->willReturn($responseCode); - $adapterMock->method('execute')->willReturn('{"response" : "myResponseString"}'); - $httpServiceMock->method('getAdapter')->willReturn($adapterMock); - - $resource = (new DummyResource())->setParentResource(new Unzer('s-priv-MyTestKey')); - - $this->expectException(UnzerApiException::class); - $this->expectExceptionMessage('The payment api returned an error!'); - $this->expectExceptionCode('No error code provided'); - - /** @var HttpService $httpServiceMock*/ - $httpServiceMock->send('/my/uri/123', $resource); - } - - /** - * Verify handleErrors will throw Exception if response contains errors field. - * - * @test - */ - public function handleErrorsShouldThrowExceptionIfResponseContainsErrorField(): void - { - $httpServiceMock = $this->getMockBuilder(HttpService::class)->setMethods(['getAdapter'])->getMock(); - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods( - ['init', 'setUserAgent', 'setHeaders', 'execute', 'getResponseCode', 'close'] - )->getMock(); - - $firstResponse = '{"errors": [{}]}'; - $secondResponse = '{"errors": [{"merchantMessage": "This is an error message for the merchant!"}]}'; - $thirdResponse = '{"errors": [{"customerMessage": "This is an error message for the customer!"}]}'; - $fourthResponse = '{"errors": [{"code": "This is the error code!"}]}'; - $fifthResponse = '{"errors": [{"code": "This is the error code!"}], "id": "s-err-1234"}'; - $sixthResponse = '{"errors": [{"code": "This is the error code!"}], "id": "s-rre-1234"}'; - - $adapterMock->method('execute')->willReturnOnConsecutiveCalls($firstResponse, $secondResponse, $thirdResponse, $fourthResponse, $fifthResponse, $sixthResponse); - $httpServiceMock->method('getAdapter')->willReturn($adapterMock); - - $resource = (new DummyResource())->setParentResource(new Unzer('s-priv-MyTestKey')); - - /** @var HttpService $httpServiceMock*/ - try { - $httpServiceMock->send('/my/uri/123', $resource); - $this->assertTrue(false, 'The first exception should have been thrown!'); - } catch (UnzerApiException $e) { - $this->assertEquals('The payment api returned an error!', $e->getMerchantMessage()); - $this->assertEquals('The payment api returned an error!', $e->getClientMessage()); - $this->assertEquals('No error code provided', $e->getCode()); - $this->assertEquals('No error id provided', $e->getErrorId()); - } - - try { - $httpServiceMock->send('/my/uri/123', $resource); - $this->assertTrue(false, 'The second exception should have been thrown!'); - } catch (UnzerApiException $e) { - $this->assertEquals('This is an error message for the merchant!', $e->getMerchantMessage()); - $this->assertEquals('The payment api returned an error!', $e->getClientMessage()); - $this->assertEquals('No error code provided', $e->getCode()); - $this->assertEquals('No error id provided', $e->getErrorId()); - } - - try { - $httpServiceMock->send('/my/uri/123', $resource); - $this->assertTrue(false, 'The third exception should have been thrown!'); - } catch (UnzerApiException $e) { - $this->assertEquals('The payment api returned an error!', $e->getMerchantMessage()); - $this->assertEquals('This is an error message for the customer!', $e->getClientMessage()); - $this->assertEquals('No error code provided', $e->getCode()); - $this->assertEquals('No error id provided', $e->getErrorId()); - } - - try { - $httpServiceMock->send('/my/uri/123', $resource); - $this->assertTrue(false, 'The fourth exception should have been thrown!'); - } catch (UnzerApiException $e) { - $this->assertEquals('The payment api returned an error!', $e->getMerchantMessage()); - $this->assertEquals('The payment api returned an error!', $e->getClientMessage()); - $this->assertEquals('This is the error code!', $e->getCode()); - $this->assertEquals('No error id provided', $e->getErrorId()); - } - - try { - $httpServiceMock->send('/my/uri/123', $resource); - $this->assertTrue(false, 'The fifth exception should have been thrown!'); - } catch (UnzerApiException $e) { - $this->assertEquals('The payment api returned an error!', $e->getMerchantMessage()); - $this->assertEquals('The payment api returned an error!', $e->getClientMessage()); - $this->assertEquals('This is the error code!', $e->getCode()); - $this->assertEquals('s-err-1234', $e->getErrorId()); - } - - try { - $httpServiceMock->send('/my/uri/123', $resource); - $this->assertTrue(false, 'The sixth exception should have been thrown!'); - } catch (UnzerApiException $e) { - $this->assertEquals('The payment api returned an error!', $e->getMerchantMessage()); - $this->assertEquals('The payment api returned an error!', $e->getClientMessage()); - $this->assertEquals('This is the error code!', $e->getCode()); - $this->assertEquals('No error id provided', $e->getErrorId()); - } - } - - /** - * Verify API environment switches accordingly depending on environment variable and keypair. - * - * @test - * - * @dataProvider environmentUrlSwitchesWithEnvironmentVariableDP - * - * @param $environment - * @param $apiUrl - * @param string $key - */ - public function environmentUrlSwitchesWithEnvironmentVariable($environment, $apiUrl, string $key): void - { - $adapterMock = $this->getMockBuilder(CurlAdapter::class)->setMethods(['init', 'setUserAgent', 'setHeaders', 'execute', 'getResponseCode', 'close'])->getMock(); - /** @noinspection PhpParamsInspection */ - $adapterMock->expects($this->once())->method('init')->with($apiUrl, self::anything(), self::anything()); - $resource = (new DummyResource())->setParentResource(new Unzer($key)); - $adapterMock->method('execute')->willReturn('myResponseString'); - $adapterMock->method('getResponseCode')->willReturn('42'); - - $envSrvMock = $this->getMockBuilder(EnvironmentService::class)->setMethods(['getPapiEnvironment'])->getMock(); - $envSrvMock->method('getPapiEnvironment')->willReturn($environment); - - /** - * @var CurlAdapter $adapterMock - * @var EnvironmentService $envSrvMock - */ - $httpService = (new HttpService())->setHttpAdapter($adapterMock)->setEnvironmentService($envSrvMock); - - /** @var HttpService $httpServiceMock*/ - $response = $httpService->send('', $resource); - - $this->assertEquals('myResponseString', $response); - } - // - /** - * Data provider for handleErrorsShouldThrowExceptionIfResponseCodeIsGoE400. - * - * @return array - */ - public function responseCodeProvider(): array - { - return [ - '400' => ['400'], - '401' => ['401'], - '404' => ['404'], - '500' => ['500'], - '600' => ['600'], - '1000' => ['1000'], - 'Response code not a number' => ['myResponseCode'] - ]; - } - - /** - * Returns test data for method public function languageShouldOnlyBeSetIfSpecificallyDefined. - */ - public function languageShouldOnlyBeSetIfSpecificallyDefinedDP(): array - { - return [ - 'de-DE' => ['de-DE'], - 'en-US' => ['en-US'], - 'null' => [null] - ]; - } - /** * Returns test data for method public function languageShouldOnlyBeSetIfSpecificallyDefined. */ @@ -461,31 +96,5 @@ public function clientIpHeaderShouldBeSetProperlyDP(): array ]; } - /** - * @return array - */ - public function environmentUrlSwitchesWithEnvironmentVariableDP(): array - { - $devUrl = 'https://dev-api.unzer.com/v1'; - $stgUrl = 'https://stg-api.unzer.com/v1'; - $sbxUrl = 'https://sbx-api.unzer.com/v1'; - $prodUrl = 'https://api.unzer.com/v1'; - - $prodKey = 'p-priv-MyTestKey'; - $sbxKey = 's-priv-MyTestKey'; - - return [ - 'Dev with production key' => [EnvironmentService::ENV_VAR_VALUE_DEVELOPMENT_ENVIRONMENT, $prodUrl, $prodKey], - 'Prod with production key' => [EnvironmentService::ENV_VAR_VALUE_PROD_ENVIRONMENT, $prodUrl, $prodKey], - 'Stg with production key' => [EnvironmentService::ENV_VAR_VALUE_STAGING_ENVIRONMENT, $prodUrl, $prodKey], - 'something else with production key' => ['something else', $prodUrl, $prodKey], - 'undefined with production key' => ['', $prodUrl, $prodKey], - 'Prod with sandbox key' => [EnvironmentService::ENV_VAR_VALUE_PROD_ENVIRONMENT, $sbxUrl, $sbxKey], - 'Stg with sandbox key' => [EnvironmentService::ENV_VAR_VALUE_STAGING_ENVIRONMENT, $stgUrl, $sbxKey], - 'something else with sandbox key' => ['something else', $sbxUrl, $sbxKey], - 'undefined with sandbox key' => ['', $sbxUrl, $sbxKey], - ]; - } - // } diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index f73cb6c8f..f4d2402f1 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -19,14 +19,11 @@ use UnzerSDK\Interfaces\ResourceServiceInterface; use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; -use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\Payment; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; use UnzerSDK\Resources\PaymentTypes\Paypage; use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; @@ -64,145 +61,8 @@ public function gettersAndSettersShouldWorkProperly(): void // - // - - /** - * Verify authorize calls create for a new authorization using the passed values. - * - * @test - * - * @param $card3ds - * - * @dataProvider card3dsDataProvider - */ - public function authorizeShouldCreateNewAuthorizationAndPayment($card3ds): void - { - $customer = (new Customer())->setId('myCustomerId'); - $metadata = (new Metadata())->setId('myMetadataId'); - $basket = (new Basket())->setId('myBasketId'); - - /** @var ResourceService|MockObject $resourceSrvMock */ - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); - $paymentSrv = (new Unzer('s-priv-123'))->setResourceService($resourceSrvMock)->getPaymentService(); - /** @noinspection PhpParamsInspection */ - $resourceSrvMock->expects($this->once())->method('createResource') - ->with($this->callback(static function ($authorize) use ($customer, $metadata, $basket, $card3ds) { - /** @var Authorization $authorize */ - $newPayment = $authorize->getPayment(); - return $authorize instanceof Authorization && - $authorize->getAmount() === 1.234 && - $authorize->getCurrency() === 'myCurrency' && - $authorize->getOrderId() === 'myId' && - $authorize->getReturnUrl() === 'myUrl' && - $authorize->isCard3ds() === $card3ds && - $newPayment instanceof Payment && - $newPayment->getMetadata() === $metadata && - $newPayment->getCustomer() === $customer && - $newPayment->getBasket() === $basket && - $newPayment->getAuthorization() === $authorize; - })); - - $type = (new PayPal())->setId('typeId'); - $paymentSrv->authorize(1.234, 'myCurrency', $type, 'myUrl', $customer, 'myId', $metadata, $basket, $card3ds); - } - - // - // - /** - * Verify charge method calls create with a charge object on resource service. - * - * @test - * - * @param $card3ds - * - * @dataProvider card3dsDataProvider - */ - public function chargeShouldCreateNewPaymentAndCharge($card3ds): void - { - $customer = (new Customer())->setId('myCustomerId'); - $unzer = new Unzer('s-priv-123'); - $paymentType = (new Sofort())->setId('myPaymentTypeId'); - $metadata = (new Metadata())->setId('myMetadataId'); - $basket = (new Basket())->setId('myBasketId'); - - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); - /** @noinspection PhpParamsInspection */ - $resourceSrvMock->expects($this->once())->method('createResource') - ->with($this->callback(static function ($charge) use ($customer, $paymentType, $basket, $card3ds) { - /** @var Charge $charge */ - $newPayment = $charge->getPayment(); - return $charge instanceof Charge && - $charge->getAmount() === 1.234 && - $charge->getCurrency() === 'myCurrency' && - $charge->getOrderId() === 'myId' && - $charge->getReturnUrl() === 'myUrl' && - $charge->isCard3ds() === $card3ds && - $newPayment instanceof Payment && - $newPayment->getCustomer() === $customer && - $newPayment->getPaymentType() === $paymentType && - $newPayment->getBasket() === $basket && - in_array($charge, $newPayment->getCharges(), true); - })); - - /** @var ResourceService $resourceSrvMock */ - $paymentSrv = $unzer->setResourceService($resourceSrvMock)->getPaymentService(); - $returnedCharge = $paymentSrv->charge(1.234, 'myCurrency', $paymentType, 'myUrl', $customer, 'myId', $metadata, $basket, $card3ds); - $this->assertSame($paymentType, $returnedCharge->getPayment()->getPaymentType()); - } - - /** - * Verify chargeAuthorization calls chargePayment with the given payment object. - * - * @test - */ - public function chargeAuthorizationShouldCallChargePaymentWithTheGivenPaymentObject(): void - { - $paymentObject = (new Payment())->setId('myPaymentId'); - /** @var PaymentService|MockObject $paymentSrvMock */ - $paymentSrvMock = $this->getMockBuilder(PaymentService::class)->setMethods(['chargePayment'])->disableOriginalConstructor()->getMock(); - $paymentSrvMock->expects($this->exactly(2))->method('chargePayment')->withConsecutive([$paymentObject, null], [$paymentObject, 1.234]); - - $paymentSrvMock->setUnzer((new Unzer('s-priv-123'))->setPaymentService($paymentSrvMock)); - $paymentSrvMock->chargeAuthorization($paymentObject); - $paymentSrvMock->chargeAuthorization($paymentObject, 1.234); - } - - /** - * @deprecated - * Verify chargeAuthorization calls fetchPayment if the payment object is passed as id string. - * - * @test - */ - public function chargeAuthorizationShouldCallChargePaymentMethod(): void - { - /** @var ResourceServiceInterface|MockObject $resourceSrvMock */ - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setMethods(['fetchPayment'])->disableOriginalConstructor()->getMock(); - /** @var PaymentService|MockObject $paymentSrvMock */ - $paymentSrvMock = $this->getMockBuilder(PaymentService::class)->setMethods(['chargePayment'])->disableOriginalConstructor()->getMock(); - $paymentSrvMock->expects($this->once())->method('chargePayment')->withAnyParameters(); - - $paymentSrvMock->chargeAuthorization('myPaymentId'); - } - - /** - * @deprecated - * Verify chargePayment calls fetchPayment if the payment object is passed as id string. - * - * @test - */ - public function chargePaymentShouldCallerformChargeOnPaymentMethod(): void - { - /** @var ResourceServiceInterface|MockObject $resourceSrvMock */ - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setMethods(['fetchPayment'])->disableOriginalConstructor()->getMock(); - /** @var PaymentService|MockObject $paymentSrvMock */ - $paymentSrvMock = $this->getMockBuilder(PaymentService::class)->setMethods(['performChargeOnPayment'])->disableOriginalConstructor()->getMock(); - $paymentSrvMock->expects($this->once())->method('performChargeOnPayment')->withAnyParameters(); - - $paymentSrvMock->chargePayment('myPaymentId'); - } - /** * Verify performChargeOnPayment calls fetchPayment if the payment object is passed as id string. * @@ -221,68 +81,6 @@ public function performChargeOnPaymentShouldCallFetchPaymentIfThePaymentIsPassed $paymentSrvMock->performChargeOnPayment('myPaymentId', new Charge()); } - /** - * Verify chargePayment will create a charge object and call create on ResourceService with it. - * - * @test - */ - public function chargePaymentShouldCallCreateOnResourceServiceWithNewCharge(): void - { - $unzer = new Unzer('s-priv-123'); - $payment = (new Payment())->setParentResource($unzer)->setId('myPaymentId'); - - /** @var ResourceService|MockObject $resourceSrvMock */ - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); - /** @noinspection PhpParamsInspection */ - $resourceSrvMock->expects($this->once())->method('createResource') - ->with($this->callback(static function ($charge) use ($payment) { - /** @var Charge $charge */ - $newPayment = $charge->getPayment(); - return $charge instanceof Charge && - $charge->getAmount() === 1.234 && - $charge->getOrderId() === null && - $charge->getInvoiceId() === null && - $newPayment instanceof Payment && - $newPayment === $payment && - in_array($charge, $newPayment->getCharges(), true); - })); - - $paymentSrv = $unzer->setResourceService($resourceSrvMock)->getPaymentService(); - $returnedCharge = $paymentSrv->chargePayment($payment, 1.234); - $this->assertEquals([$returnedCharge], $payment->getCharges()); - } - - /** - * Verify chargePayment will set Ids if they are defined. - * - * @test - */ - public function chargePaymentShouldSetArgumentsInNewChargeObject(): void - { - $unzer = new Unzer('s-priv-123'); - $payment = (new Payment())->setParentResource($unzer)->setId('myPaymentId'); - - /** @var ResourceService|MockObject $resourceSrvMock */ - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); - /** @noinspection PhpParamsInspection */ - $resourceSrvMock->expects($this->once())->method('createResource') - ->with($this->callback(static function ($charge) use ($payment) { - /** @var Charge $charge */ - $newPayment = $charge->getPayment(); - return $charge instanceof Charge && - $charge->getAmount() === 1.234 && - $charge->getOrderId() === 'orderId' && - $charge->getInvoiceId() === 'invoiceId' && - $newPayment instanceof Payment && - $newPayment === $payment && - in_array($charge, $newPayment->getCharges(), true); - })); - - $paymentSrv = $unzer->setResourceService($resourceSrvMock)->getPaymentService(); - $returnedCharge = $paymentSrv->chargePayment($payment, 1.234, 'orderId', 'invoiceId'); - $this->assertEquals([$returnedCharge], $payment->getCharges()); - } - // // @@ -576,50 +374,8 @@ public function paymentShouldBeCreatedByInitPayPage(string $action): void // - // - - /** - * Verify fetch hdd instalment plans. - * - * @test - */ - public function fetchInstalmentPlansWillCallFetchOnResourceService(): void - { - $unzer = new Unzer('s-priv-1234'); - /** @var MockObject|ResourceService $resourceSrvMock */ - $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setConstructorArgs(['unzer' => $unzer])->setMethods(['fetchResource'])->getMock(); - $unzer->setResourceService($resourceSrvMock); - - $date = $this->getYesterdaysTimestamp(); - /** @noinspection PhpParamsInspection */ - $resourceSrvMock->expects($this->once())->method('fetchResource') - ->with($this->callback(static function ($param) use ($date) { - return $param instanceof InstalmentPlans && - $param->getAmount() === 12.23 && - $param->getCurrency() === 'EUR' && - $param->getEffectiveInterest() === 4.99 && - $param->getOrderDate() === $date->format('Y-m-d') && - $param->getParentResource() instanceof InstallmentSecured; - }))->willReturn(new InstalmentPlans(12.23, 'EUR', 4.99, $date)); - $unzer->getPaymentService()->fetchInstallmentPlans(12.23, 'EUR', 4.99, $date); - } - - // - // - /** - * @return array - */ - public function card3dsDataProvider(): array - { - return [ - 'default' => [null], - 'non 3ds' => [false], - '3ds' => [true] - ]; - } - /** * @return array */ diff --git a/test/unit/Services/ResourceServiceTest.php b/test/unit/Services/ResourceServiceTest.php index 6cb6de5cd..7cf696e31 100755 --- a/test/unit/Services/ResourceServiceTest.php +++ b/test/unit/Services/ResourceServiceTest.php @@ -16,6 +16,7 @@ use RuntimeException; use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; +use UnzerSDK\Apis\ApiRequest; use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Constants\ApiVersions; use UnzerSDK\Exceptions\UnzerApiException; @@ -31,12 +32,8 @@ use UnzerSDK\Resources\PaymentTypes\Bancontact; use UnzerSDK\Resources\PaymentTypes\Card; use UnzerSDK\Resources\PaymentTypes\EPS; -use UnzerSDK\Resources\PaymentTypes\Giropay; use UnzerSDK\Resources\PaymentTypes\Googlepay; use UnzerSDK\Resources\PaymentTypes\Ideal; -use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; -use UnzerSDK\Resources\PaymentTypes\Invoice; -use UnzerSDK\Resources\PaymentTypes\InvoiceSecured; use UnzerSDK\Resources\PaymentTypes\Klarna; use UnzerSDK\Resources\PaymentTypes\OpenbankingPis; use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice; @@ -47,8 +44,6 @@ use UnzerSDK\Resources\PaymentTypes\Prepayment; use UnzerSDK\Resources\PaymentTypes\Przelewy24; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; -use UnzerSDK\Resources\PaymentTypes\SepaDirectDebitSecured; -use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\Resources\PaymentTypes\Wechatpay; use UnzerSDK\Resources\Recurring; use UnzerSDK\Resources\TransactionTypes\Authorization; @@ -104,13 +99,17 @@ public function sendShouldCallSendOnHttpService(string $method, string $uri, boo /** @noinspection PhpParamsInspection */ $resourceMock->expects($this->once())->method('getUri')->with($appendId, $method)->willReturn($uri); $resourceMock->method('getUnzerObject')->willReturn($unzer); - $httpSrvMock = $this->getMockBuilder(HttpService::class)->setMethods(['send'])->getMock(); + $httpSrvMock = $this->getMockBuilder(HttpService::class)->setMethods(['sendRequest'])->getMock(); $resourceSrv = new ResourceService($unzer); /** @var HttpService $httpSrvMock */ $unzer->setHttpService($httpSrvMock); /** @noinspection PhpParamsInspection */ - $httpSrvMock->expects($this->once())->method('send')->with($uri, $resourceMock, $method)->willReturn('{"response": "This is the response"}'); + $httpSrvMock->expects($this->once())->method('sendRequest') + ->with($this->callback(static function (ApiRequest $request) use ($uri, $resourceMock, $method) { + return $request->getUri() === $uri && $request->getHttpMethod() === $method && $request->getResource() === $resourceMock; + })) + ->willReturn('{"response": "This is the response"}'); /** @var AbstractUnzerResource $resourceMock */ $response = $resourceSrv->send($resourceMock, $method); @@ -137,16 +136,20 @@ public function AuthTokenShouldBeRequestedAutomatically(string $method, string $ $httpMethod = HttpAdapterInterface::REQUEST_POST; $dummyResource = new DummyPaypageResource(); $dummyResource->setParentResource($unzer); - $httpSrvMock = $this->getMockBuilder(HttpService::class)->setMethods(['send'])->getMock(); + $httpSrvMock = $this->getMockBuilder(HttpService::class)->setMethods(['sendRequest'])->getMock(); $resourceSrv = new ResourceService($unzer); /** @var HttpService $httpSrvMock */ $unzer->setHttpService($httpSrvMock); - $httpSrvMock->expects($this->exactly(2))->method('send')->withConsecutive( - [$uri], - ['/dummy-paypage-uri', $dummyResource, $method] - )->willReturnOnConsecutiveCalls('{"accessToken": "jwt.auth.token"}', '{"response": "paypage response"}'); + $httpSrvMock->expects($this->exactly(2))->method('sendRequest') + ->withConsecutive( + [$this->callback(static function (ApiRequest $r) use ($uri) { return $r->getUri() === $uri; })], + [$this->callback(static function (ApiRequest $r) use ($dummyResource, $method) { + return $r->getUri() === '/dummy-paypage-uri' && $r->getHttpMethod() === $method && $r->getResource() === $dummyResource; + })] + ) + ->willReturnOnConsecutiveCalls('{"accessToken": "jwt.auth.token"}', '{"response": "paypage response"}'); $response = $resourceSrv->send($dummyResource, $method); $this->assertEquals('paypage response', $response->response); @@ -174,17 +177,20 @@ public function customerV2CreationShouldCallV2Enpoint(string $uri, bool $appendI $customer->setParentResource($unzer); //prepare http service mock. - $method = 'send'; - $httpSrvMock = $this->getMockBuilder(HttpService::class)->setMethods([$method])->getMock(); + $method = HttpAdapterInterface::REQUEST_POST; + $httpSrvMock = $this->getMockBuilder(HttpService::class)->setMethods(['sendRequest'])->getMock(); $resourceSrv = new ResourceService($unzer); /** @var HttpService $httpSrvMock */ $unzer->setHttpService($httpSrvMock); - $httpSrvMock->expects($this->exactly(2))->method($method)->withConsecutive( - ['/auth/token'], - [$uri, $customer, $method] - ) + $httpSrvMock->expects($this->exactly(2))->method('sendRequest') + ->withConsecutive( + [$this->callback(static function (ApiRequest $r) { return $r->getUri() === '/auth/token'; })], + [$this->callback(static function (ApiRequest $r) use ($uri, $customer, $method) { + return $r->getUri() === $uri && $r->getResource() === $customer && $r->getHttpMethod() === $method; + })] + ) ->willReturnOnConsecutiveCalls( '{"accessToken": "jwt.auth.token"}', '{"response": "paypage response"}' @@ -522,7 +528,7 @@ static function ($resource) use ($callback, $unzer) { public function createPaymentTypeShouldSetUnzerObjectAndCallCreate(): void { $unzer = new Unzer('s-priv-1234'); - $paymentType = new Sofort(); + $paymentType = new Paypal(); $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setMethods(['createResource'])->setConstructorArgs([$unzer])->getMock(); /** @noinspection PhpParamsInspection */ @@ -565,7 +571,7 @@ public function fetchPaymentTypeShouldThrowExceptionOnInvalidTypeId($typeId): vo */ public function updatePaymentTypeShouldCallUpdateMethod(): void { - $paymentType = (new InstallmentSecured())->setId('paymentTypeId'); + $paymentType = (new Paypal())->setId('paymentTypeId'); /** @var ResourceServiceInterface|MockObject $resourceSrvMock */ $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setMethods(['updateResource'])->disableOriginalConstructor()->getMock(); @@ -1306,7 +1312,7 @@ public function createRecurringShouldThrowExceptionWhenRecurringPaymentIsNotSupp $resourceService = new ResourceService(new Unzer('s-priv-123')); $this->expectException(RuntimeException::class); - $resourceService->activateRecurringPayment(new Sofort(), 'returnUrl', null); + $resourceService->activateRecurringPayment(new EPS(), 'returnUrl', null); } /** @@ -1409,14 +1415,7 @@ public function fetchResourceByUrlForAPaymentTypeShouldCallFetchPaymentTypeDP(): 'BANCONTACT' => ['s-bct-xen2ybcovn56', 'https://api.unzer.com/v1/types/bancontact/s-bct-xen2ybcovn56/'], 'CARD' => ['s-crd-xen2ybcovn56', 'https://api.unzer.com/v1/types/card/s-crd-xen2ybcovn56/'], 'EPS' => ['s-eps-xen2ybcovn56', 'https://api.unzer.com/v1/types/eps/s-eps-xen2ybcovn56/'], - 'GIROPAY' => ['s-gro-xen2ybcovn56', 'https://api.unzer.com/v1/types/giropay/s-gro-xen2ybcovn56/'], - 'HIRE_PURCHASE_DIRECT_DEBIT' => ['s-hdd-xen2ybcovn56', 'https://api.unzer.com/v1/types/hire-purchase-direct-debit/s-hdd-xen2ybcovn56/'], 'IDEAL' => ['s-idl-xen2ybcovn56', 'https://api.unzer.com/v1/types/ideal/s-idl-xen2ybcovn56/'], - 'INVOICE' => ['s-ivc-xen2ybcovn56', 'https://api.unzer.com/v1/types/invoice/s-ivc-xen2ybcovn56/'], - 'INVOICE_FACTORING' => ['s-ivf-xen2ybcovn56', 'https://api.unzer.com/v1/types/wechatpay/s-ivf-xen2ybcovn56/'], - 'INVOICE_GUARANTEED' => ['s-ivg-xen2ybcovn56', 'https://api.unzer.com/v1/types/invoice-guaranteed/s-ivg-xen2ybcovn56/'], - 'INVOICE_SECURED' => ['s-ivs-xen2ybcovn56', 'https://api.unzer.com/v1/types/invoice-secured/s-ivs-xen2ybcovn56/'], - 'Installment_SECURED' => ['s-ins-xen2ybcovn56', 'https://api.unzer.com/v1/types/installment-secured/s-ins-xen2ybcovn56/'], 'PAYLATER_INVOICE' => ['s-piv-xen2ybcovn56', 'https://api.unzer.com/v1/types/paylater-invoice/s-piv-xen2ybcovn56/'], 'PAYPAL' => ['s-ppl-xen2ybcovn56', 'https://api.unzer.com/v1/types/paypal/s-ppl-xen2ybcovn56/'], 'PIS' => ['s-pis-xen2ybcovn56', 'https://api.unzer.com/v1/types/pis/s-pis-xen2ybcovn56/'], @@ -1425,8 +1424,6 @@ public function fetchResourceByUrlForAPaymentTypeShouldCallFetchPaymentTypeDP(): 'PREPAYMENT' => ['s-ppy-xen2ybcovn56', 'https://api.unzer.com/v1/types/prepayment/s-ppy-xen2ybcovn56/'], 'PRZELEWY24' => ['s-p24-xen2ybcovn56', 'https://api.unzer.com/v1/types/przelewy24/s-p24-xen2ybcovn56/'], 'SEPA_DIRECT_DEBIT' => ['s-sdd-xen2ybcovn56', 'https://api.unzer.com/v1/types/direct-debit/s-sdd-xen2ybcovn56/'], - 'SEPA_DIRECT_DEBIT_GUARANTEED' => ['s-ddg-xen2ybcovn56', 'https://api.unzer.com/v1/types/direct-debit-guaranteed/s-ddg-xen2ybcovn56/'], - 'SOFORT' => ['s-sft-xen2ybcovn56', 'https://api.unzer.com/v1/types/sofort/s-sft-xen2ybcovn56/'], 'WECHATPAY' => ['s-wcp-xen2ybcovn56', 'https://api.unzer.com/v1/types/wechatpay/s-wcp-xen2ybcovn56/'], 'WERO' => ['s-wro-xen2ybcovn56', 'https://api.unzer.com/v1/types/wero/s-wro-xen2ybcovn56/'] ]; @@ -1498,43 +1495,27 @@ public function fetchShouldCallFetchResourceDP(): array 'fetchBasket by id' => ['fetchBasket', ['myBasketId'], $fetchBasketCB], 'fetchBasket by obj' => ['fetchBasket', [(new Basket())->setId('myBasketId')], $fetchBasketCB], 'PaymentType Card sandbox' => ['fetchPaymentType', ['s-crd-12345678'], $getPaymentTypeCB(Card::class)], - 'PaymentType Giropay sandbox' => ['fetchPaymentType', ['s-gro-12345678'], $getPaymentTypeCB(Giropay::class)], 'PaymentType Google Pay sandbox' => ['fetchPaymentType', ['s-gop-12345678'], $getPaymentTypeCB(Googlepay::class)], 'PaymentType Ideal sandbox' => ['fetchPaymentType', ['s-idl-12345678'], $getPaymentTypeCB(Ideal::class)], - 'PaymentType Invoice sandbox' => ['fetchPaymentType', ['s-ivc-12345678'], $getPaymentTypeCB(Invoice::class)], - 'PaymentType InvoiceGuaranteed sandbox' => ['fetchPaymentType', ['s-ivg-12345678'], $getPaymentTypeCB(InvoiceSecured::class)], - 'PaymentType InvoiceSecured sandbox' => ['fetchPaymentType', ['s-ivs-12345678'], $getPaymentTypeCB(InvoiceSecured::class)], - 'PaymentType Invoie factoring sandbox' => ['fetchPaymentType', ['s-ivf-12345678'], $getPaymentTypeCB(InvoiceSecured::class)], 'PaymentType Klarna' => ['fetchPaymentType', ['s-kla-12345678'], $getPaymentTypeCB(Klarna::class)], 'PaymentType Paypal sandbox' => ['fetchPaymentType', ['s-ppl-12345678'], $getPaymentTypeCB(Paypal::class)], 'PaymentType Paylater-Invoice sandbox' => ['fetchPaymentType', ['s-piv-12345678'], $getPaymentTypeCB(PaylaterInvoice::class)], 'PaymentType Prepayment sandbox' => ['fetchPaymentType', ['s-ppy-12345678'], $getPaymentTypeCB(Prepayment::class)], 'PaymentType Przelewy24 sandbox' => ['fetchPaymentType', ['s-p24-12345678'], $getPaymentTypeCB(Przelewy24::class)], 'PaymentType SepaDirectDebit sandbox' => ['fetchPaymentType', ['s-sdd-12345678'], $getPaymentTypeCB(SepaDirectDebit::class)], - 'PaymentType SepaDirectDebitGuaranteed sandbox' => ['fetchPaymentType', ['s-ddg-12345678'], $getPaymentTypeCB(SepaDirectDebitSecured::class)], - 'PaymentType SepaDirectDebitSecured sandbox' => ['fetchPaymentType', ['s-dds-12345678'], $getPaymentTypeCB(SepaDirectDebitSecured::class)], - 'PaymentType Sofort sandbox' => ['fetchPaymentType', ['s-sft-12345678'], $getPaymentTypeCB(Sofort::class)], 'PaymentType PIS sandbox' => ['fetchPaymentType', ['s-pis-12345678'], $getPaymentTypeCB(PIS::class)], 'PaymentType PFC sandbox' => ['fetchPaymentType', ['s-pfc-12345678'], $getPaymentTypeCB(PostFinanceCard::class)], 'PaymentType PFE sandbox' => ['fetchPaymentType', ['s-pfe-12345678'], $getPaymentTypeCB(PostFinanceEfinance::class)], 'PaymentType EPS sandbox' => ['fetchPaymentType', ['s-eps-12345678'], $getPaymentTypeCB(EPS::class)], 'PaymentType Alipay sandbox' => ['fetchPaymentType', ['s-ali-12345678'], $getPaymentTypeCB(Alipay::class)], 'PaymentType Wechatpay sandbox' => ['fetchPaymentType', ['s-wcp-12345678'], $getPaymentTypeCB(Wechatpay::class)], - 'PaymentType HirePurchaseDirectDebit sandbox' => ['fetchPaymentType', ['s-hdd-12345678'], $getPaymentTypeCB(InstallmentSecured::class)], - 'PaymentType InstallmentSecured sandbox' => ['fetchPaymentType', ['s-ins-12345678'], $getPaymentTypeCB(InstallmentSecured::class)], 'PaymentType Bancontact sandbox' => ['fetchPaymentType', ['s-bct-12345678'], $getPaymentTypeCB(Bancontact::class)], 'PaymentType OpenBanking sandbox' => ['fetchPaymentType', ['s-obp-12345678'], $getPaymentTypeCB(OpenbankingPis::class)], 'PaymentType Alipay production' => ['fetchPaymentType', ['p-ali-12345678'], $getPaymentTypeCB(Alipay::class)], 'PaymentType Bancontact production' => ['fetchPaymentType', ['p-bct-12345678'], $getPaymentTypeCB(Bancontact::class)], 'PaymentType Card production' => ['fetchPaymentType', ['p-crd-12345678'], $getPaymentTypeCB(Card::class)], 'PaymentType EPS production' => ['fetchPaymentType', ['p-eps-12345678'], $getPaymentTypeCB(EPS::class)], - 'PaymentType Giropay production' => ['fetchPaymentType', ['p-gro-12345678'], $getPaymentTypeCB(Giropay::class)], - 'PaymentType HirePurchaseDirectDebit production' => ['fetchPaymentType', ['p-hdd-12345678'], $getPaymentTypeCB(InstallmentSecured::class)], 'PaymentType Ideal production' => ['fetchPaymentType', ['p-idl-12345678'], $getPaymentTypeCB(Ideal::class)], - 'PaymentType InstallmentSecured production' => ['fetchPaymentType', ['p-hdd-12345678'], $getPaymentTypeCB(InstallmentSecured::class)], - 'PaymentType Invoice factoring production' => ['fetchPaymentType', ['p-ivf-12345678'], $getPaymentTypeCB(InvoiceSecured::class)], - 'PaymentType Invoice production' => ['fetchPaymentType', ['p-ivc-12345678'], $getPaymentTypeCB(Invoice::class)], - 'PaymentType InvoiceGuaranteed production' => ['fetchPaymentType', ['p-ivg-12345678'], $getPaymentTypeCB(InvoiceSecured::class)], 'PaymentType Paylater-Invoice production' => ['fetchPaymentType', ['p-piv-12345678'], $getPaymentTypeCB(PaylaterInvoice::class)], 'PaymentType Paypal production' => ['fetchPaymentType', ['p-ppl-12345678'], $getPaymentTypeCB(Paypal::class)], 'PaymentType PFC production' => ['fetchPaymentType', ['p-pfc-12345678'], $getPaymentTypeCB(PostFinanceCard::class)], @@ -1542,9 +1523,6 @@ public function fetchShouldCallFetchResourceDP(): array 'PaymentType Prepayment production' => ['fetchPaymentType', ['p-ppy-12345678'], $getPaymentTypeCB(Prepayment::class)], 'PaymentType Przelewy24 production' => ['fetchPaymentType', ['p-p24-12345678'], $getPaymentTypeCB(Przelewy24::class)], 'PaymentType SepaDirectDebit production' => ['fetchPaymentType', ['p-sdd-12345678'], $getPaymentTypeCB(SepaDirectDebit::class)], - 'PaymentType SepaDirectDebitGuaranteed production' => ['fetchPaymentType', ['p-ddg-12345678'], $getPaymentTypeCB(SepaDirectDebitSecured::class)], - 'PaymentType SepaDirectDebitSecured production' => ['fetchPaymentType', ['p-dds-12345678'], $getPaymentTypeCB(SepaDirectDebitSecured::class)], - 'PaymentType Sofort production' => ['fetchPaymentType', ['p-sft-12345678'], $getPaymentTypeCB(Sofort::class)], 'PaymentType Wechatpay production' => ['fetchPaymentType', ['p-wcp-12345678'], $getPaymentTypeCB(Wechatpay::class)], 'PaymentType OpenBanking production' => ['fetchPaymentType', ['p-obp-12345678'], $getPaymentTypeCB(OpenbankingPis::class)], ]; diff --git a/test/unit/Traits/CanAuthorizeTest.php b/test/unit/Traits/CanAuthorizeTest.php index 5597d713d..1e3b7bec0 100755 --- a/test/unit/Traits/CanAuthorizeTest.php +++ b/test/unit/Traits/CanAuthorizeTest.php @@ -36,36 +36,58 @@ public function authorizeShouldThrowExceptionIfTheClassDoesNotImplementParentInt } /** - * Verify authorize method propagates authorize method to Unzer object. + * Verify authorize method propagates to Unzer object. * * @test + * @dataProvider authorizeDataProvider */ - public function authorizeShouldPropagateAuthorizeToUnzer(): void - { - $unzerMock = $this->getMockBuilder(Unzer::class)->setMethods(['authorize'])->disableOriginalConstructor()->getMock(); - $dummyMock = $this->getMockBuilder(TraitDummyWithoutCustomerWithParentIF::class)->setMethods(['getUnzerObject'])->getMock(); - - $authorize = new Authorization(); - $customer = (new Customer())->setId('123'); - $metadata = new Metadata(); - $dummyMock->expects($this->exactly(4))->method('getUnzerObject')->willReturn($unzerMock); - $unzerMock->expects($this->exactly(4))->method('authorize') - ->withConsecutive( - [1.1, 'MyCurrency', $dummyMock, 'https://return.url', null, null], - [1.2, 'MyCurrency2', $dummyMock, 'https://return.url2', $customer, null], - [1.3, 'MyCurrency3', $dummyMock, 'https://return.url3', $customer, 'orderId'], - [1.4, 'MyCurrency3', $dummyMock, 'https://return.url3', $customer, 'orderId', $metadata] - )->willReturn($authorize); + public function authorizeShouldPropagateAuthorizeToUnzer( + float $amount, + string $currency, + string $returnUrl, + ?object $customer, + ?string $orderId, + ?Metadata $metadata + ): void { + $unzerMock = $this->getMockBuilder(Unzer::class) + ->setMethods(['performAuthorization']) + ->disableOriginalConstructor() + ->getMock(); + $dummyMock = $this->getMockBuilder(TraitDummyWithoutCustomerWithParentIF::class) + ->setMethods(['getUnzerObject']) + ->getMock(); + $expectedAuthorization = new Authorization(); + $dummyMock->method('getUnzerObject')->willReturn($unzerMock); + $unzerMock->expects($this->once()) + ->method('performAuthorization') + ->with( + $this->callback(static function (Authorization $a) use ($amount, $currency, $returnUrl, $orderId) { + return $a->getAmount() === $amount + && $a->getCurrency() === $currency + && $a->getReturnUrl() === $returnUrl + && $a->getOrderId() === $orderId; + }), + $dummyMock, + $customer, + $metadata + ) + ->willReturn($expectedAuthorization); /** @var TraitDummyWithoutCustomerWithParentIF $dummyMock */ - $returnedAuthorize = $dummyMock->authorize(1.1, 'MyCurrency', 'https://return.url'); - $this->assertSame($authorize, $returnedAuthorize); - $returnedAuthorize = $dummyMock->authorize(1.2, 'MyCurrency2', 'https://return.url2', $customer); - $this->assertSame($authorize, $returnedAuthorize); - $returnedAuthorize = $dummyMock->authorize(1.3, 'MyCurrency3', 'https://return.url3', $customer, 'orderId'); - $this->assertSame($authorize, $returnedAuthorize); - $returnedAuthorize = $dummyMock->authorize(1.4, 'MyCurrency3', 'https://return.url3', $customer, 'orderId', $metadata); - $this->assertSame($authorize, $returnedAuthorize); + $returnedAuthorize = $dummyMock->authorize($amount, $currency, $returnUrl, $customer, $orderId, $metadata); + $this->assertSame($expectedAuthorization, $returnedAuthorize); + } + + public function authorizeDataProvider(): array + { + $customer = (new Customer())->setId('123'); + $metadata = new Metadata(); + return [ + 'no customer' => [1.1, 'MyCurrency', 'https://return.url', null, null, null], + 'with customer' => [1.2, 'MyCurrency2', 'https://return.url2', $customer, null, null], + 'with customer and orderId' => [1.3, 'MyCurrency3', 'https://return.url3', $customer, 'orderId', null], + 'with customer and metadata' => [1.4, 'MyCurrency3', 'https://return.url3', $customer, 'orderId', $metadata], + ]; } } diff --git a/test/unit/Traits/CanDirectChargeTest.php b/test/unit/Traits/CanDirectChargeTest.php index 4c403303a..020c93aa4 100755 --- a/test/unit/Traits/CanDirectChargeTest.php +++ b/test/unit/Traits/CanDirectChargeTest.php @@ -39,33 +39,55 @@ public function directChargeShouldThrowExceptionIfTheClassDoesNotImplementParent * Verify direct charge propagates to Unzer object. * * @test + * @dataProvider directChargeDataProvider */ - public function directChargeShouldPropagateToUnzer(): void - { - $unzerMock = $this->getMockBuilder(Unzer::class)->setMethods(['charge'])->disableOriginalConstructor()->getMock(); - $dummyMock = $this->getMockBuilder(TraitDummyWithoutCustomerWithParentIF::class)->setMethods(['getUnzerObject'])->getMock(); - - $charge = new Charge(); - $metadata = new Metadata(); - $customer = (new Customer())->setId('123'); - $dummyMock->expects($this->exactly(4))->method('getUnzerObject')->willReturn($unzerMock); - $unzerMock->expects($this->exactly(4))->method('charge') - ->withConsecutive( - [1.1, 'MyCurrency', $dummyMock, 'https://return.url', null, null], - [1.2, 'MyCurrency2', $dummyMock, 'https://return.url2', $customer, null], - [1.3, 'MyCurrency3', $dummyMock, 'https://return.url3', $customer, 'orderId'], - [1.4, 'MyCurrency4', $dummyMock, 'https://return.url4', $customer, 'orderId', $metadata] - )->willReturn($charge); + public function directChargeShouldPropagateToUnzer( + float $amount, + string $currency, + string $returnUrl, + ?object $customer, + ?string $orderId, + ?Metadata $metadata + ): void { + $unzerMock = $this->getMockBuilder(Unzer::class) + ->setMethods(['performCharge']) + ->disableOriginalConstructor() + ->getMock(); + $dummyMock = $this->getMockBuilder(TraitDummyWithoutCustomerWithParentIF::class) + ->setMethods(['getUnzerObject']) + ->getMock(); + $expectedCharge = new Charge(); + $dummyMock->method('getUnzerObject')->willReturn($unzerMock); + $unzerMock->expects($this->once()) + ->method('performCharge') + ->with( + $this->callback(static function (Charge $c) use ($amount, $currency, $returnUrl, $orderId) { + return $c->getAmount() === $amount + && $c->getCurrency() === $currency + && $c->getReturnUrl() === $returnUrl + && $c->getOrderId() === $orderId; + }), + $dummyMock, + $customer, + $metadata + ) + ->willReturn($expectedCharge); /** @var TraitDummyWithoutCustomerWithParentIF $dummyMock */ - $returnedCharge = $dummyMock->charge(1.1, 'MyCurrency', 'https://return.url'); - $this->assertSame($charge, $returnedCharge); - $returnedCharge = $dummyMock->charge(1.2, 'MyCurrency2', 'https://return.url2', $customer); - $this->assertSame($charge, $returnedCharge); - $returnedCharge = $dummyMock->charge(1.3, 'MyCurrency3', 'https://return.url3', $customer, 'orderId'); - $this->assertSame($charge, $returnedCharge); - $returnedCharge = $dummyMock->charge(1.4, 'MyCurrency4', 'https://return.url4', $customer, 'orderId', $metadata); - $this->assertSame($charge, $returnedCharge); + $returnedCharge = $dummyMock->charge($amount, $currency, $returnUrl, $customer, $orderId, $metadata); + $this->assertSame($expectedCharge, $returnedCharge); + } + + public function directChargeDataProvider(): array + { + $customer = (new Customer())->setId('123'); + $metadata = new Metadata(); + return [ + 'no customer' => [1.1, 'MyCurrency', 'https://return.url', null, null, null], + 'with customer' => [1.2, 'MyCurrency2', 'https://return.url2', $customer, null, null], + 'with customer and orderId' => [1.3, 'MyCurrency3', 'https://return.url3', $customer, 'orderId', null], + 'with customer and metadata' => [1.4, 'MyCurrency4', 'https://return.url4', $customer, 'orderId', $metadata], + ]; } } diff --git a/test/unit/Traits/CanRecurTest.php b/test/unit/Traits/CanRecurTest.php index 2d4738ac8..5ed106a57 100644 --- a/test/unit/Traits/CanRecurTest.php +++ b/test/unit/Traits/CanRecurTest.php @@ -34,33 +34,4 @@ public function gettersAndSettersShouldWorkProperly(): void $this->assertTrue($dummy->isRecurring()); } - /** - * Verify recurring activation on a resource which is not an abstract resource will throw an exception. - * - * @test - */ - public function activateRecurringWillThrowExceptionIfTheObjectHasWrongType(): void - { - $dummy = new TraitDummyCanRecurNonResource(); - - $this->expectException(RuntimeException::class); - $dummy->activateRecurring('1234'); - } - - /** - * Verify activation on object will call Unzer. - * - * @test - */ - public function activateRecurringWillCallUnzerMethod(): void - { - $unzerMock = $this->getMockBuilder(Unzer::class)->disableOriginalConstructor()->setMethods(['activateRecurringPayment'])->getMock(); - - /** @var Unzer $unzerMock */ - $dummy = (new TraitDummyCanRecur())->setParentResource($unzerMock); - /** @noinspection PhpParamsInspection */ - $unzerMock->expects(self::once())->method('activateRecurringPayment')->with($dummy, 'return url')->willReturn(new Recurring('', '')); - - $dummy->activateRecurring('return url'); - } } diff --git a/test/unit/UnzerTest.php b/test/unit/UnzerTest.php index c9c22488e..5a4bcb313 100644 --- a/test/unit/UnzerTest.php +++ b/test/unit/UnzerTest.php @@ -11,7 +11,6 @@ namespace UnzerSDK\test\unit; -use DateTime; use PHPUnit\Framework\MockObject\MockObject; use RuntimeException; use UnzerSDK\Resources\Basket; @@ -19,8 +18,8 @@ use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\Card; +use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\Paypage; -use UnzerSDK\Resources\PaymentTypes\Sofort; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Resources\Webhook; @@ -77,18 +76,6 @@ public function gettersAndSettersShouldWorkProperly(): void $this->assertEquals('myLocale', $unzer->getLocale()); $this->assertEquals('myIpAddress', $unzer->getClientIp()); - try { - $unzer->setKey('this is not a valid key'); - $this->assertTrue(false, 'This exception should have been thrown'); - } catch (RuntimeException $e) { - $this->assertEquals('Illegal key: Use a valid private or public key with this SDK!', $e->getMessage()); - } - - $unzer->setKey('s-pub-1234'); - $this->assertEquals('s-pub-1234', $unzer->getKey()); - $unzer->setKey('p-pub-1234'); - $this->assertEquals('p-pub-1234', $unzer->getKey()); - $httpService = new HttpService(); $this->assertNotSame($httpService, $unzer->getHttpService()); $unzer->setHttpService($httpService); @@ -244,7 +231,7 @@ public static function resourceServiceDP(): array $customer = new Customer(); $basket = new Basket(); $payment = new Payment(); - $sofort = new Sofort(); + $paypal = new Paypal(); $card = new Card('', '03/33'); $auth = new Authorization(); $charge = new Charge(); @@ -258,7 +245,7 @@ public static function resourceServiceDP(): array 'createMetadata' => ['createMetadata', [$metadata], 'createMetadata', [$metadata]], 'fetchMetadata' => ['fetchMetadata', [$metadata], 'fetchMetadata', [$metadata]], 'fetchMetadataStr' => ['fetchMetadata', [$metadataId], 'fetchMetadata', [$metadataId]], - 'createPaymentType' => ['createPaymentType', [$sofort], 'createPaymentType', [$sofort]], + 'createPaymentType' => ['createPaymentType', [$paypal], 'createPaymentType', [$paypal]], 'fetchPaymentType' => ['fetchPaymentType', [$paymentTypeId], 'fetchPaymentType', [$paymentTypeId]], 'createCustomer' => ['createCustomer', [$customer], 'createCustomer', [$customer]], 'createOrUpdateCustomer' => ['createOrUpdateCustomer', [$customer], 'createOrUpdateCustomer', [$customer]], @@ -297,36 +284,19 @@ public static function resourceServiceDP(): array */ public static function paymentServiceDP(): array { - $url = 'https://dev.unzer.com'; $orderId = 'orderId'; $paymentTypeId = 'paymentTypeId'; - $customerId = 'customerId'; - $paymentId = 'paymentId'; $customer = new Customer(); - $sofort = new Sofort(); $metadata = new Metadata(); $payment = new Payment(); $paypage = new Paypage(123.1234, 'EUR', 'url'); $basket = new Basket(); - $today = new DateTime(); return [ - 'auth' => ['authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata], 'authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata]], - 'authAlt' => ['authorize', [234.1, 'DZD', $sofort, $url], 'authorize', [234.1, 'DZD', $sofort, $url]], - 'authStr' => ['authorize', [34.12, 'DKK', $paymentTypeId, $url, $customerId, $orderId], 'authorize', [34.12, 'DKK', $paymentTypeId, $url, $customerId, $orderId]], - 'charge' => ['charge', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata], 'charge', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata]], - 'chargeAlt' => ['charge', [234.1, 'DZD', $sofort, $url], 'charge', [234.1, 'DZD', $sofort, $url]], - 'chargeStr' => ['charge', [34.12, 'DKK', $paymentTypeId, $url, $customerId, $orderId], 'charge', [34.12, 'DKK', $paymentTypeId, $url, $customerId, $orderId]], - 'chargeAuth' => ['chargeAuthorization', [$payment, 1.234], 'chargeAuthorization', [$payment, 1.234]], - 'chargeAuthAlt' => ['chargeAuthorization', [$paymentId], 'chargeAuthorization', [$paymentId, null]], - 'chargeAuthStr' => ['chargeAuthorization', [$paymentId, 2.345], 'chargeAuthorization', [$paymentId, 2.345]], - 'chargePayment' => ['chargePayment', [$payment, 1.234, 'ALL'], 'chargePayment', [$payment, 1.234, 'ALL']], - 'chargePaymentAlt' => ['chargePayment', [$payment], 'chargePayment', [$payment]], 'ship' => ['ship', [$payment], 'ship', [$payment]], 'payout' => ['payout', [123, 'EUR', $paymentTypeId, 'url', $customer, $orderId, $metadata, $basket], 'payout', [123, 'EUR', $paymentTypeId, 'url', $customer, $orderId, $metadata, $basket]], 'initPayPageCharge' => ['initPayPageCharge', [$paypage, $customer, $basket, $metadata], 'initPayPageCharge', [$paypage, $customer, $basket, $metadata]], 'initPayPageAuthorize' => ['initPayPageAuthorize', [$paypage, $customer, $basket, $metadata], 'initPayPageAuthorize', [$paypage, $customer, $basket, $metadata]], - 'fetchDDInstalmentPlans' => ['fetchInstallmentPlans', [123.4567, 'EUR', 4.99, $today], 'fetchInstallmentPlans', [123.4567, 'EUR', 4.99, $today]] ]; }