Skip to content

Commit

Permalink
Merge pull request #14 from PAYONE-GmbH/chore/demo-payment-execution
Browse files Browse the repository at this point in the history
chore/demo payment execution
  • Loading branch information
lrosenfeldt authored Aug 1, 2024
2 parents ab512eb + 4a79df5 commit f8d50bc
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 18 deletions.
93 changes: 93 additions & 0 deletions examples/demo-app/src/DemoApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use PayoneCommercePlatform\Sdk\Models\OrderType;
use PayoneCommercePlatform\Sdk\Models\PatchCheckoutRequest;
use PayoneCommercePlatform\Sdk\Models\PaymentChannel;
use PayoneCommercePlatform\Sdk\Models\PaymentExecutionRequest;
use PayoneCommercePlatform\Sdk\Models\PaymentExecutionSpecificInput;
use PayoneCommercePlatform\Sdk\Models\PaymentMethodSpecificInput;
use PayoneCommercePlatform\Sdk\Models\PersonalInformation;
use PayoneCommercePlatform\Sdk\Models\PersonalName;
Expand Down Expand Up @@ -74,6 +76,95 @@ public function __construct()
$this->orderManagementCheckoutClient = new OrderManagementCheckoutActionsApiClient($this->config);
}

protected function runCheckoutWithPaymentExecution(string $commerceCaseMerchantReference): void
{
// Create a commerce case, add customer data, put something into the shopping cart
/** @var CreateCommerceCaseRequest */
$createCommerceCaseRequest = new CreateCommerceCaseRequest(
customer: new Customer(
personalInformation: new PersonalInformation(
dateOfBirth: "19991112",
name: new PersonalName(firstName: "Ryan", surname: "Carniato"),
),
contactDetails: new ContactDetails(
emailAddress: "mail@mail.com",
),
billingAddress: new Address(
countryCode: "DE",
zip: "24937",
city: "Flensburg",
street: "Rathausplatz",
houseNumber: "1",
),
),
checkout: new CreateCheckoutRequest(
amountOfMoney: new AmountOfMoney(amount: 3599, currencyCode: "EUR"),
shipping: new Shipping(
address: new AddressPersonal(
countryCode: "DE",
zip: "24937",
city: "Flensburg",
street: "Rathausplatz",
houseNumber: "1"
)
),
shoppingCart: new ShoppingCartInput(
items: [new CartItemInput(
invoiceData: new CartItemInvoiceData(
description: "T-Shirt - Scaleshape Logo - S",
),
orderLineDetails: new OrderLineDetailsInput(
productPrice: 3599,
quantity: 1,
productType: ProductType::GOODS,
),
)],
),
)
);

$commerceCase = $this->commerceCaseClient->createCommerceCase($this->merchantId, $createCommerceCaseRequest);

$paymentExecutionRequest = new PaymentExecutionRequest(
paymentExecutionSpecificInput: new PaymentExecutionSpecificInput(
paymentReferences: new References(merchantReference: "p-" . $commerceCaseMerchantReference),
amountOfMoney: new AmountOfMoney(amount: 3599, currencyCode: "EUR"),
),
paymentMethodSpecificInput: new PaymentMethodSpecificInput(
sepaDirectDebitPaymentMethodSpecificInput: new SepaDirectDebitPaymentMethodSpecificInput(
paymentProductId: 771,
paymentProduct771SpecificInput: new SepaDirectDebitPaymentProduct771SpecificInput(
mandate: new ProcessingMandateInformation(
bankAccountIban: new BankAccountInformation(
iban: "DE75512108001245126199",
accountHolder: "Ryan Carniato",
),
dateOfSignature: "20240730",
recurrenceType: MandateRecurrenceType::UNIQUE,
uniqueMandateReference: "m-" . $commerceCaseMerchantReference,
creditorId: "DE98ZZZ09999999999",
),
),
),
),
);

$paymentResponse = $this->paymentExecutionClient->createPayment(
$this->merchantId,
$commerceCase->getCommerceCaseId(),
$commerceCase->getCheckout()->getCheckoutId(),
$paymentExecutionRequest
);
var_dump($paymentResponse);

$finalCheckout = $this->checkoutClient->getCheckout(
$this->merchantId,
$commerceCase->getCommerceCaseId(),
$commerceCase->getCheckout()->getCheckoutId(),
);
var_dump($finalCheckout);
}

protected function runMultistepCheckout(string $commercaseMerchantReference): void
{
// create the commercase
Expand Down Expand Up @@ -261,6 +352,8 @@ public function runApp(): void
// see: https://docs.payone.com/pcp/checkout-flows/step-by-step-checkout
// not that the given reference must be unique and has to renewed after each run
$this->runMultistepCheckout('com1a3b');
// creates a checkout and executes the payment in one go
$this->runCheckoutWithPaymentExecution("com1a3l");
}

