Skip to content

Instantly share code, notes, and snippets.

@stnc
Created July 23, 2020 07:06
Show Gist options
  • Select an option

  • Save stnc/13d6f97ef0bfa87f4aa4ed17869e1ee6 to your computer and use it in GitHub Desktop.

Select an option

Save stnc/13d6f97ef0bfa87f4aa4ed17869e1ee6 to your computer and use it in GitHub Desktop.
error_log_blog_example
<?php
private function creditcard_callback($postParams, $action = "")
{
$strMDStatus = isset($this->mdStatuses[$postParams["mdstatus"]]) ? $postParams["mdstatus"] : 7; // 7=Sistem hatası
if ($action == "success" && in_array($strMDStatus, array(1, 2, 3, 4))) {
// Tam Doğrulama, Kart Sahibi veya bankası sisteme kayıtlı değil, Kartın bankası sisteme kayıtlı değil, Kart sahibi sisteme daha sonra kayıt olmayı seçmiş cevaplarını alan işlemler için provizyon almaya çalışıyoruz
$strNumber = ""; // Kart bilgilerinin boş gitmesi gerekiyor
$strExpireDate = ""; // Kart bilgilerinin boş gitmesi gerekiyor
$strCVV2 = ""; // Kart bilgilerinin boş gitmesi gerekiyor
$strCardholderPresentCode = "13"; // 3D Model işlemde bu değer 13 olmalı
$strType = $postParams["txntype"];
$strMotoInd = "N";
$strAuthenticationCode = $postParams["cavv"];
$strSecurityLevel = $postParams["eci"];
$strTxnID = $postParams["xid"];
$strMD = $postParams["md"];
$SecurityData = strtoupper(sha1($this->provUserPassword . $this->terminalID_));
$HashData = strtoupper(sha1($this->orderNo . $this->terminalID . $this->amount . $SecurityData)); //Daha kısıtlı bilgileri HASH ediyoruz.
// Provizyona Post edilecek XML Şablonu
$strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<GVPSRequest>
<Mode>{$this->mode}</Mode>
<Version>{$this->version}</Version>
<ChannelCode></ChannelCode>
<Terminal>
<ProvUserID>{$this->provUserID}</ProvUserID>
<HashData>{$HashData}</HashData>
<UserID>{$this->terminalMerchantID}</UserID>
<ID>{$this->terminalID}</ID>
<MerchantID>{$this->terminalMerchantID}</MerchantID>
</Terminal>
<Customer>
<IPAddress>{$this->customerIP}</IPAddress>
<EmailAddress>{$this->customerEmail}</EmailAddress>
</Customer>
<Card>
<Number>{$strNumber}</Number>
<ExpireDate>{$strExpireDate}</ExpireDate>
<CVV2>{$strCVV2}</CVV2>
</Card>
<Order>
<OrderID>{$this->orderNo}</OrderID>
<GroupID></GroupID>
<AddressList>
<Address>
<Type>B</Type>
<Name></Name>
<LastName></LastName>
<Company></Company>
<Text></Text>
<District></District>
<City></City>
<PostalCode></PostalCode>
<Country></Country>
<PhoneNumber></PhoneNumber>
</Address>
</AddressList>
</Order>
<Transaction>
<Type>{$strType}</Type>
<InstallmentCnt>{$this->installmentCount}</InstallmentCnt>
<Amount>{$this->amount}</Amount>
<CurrencyCode>{$this->currencyCode}</CurrencyCode>
<CardholderPresentCode>{$strCardholderPresentCode}</CardholderPresentCode>
<MotoInd>{$strMotoInd}</MotoInd>
<Secure3D>
<AuthenticationCode>{$strAuthenticationCode}</AuthenticationCode>
<SecurityLevel>{$strSecurityLevel}</SecurityLevel>
<TxnID>{$strTxnID}</TxnID>
<Md>{$strMD}</Md>
</Secure3D>
</Transaction>
</GVPSRequest>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ($this->mode == "TEST" ? $this->provisionTestUrl : $this->provisionUrl));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "data=" . $strXML);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$resultContent = curl_exec($ch);
curl_close($ch);
if ($this->debugMode) {
echo '<pre>' . var_export($resultContent, true) . '</pre>';
}
$resultXML = simplexml_load_string($resultContent);
// echo '<pre>' ;
// print_r( $resultXML);
$resultXML2=$this->simpleXmlToArray($resultXML->Transaction->Response);
$resultXMLTransaction=$this->simpleXmlToArray($resultXML->Transaction);
$resultOrderID=$this->simpleXmlToArray($resultXML->Order);
// echo '<pre>' ;
// print_r( $resultXML2);
$responseCode = $resultXML->Transaction->Response->Code;
$responseMessage = $resultXML->Transaction->Response->Message;
$source = $resultXML2['Source'];
$code = $resultXML2['Code'];
$reasonCode = $resultXML2['ReasonCode'];
$message = $resultXML2['Message'];
$errorMsg = $resultXML2['ErrorMsg'];
$sysErrMsg = $resultXML2['ReasonSysErrMsgCode'];
if ($responseCode == "00" || $responseMessage == "Approved") {
$result = array(
'status' => 'success',
'message' => 'OK',
'source' => $source,
'code' => $code,
'reasonCode' => $reasonCode,
'detailMessage' => $message,
'orderID' => $resultOrderID["OrderID"],
'RetrefNum' => $resultXMLTransaction["RetrefNum"],
);
} else {
$result = array(
'status' => 'error',
'message' => $errorMsg,
'source' => $source,
'code' => $code,
'reasonCode' => $reasonCode,
'detailMessage' => $message,
'errorMsg' => $errorMsg,
'sysErrMsg' => $sysErrMsg,
'orderID' => $resultOrderID["OrderID"],
);
}
} else {
// MD status değeri Tam Doğrulama, Kart Sahibi veya bankası sisteme kayıtlı değil, Kartın bankası sisteme kayıtlı değil
//veya Kart sahibi sisteme daha sonra kayıt olmayı seçmiş haricindeyse hata mesajı alınıyor
$result = array(
'status' => 'error',
'message' => $postParams['errmsg'] ? $postParams['errmsg'] : ($postParams['ErrorMsg'] ? $postParams['ErrorMsg'] :
($postParams['mderrormessage'] ? $postParams['mderrormessage'] : ($postParams['mdErrorMsg'] ? $postParams['mdErrorMsg'] : "3D process failure"))),
'status' => 'error',
'source' => $source,
'code' => $code,
'reasonCode' => $reasonCode,
'errorMsg' => $errorMsg,
'sysErrMsg' => $sysErrMsg,
'orderID' => $resultOrderID["OrderID"],
);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment