Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #172 - upgrade KuveytPos version to TDV2.0.0 #194

Merged
merged 7 commits into from
Apr 23, 2024
Merged
4 changes: 2 additions & 2 deletions config/pos_production.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
'name' => 'kuveyt-pos',
'class' => Mews\Pos\Gateways\KuveytPos::class,
'gateway_endpoints' => [
'payment_api' => 'https://boa.kuveytturk.com.tr/sanalposservice/Home/ThreeDModelProvisionGate',
'gateway_3d' => 'https://boa.kuveytturk.com.tr/sanalposservice/Home/ThreeDModelPayGate',
'payment_api' => 'https://sanalpos.kuveytturk.com.tr/ServiceGateWay/Home/ThreeDModelProvisionGate',
'gateway_3d' => 'https://sanalpos.kuveytturk.com.tr/ServiceGateWay/Home/ThreeDModelPayGate',
'query_api' => 'https://boa.kuveytturk.com.tr/BOA.Integration.WCFService/BOA.Integration.VirtualPos/VirtualPosService.svc?wsdl',
],
],
Expand Down
33 changes: 33 additions & 0 deletions docs/THREED-PAYMENT-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,39 @@ try {
}
});

// KuveytVos TDV2.0.0 icin ozel biri durum
$eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $requestDataPreparedEvent) use ($pos): void {
if (get_class($pos) !== \Mews\Pos\Gateways\KuveytPos::class) {
return;
}
// KuveytPos TDV2.0.0 icin zorunlu eklenmesi gereken ekstra alanlar:
$additionalRequestDataForKuveyt = [
'DeviceData' => [
//2 karakter olmalıdır. 01-Mobil, 02-Web Browser için kullanılmalıdır.
'DeviceChannel' => '02',
],
'CardHolderData' => [
'BillAddrCity' => 'İstanbul',
// ISO 3166-1 sayısal üç haneli ülke kodu standardı kullanılmalıdır.
'BillAddrCountry' => '792',
'BillAddrLine1' => 'XXX Mahallesi XXX Caddesi No 55 Daire 1',
'BillAddrPostCode' => '34000',
// ISO 3166-2'de tanımlı olan il/eyalet kodu olmalıdır.
'BillAddrState' => '40',
'Email' => '[email protected]',
'MobilePhone' => [
'Cc' => '90',
'Subscriber' => '1234567899',
],
],
];
$requestData = $requestDataPreparedEvent->getRequestData();
$requestData = array_merge_recursive($requestData, $additionalRequestDataForKuveyt);
$requestDataPreparedEvent->setRequestData($requestData);
});

$formData = $pos->get3DFormData(
$order,
$paymentModel,
Expand Down
65 changes: 65 additions & 0 deletions examples/_common-codes/3d/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,71 @@
*/
});

// KuveytVos TDV2.0.0 icin ozel biri durum
$eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $requestDataPreparedEvent) use ($pos): void {
if (get_class($pos) !== \Mews\Pos\Gateways\KuveytPos::class) {
return;
}
// KuveytPos TDV2.0.0 icin zorunlu eklenmesi gereken ekstra alanlar:
$additionalRequestDataForKuveyt = [
'DeviceData' => [
/**
* DeviceChannel : DeviceData alanı içerisinde gönderilmesi beklenen işlemin yapıldığı cihaz bilgisi.
* 2 karakter olmalıdır. 01-Mobil, 02-Web Browser için kullanılmalıdır.
*/
'DeviceChannel' => '02',
],
'CardHolderData' => [
/**
* BillAddrCity: Kullanılan kart ile ilişkili kart hamilinin fatura adres şehri.
* Maksimum 50 karakter uzunluğunda olmalıdır.
*/
'BillAddrCity' => 'İstanbul',
/**
* BillAddrCountry Kullanılan kart ile ilişkili kart hamilinin fatura adresindeki ülke kodu.
* Maksimum 3 karakter uzunluğunda olmalıdır.
* ISO 3166-1 sayısal üç haneli ülke kodu standardı kullanılmalıdır.
*/
'BillAddrCountry' => '792',
/**
* BillAddrLine1: Kullanılan kart ile ilişkili kart hamilinin teslimat adresinde yer alan sokak vb. bilgileri içeren açık adresi.
* Maksimum 150 karakter uzunluğunda olmalıdır.
*/
'BillAddrLine1' => 'XXX Mahallesi XXX Caddesi No 55 Daire 1',
/**
* BillAddrPostCode: Kullanılan kart ile ilişkili kart hamilinin fatura adresindeki posta kodu.
*/
'BillAddrPostCode' => '34000',
/**
* BillAddrState: CardHolderData alanı içerisinde gönderilmesi beklenen ödemede kullanılan kart ile ilişkili kart hamilinin fatura adresindeki il veya eyalet bilgisi kodu.
* ISO 3166-2'de tanımlı olan il/eyalet kodu olmalıdır.
*/
'BillAddrState' => '40',
/**
* Email: Kullanılan kart ile ilişkili kart hamilinin iş yerinde oluşturduğu hesapta kullandığı email adresi.
* Maksimum 254 karakter uzunluğunda olmalıdır.
*/
'Email' => '[email protected]',
'MobilePhone' => [
/**
* Cc: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait ülke kodu. 1-3 karakter uzunluğunda olmalıdır.
*/
'Cc' => '90',
/**
* Subscriber: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait abone numarası.
* Maksimum 15 karakter uzunluğunda olmalıdır.
*/
'Subscriber' => '1234567899',
],
],
];
$requestData = $requestDataPreparedEvent->getRequestData();
$requestData = array_merge_recursive($requestData, $additionalRequestDataForKuveyt);
$requestDataPreparedEvent->setRequestData($requestData);
});

