136 lines
6.5 KiB
PHP
Executable File
136 lines
6.5 KiB
PHP
Executable File
<?php
|
|
$nomFicAppelant = basename(__FILE__);
|
|
// To switch to Production mode, please init the configuration with: Configuration::API_ENV_PRODUCTION
|
|
|
|
// Create a configuration object
|
|
// By default Configuration object is configured in Stage mode (Configuration::API_ENV_STAGE)
|
|
$config = new \HiPay\Fullservice\HTTP\Configuration\Configuration("username","password");
|
|
|
|
// Instantiate client provider with configuration object
|
|
$clientProvider = new \HiPay\Fullservice\HTTP\SimpleHTTPClient($config);
|
|
|
|
// Create your gateway client
|
|
$gatewayClient = new \HiPay\Fullservice\Gateway\Client\GatewayClient($clientProvider);
|
|
|
|
|
|
$orderRequest = new \HiPay\Fullservice\Gateway\Request\Order\OrderRequest();
|
|
$orderRequest->orderid = "ORDER #123456";
|
|
$orderRequest->operation = "Sale";
|
|
$orderRequest->payment_product = "visa";
|
|
$orderRequest->description = "ref_85";
|
|
$orderRequest->firstname = "Jane";
|
|
$orderRequest->lastname = "Doe";
|
|
$orderRequest->email = "jane.doe@unknow.com";
|
|
$orderRequest->currency = "EUR";
|
|
$orderRequest->amount = "21.60";
|
|
$orderRequest->shipping = "0.00";
|
|
$orderRequest->tax = "3.6";
|
|
$orderRequest->cid = null;
|
|
$orderRequest->ipaddr = "172.20.0.1";
|
|
$orderRequest->accept_url = "http:/www.my-shop.fr/checkout/accept";
|
|
$orderRequest->decline_url = "http:/www.my-shop.fr/checkout/decline";
|
|
$orderRequest->pending_url = "http:/www.my-shop.fr/checkout/pending";
|
|
$orderRequest->exception_url = "http:/www.my-shop.fr/checkout/exeception";
|
|
$orderRequest->cancel_url = "http:/www.my-shop.fr/checkout/cancel";
|
|
$orderRequest->http_accept = "*/*";
|
|
$orderRequest->http_user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
|
|
$orderRequest->language = "en_US";
|
|
$orderRequest->custom_data = "{\"shipping_description\":\"Flat rate\",\"payment_code\":\"visa\",\"display_iframe\":0}";
|
|
$orderRequest->authentication_indicator = 0;
|
|
|
|
// $paymentMethod = new \HiPay\Fullservice\Gateway\Request\PaymentMethod\CardTokenPaymentMethod();
|
|
// $paymentMethod->cardtoken = "61f92d7a135db52dbd583b2aad208e73978196392357f674bacf39f549042f14";
|
|
// $paymentMethod->eci = 7;
|
|
// $paymentMethod->authentication_indicator = 0;
|
|
// $orderRequest->paymentMethod = $paymentMethod;
|
|
|
|
|
|
|
|
|
|
// These two objects are related to the delivery and billing addresses. You can find the same type of information on both objects
|
|
$customerShippingInfo = new \HiPay\Fullservice\Gateway\Request\Info\CustomerShippingInfoRequest();
|
|
$customerShippingInfo->shipto_firstname = "Jane";
|
|
$customerShippingInfo->shipto_lastname = "Doe";
|
|
$customerShippingInfo->shipto_streetaddress = "56 avenue de la paix";
|
|
$customerShippingInfo->shipto_streetaddress2 = "";
|
|
$customerShippingInfo->shipto_city = "Paris";
|
|
$customerShippingInfo->shipto_state = "";
|
|
$customerShippingInfo->shipto_zipcode = "75000";
|
|
$customerShippingInfo->shipto_country = "FR";
|
|
$customerShippingInfo->shipto_phone = "0130811322";
|
|
$customerShippingInfo->shipto_msisdn = "0600000000";
|
|
$customerShippingInfo->shipto_gender = "M";
|
|
|
|
$orderRequest->customerShippingInfo = $customerShippingInfo;
|
|
|
|
// Make a request and return \HiPay\Fullservice\Gateway\Model\Transaction.php object
|
|
$transaction = $gatewayClient->requestNewOrder($orderRequest);
|
|
|
|
|
|
$forwardUrl = $transaction->getForwardUrl();
|
|
switch ($transaction->getState()) {
|
|
case TransactionState::COMPLETED:
|
|
case TransactionState::PENDING:
|
|
$redirectUrl = "YOUR_URL_FOR_PENDING_PAYMENT";
|
|
break;
|
|
case TransactionState::FORWARDING:
|
|
$redirectUrl = $forwardUrl;
|
|
break;
|
|
case TransactionState::DECLINED:
|
|
$reason = $response->getReason();
|
|
$this->logErrors('There was an error requesting new transaction: ' . $reason['message']);
|
|
throw new Payment_Exception('Sorry, your payment has been declined. Please try again with an other means of payment. ');
|
|
case TransactionState::ERROR:
|
|
$redirectUrl = 'YOUR_URL_FOR_ERROR_PAYMENT';
|
|
$reason = $response->getReason();
|
|
$this->logErrors('There was an error requesting new transaction: ' . $reason['message']);
|
|
throw new Payment_Exception('An error occured, process has been cancelled. ');
|
|
default:
|
|
throw new Payment_Exception('An error occured, process has been cancelled. ');
|
|
}
|
|
|
|
return $redirectUrl;
|
|
|
|
|
|
|
|
|
|
$hpaymentRequest = new \HiPay\Fullservice\Gateway\Request\Order\HostedPaymentPageRequest();
|
|
$hpaymentRequest->orderid = "ORDER #123456";
|
|
$hpaymentRequest->operation = "Sale";
|
|
$hpaymentRequest->description = "ref_85";
|
|
$hpaymentRequest->firstname = "Jane";
|
|
$hpaymentRequest->lastname = "Doe";
|
|
$hpaymentRequest->email = "jane.doe@unknow.com";
|
|
$hpaymentRequest->currency = "EUR";
|
|
$hpaymentRequest->amount = "21.60";
|
|
$hpaymentRequest->shipping = "0.00";
|
|
$hpaymentRequest->tax = "3.6";
|
|
$hpaymentRequest->cid = null;
|
|
$hpaymentRequest->ipaddr = "172.20.0.1";
|
|
$hpaymentRequest->accept_url = "http:/www.my-shop.fr/checkout/accept";
|
|
$hpaymentRequest->decline_url = "http:/www.my-shop.fr/checkout/decline";
|
|
$hpaymentRequest->pending_url = "http:/www.my-shop.fr/checkout/pending";
|
|
$hpaymentRequest->exception_url = "http:/www.my-shop.fr/checkout/exeception";
|
|
$hpaymentRequest->cancel_url = "http:/www.my-shop.fr/checkout/cancel";
|
|
$hpaymentRequest->http_accept = "*/*";
|
|
$hpaymentRequest->http_user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
|
|
$hpaymentRequest->language = "en_US";
|
|
$hpaymentRequest->authentication_indicator = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hpaymentRequest->payment_product_list = "visa,mastercard,cb,maestro,american-express";
|
|
$hpaymentRequest->payment_product_category_list = "";
|
|
$hpaymentRequest->css = "";
|
|
$hpaymentRequest->template = "basic-js";
|
|
$hpaymentRequest->display_selector = "1";
|
|
$hpaymentRequest->time_limit_to_pay = 3000;
|
|
$hpaymentRequest->multi_use = 0;
|
|
|
|
// Make a request and return \HiPay\Fullservice\Gateway\Model\Transaction.php object
|
|
$transaction = $gatewayClient->requestHostedPaymentPage($hpaymentRequest);
|
|
$forwardUrl = $transaction->getForwardUrl();
|
|
?>
|