-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-test-ingenico-create-hosted-checkout.php
81 lines (61 loc) · 3.55 KB
/
01-test-ingenico-create-hosted-checkout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
use Ingenico\Connect\Sdk\Client as ClientAlias;
use Ingenico\Connect\Sdk\Communicator as CommunicatorAlias;
use Ingenico\Connect\Sdk\CommunicatorConfiguration as CommunicatorConfigurationAlias;
use Ingenico\Connect\Sdk\DefaultConnection as DefaultConnectionAlias;
use Ingenico\Connect\Sdk\Domain\Hostedcheckout\CreateHostedCheckoutRequest;
use Ingenico\Connect\Sdk\Domain\Payment\Definitions\Order as OrderAlias;
use Ingenico\Connect\Sdk\Domain\Definitions\Card;
use Ingenico\Connect\Sdk\Domain\Payment\Definitions\CardPaymentMethodSpecificInput;
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
//$callContext = new CallContext();
//$callContext->setIdempotenceKey($idempotenceKey);
$logFile = fopen('hosted-checkout-test.log','a');
$communicatorConfiguration =
new CommunicatorConfigurationAlias(
$_ENV['API_KEY'], $_ENV['API_SECRET'], 'https://eu.sandbox.api-ingenico.com', 'GSped'
);
$connection = new DefaultConnectionAlias();
$communicator = new CommunicatorAlias($connection, $communicatorConfiguration);
$client = new ClientAlias($communicator);
$client->setClientMetaInfo(json_encode(['msg'=>"consumer specific JSON meta info"]));
$client->enableLogging(new \Ingenico\Connect\Sdk\ResourceLogger($logFile));
$amountOfMoney = new \Ingenico\Connect\Sdk\Domain\Definitions\AmountOfMoney();
$amountOfMoney->amount = 3500;
$amountOfMoney->currencyCode = "USD";
$billingAddress = new \Ingenico\Connect\Sdk\Domain\Definitions\Address();
$billingAddress->countryCode = "IT";
$customer = new \Ingenico\Connect\Sdk\Domain\Payment\Definitions\Customer();
$customer->locale = "it_IT";
$customer->billingAddress = $billingAddress;
$order = new OrderAlias();
$order->amountOfMoney = $amountOfMoney;
$order->customer = $customer;
$body = new CreateHostedCheckoutRequest();
$body->order = $order;
$cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
$cardPaymentMethodSpecificInput->authorizationMode = 'SALE';
$body->cardPaymentMethodSpecificInput = $cardPaymentMethodSpecificInput;
$hcsi = new \Ingenico\Connect\Sdk\Domain\Hostedcheckout\Definitions\HostedCheckoutSpecificInput();
$hcsi->returnUrl = $_ENV['RETURN_URL'] ?? 'https://www.gsped.it';
$hcsi->showResultPage = true;
$body->hostedCheckoutSpecificInput = $hcsi;
$body->hostedCheckoutSpecificInput->paymentProductFilters = new \Ingenico\Connect\Sdk\Domain\Hostedcheckout\Definitions\PaymentProductFiltersHostedCheckout();
$body->hostedCheckoutSpecificInput->paymentProductFilters->restrictTo = new \Ingenico\Connect\Sdk\Domain\Definitions\PaymentProductFilter();
$body->hostedCheckoutSpecificInput->paymentProductFilters->restrictTo->groups = ['cards'];
//$body->hostedCheckoutSpecificInput->paymentProductFilters->restrictTo->products = [1];
//$response = $client->merchant(2502)->hostedcheckouts()->create($body);
$response = $client->merchant(1221)->hostedcheckouts()->create($body);
// questi vanno salvati
printf("RETURNMAC : %s\n",$response->RETURNMAC);
printf("partialRedirectUrl: %s\n",$response->partialRedirectUrl);
printf("merchantReference : %s\n",$response->merchantReference?:'merchantReference is EMPTY !!');
printf("\nPlease, complete payment on: %s\n\n",'https://payment.'.$response->partialRedirectUrl);
printf("Select VISA payment method\n");
printf("Use this CC number test case : %s\n",'4012000033330026');
printf("Use this CC CCV : %s\n",'123');
printf("Use this CC expiry date : %s\n",'0624');
printf("\nCall this php script after completing online payment\n> php 02-test-ingenico-get-status.php %s\n",
$response->hostedCheckoutId);