public static function run(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class PaymentInformationApiClient extends BaseApiClient
public function createPaymentInformation(string $merchantId, string $commerceCaseId, string $checkoutId, PaymentInformationRequest $paymentInformationRequest): PaymentInformationResponse
{
$request = $this->createPaymentInformationRequest($merchantId, $commerceCaseId, $checkoutId, $paymentInformationRequest);
list($response) = $this->makeApiCall($request, PaymentInformationResponse::class);
return $response;
return $this->makeApiCall($request, PaymentInformationResponse::class)[0];
}

/**
Expand Down Expand Up @@ -100,8 +99,7 @@ protected function createPaymentInformationRequest(
public function getPaymentInformation(string $merchantId, string $commerceCaseId, string $checkoutId, string $paymentInformationId): PaymentInformationResponse
{
$request = $this->getPaymentInformationRequest($merchantId, $commerceCaseId, $checkoutId, $paymentInformationId);
list($response) = $this->makeApiCall($request, PaymentInformationResponse::class);
return $response;
return $this->makeApiCall($request, PaymentInformationResponse::class)[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testCreateCheckoutUnsuccessful400(): void
$createCheckoutRequest = new CreateCheckoutRequest(
amountOfMoney: new AmountOfMoney(400, 'EUR'),
);
$response = $this->checkoutClient->createCheckout('1', '2', $createCheckoutRequest);
$this->checkoutClient->createCheckout('1', '2', $createCheckoutRequest);
}

public function testCreateCheckoutUnsuccessful500(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testCancelPaymentExecutionUnsuccessful400(): void
$this->expectExceptionCode(400);

$payload = new CancelPaymentRequest(CancellationReason::FRAUDULENT);
$response = $this->paymentExecutionClient->cancelPaymentExecution('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->cancelPaymentExecution('1', '2', '3', '4', $payload);
}

public function testCancelPaymentExecutionUnsuccessful500(): void
Expand All @@ -70,7 +70,7 @@ public function testCancelPaymentExecutionUnsuccessful500(): void
$this->expectExceptionCode(500);

$payload = new CancelPaymentRequest(CancellationReason::CONSUMER_REQUEST);
$response = $this->paymentExecutionClient->cancelPaymentExecution('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->cancelPaymentExecution('1', '2', '3', '4', $payload);
}

public function capturePaymentExecutionSuccessful(): void
Expand All @@ -90,7 +90,7 @@ public function capturePaymentExecutionUnsuccessful400(): void
$this->expectExceptionCode(400);

$payload = new CapturePaymentRequest(amount: 20000, isFinal: true, cancellationReason: CancellationReason::DUPLICATE);
$response = $this->paymentExecutionClient->capturePaymentExecution('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->capturePaymentExecution('1', '2', '3', '4', $payload);
}

public function capturePaymentExecutionUnsuccessful500(): void
Expand All @@ -100,7 +100,7 @@ public function capturePaymentExecutionUnsuccessful500(): void
$this->expectExceptionCode(500);

$payload = new CapturePaymentRequest(amount: 50000, isFinal: true, cancellationReason: CancellationReason::DUPLICATE);
$response = $this->paymentExecutionClient->capturePaymentExecution('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->capturePaymentExecution('1', '2', '3', '4', $payload);
}

public function testCompletePaymentSuccessful(): void
Expand All @@ -122,7 +122,7 @@ public function testCompletePaymentUnsuccessful400(): void
$this->expectExceptionCode(400);

$payload = new CompletePaymentRequest(device: new CustomerDevice('127.0.0.1', 'token-2'));
$response = $this->paymentExecutionClient->completePayment('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->completePayment('1', '2', '3', '4', $payload);
}

public function testCompletePaymentUnsuccessful500(): void
Expand All @@ -133,7 +133,7 @@ public function testCompletePaymentUnsuccessful500(): void
$this->expectExceptionCode(500);

$payload = new CompletePaymentRequest(device: new CustomerDevice('127.0.0.1', 'token-3'));
$response = $this->paymentExecutionClient->completePayment('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->completePayment('1', '2', '3', '4', $payload);
}

public function testCreatePaymentSuccessful(): void
Expand All @@ -158,7 +158,7 @@ public function testCreatePaymentUnsuccessful400(): void
$this->expectExceptionCode(400);

$payload = new PaymentExecutionRequest(new PaymentMethodSpecificInput());
$response = $this->paymentExecutionClient->createPayment('1', '2', '3', $payload);
$this->paymentExecutionClient->createPayment('1', '2', '3', $payload);
}

public function testCreatePaymentUnsuccessful500(): void
Expand All @@ -168,7 +168,7 @@ public function testCreatePaymentUnsuccessful500(): void
$this->expectExceptionCode(500);

$payload = new PaymentExecutionRequest(new PaymentMethodSpecificInput());
$response = $this->paymentExecutionClient->createPayment('1', '2', '3', $payload);
$this->paymentExecutionClient->createPayment('1', '2', '3', $payload);
}

public function testRefundPaymentSuccessful(): void
Expand All @@ -191,7 +191,7 @@ public function testRefundPaymentUnsuccessful400(): void


$payload = new RefundRequest(return: new ReturnInformation(returnReason: 'test-reason', items: []));
$response = $this->paymentExecutionClient->refundPaymentExecution('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->refundPaymentExecution('1', '2', '3', '4', $payload);
}

public function testRefundPaymentUnsuccessful500(): void
Expand All @@ -203,6 +203,6 @@ public function testRefundPaymentUnsuccessful500(): void


$payload = new RefundRequest(return: new ReturnInformation(returnReason: 'test-reason', items: []));
$response = $this->paymentExecutionClient->refundPaymentExecution('1', '2', '3', '4', $payload);
$this->paymentExecutionClient->refundPaymentExecution('1', '2', '3', '4', $payload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public function testGetPaymentInformationUnsuccessful400(): void

public function testGetPaymentInformationUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ public function testGetters(): void
$query->setDateOfBirth("1990-02-01");
$query->setCompanyInformation("Another Company LLC");

$queryMap = $query->toQueryMap();

$this->assertEquals(2, $query->getOffset());
$this->assertEquals(20, $query->getSize());
$this->assertEquals(new DateTime("2022-02-01"), $query->getFromDate());
Expand Down

0 comments on commit f8d50bc

Please sign in to comment.