/**
* Bu Event'i dinleyerek 3D formun hash verisi hesaplanmadan önce formun input array içireğini güncelleyebilirsiniz.
*/
Expand Down
4 changes: 2 additions & 2 deletions examples/kuveytpos/3d/_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
$account = \Mews\Pos\Factory\AccountFactory::createKuveytPosAccount(
'kuveytpos',
'496',
'apiuser1',
'apitest',
'400235',
'Api1232',
'api123',
PosInterface::MODEL_3D_SECURE
);

Expand Down
9 changes: 5 additions & 4 deletions examples/kuveytpos/_payment_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

$testCards = [
'visa1' => [
'number' => '4155650100416111',
//Kart Doğrulama Şifresi: 123456
'number' => '5188961939192544',
'year' => '25',
'month' => '1',
'cvv' => '123',
'month' => '06',
'cvv' => '929',
'name' => 'John Doe',
'type' => CreditCardInterface::CARD_TYPE_VISA,
'type' => CreditCardInterface::CARD_TYPE_MASTERCARD,
],
];
13 changes: 8 additions & 5 deletions src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class KuveytPosRequestDataMapper extends AbstractRequestDataMapper
{
/** @var string */
public const API_VERSION = '1.0.0';
public const API_VERSION = 'TDV2.0.0';

/** @var string */
public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';
Expand All @@ -39,10 +39,10 @@ class KuveytPosRequestDataMapper extends AbstractRequestDataMapper
* {@inheritDoc}
*/
protected array $txTypeMappings = [
PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
PosInterface::TX_TYPE_CANCEL => 'SaleReversal',
PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail',
PosInterface::TX_TYPE_REFUND => 'PartialDrawback', // Also there is a "Drawback"
PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
PosInterface::TX_TYPE_CANCEL => 'SaleReversal',
PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail',
PosInterface::TX_TYPE_REFUND => 'Drawback', // Also there is a "PartialDrawback"
];

/**
Expand Down Expand Up @@ -133,6 +133,9 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
'MerchantOrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
'DeviceData' => [
'ClientIP' => $order['ip'],
],
];

if ($creditCard instanceof CreditCardInterface) {
Expand Down
33 changes: 25 additions & 8 deletions src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public function mapStatusResponse(array $rawResponseData): array
$defaultResponse = $this->getDefaultStatusResponse($rawResponseData);

if (!isset($data['OrderContract'])) {
if (isset($rawResponseData['GetMerchantOrderDetailResult']['Results']['Result'])) {
$rawResult = $rawResponseData['GetMerchantOrderDetailResult']['Results']['Result'];
$defaultResponse['error_code'] = $rawResult['ErrorCode'];
$defaultResponse['error_message'] = $rawResult['ErrorMessage'];
}

return $defaultResponse;
}

Expand Down Expand Up @@ -198,8 +204,9 @@ public function mapRefundResponse(array $rawResponseData): array
'all' => $rawResponseData,
];

$drawbackResult = $rawResponseData['PartialDrawbackResult'] ?? $rawResponseData['DrawBackResult'];
$value = $drawbackResult['Value'];

$value = $rawResponseData['PartialDrawbackResult']['Value'];
$procReturnCode = $this->getProcReturnCode($value);

if (null === $procReturnCode) {
Expand All @@ -210,11 +217,16 @@ public function mapRefundResponse(array $rawResponseData): array
$status = self::TX_APPROVED;
}

$responseResults = $rawResponseData['PartialDrawbackResult']['Results'];
$responseResults = $drawbackResult['Results'];
if (self::TX_APPROVED !== $status && isset($responseResults['Result']) && [] !== $responseResults['Result']) {
$responseResult = $responseResults['Result'][0];
$result['error_code'] = $responseResult['ErrorCode'];
$result['error_message'] = $responseResult['ErrorMessage'];
if (isset($responseResults['Result'][0])) {
$responseResult = $responseResults['Result'][0];
} else {
$responseResult = $responseResults['Result'];
}
$result['proc_return_code'] = $procReturnCode;
$result['error_code'] = $responseResult['ErrorCode'] ?? $procReturnCode;
$result['error_message'] = $responseResult['ErrorMessage'];

return $result;
}
Expand Down Expand Up @@ -269,9 +281,14 @@ public function mapCancelResponse(array $rawResponseData): array

$responseResults = $rawResponseData['SaleReversalResult']['Results'];
if (self::TX_APPROVED !== $status && isset($responseResults['Result']) && [] !== $responseResults['Result']) {
$responseResult = $responseResults['Result'][0];
$result['error_code'] = $responseResult['ErrorCode'];
$result['error_message'] = $responseResult['ErrorMessage'];
if (isset($responseResults['Result'][0])) {
$responseResult = $responseResults['Result'][0];
} else {
$responseResult = $responseResults['Result'];
}
$result['proc_return_code'] = $procReturnCode;
$result['error_code'] = $responseResult['ErrorCode'] ?? $procReturnCode;
$result['error_message'] = $responseResult['ErrorMessage'];

return $result;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Gateways/KuveytPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ protected function sendSoapRequest(array $contents, string $txType, string $url
throw new RuntimeException('Bankaya istek başarısız!');
}

return $this->serializer->decode($result, $txType);
$encodedResult = \json_encode($result);

if (false === $encodedResult) {
return [];
}

return $this->serializer->decode($encodedResult, $txType);
}

/**
Expand Down
Loading