Skip to content

Instantly share code, notes, and snippets.

@eksahin
Last active August 29, 2015 14:24
Show Gist options
  • Save eksahin/b60279149a5d7955c3aa to your computer and use it in GitHub Desktop.
Save eksahin/b60279149a5d7955c3aa to your computer and use it in GitHub Desktop.
/**
* Ödeme isteği bu method ile başlıyor.
*/
public function paymentRequest(PaymentContext $ctx)
{
// parametreker array tipine çevriliyor.
$params = $this->getDailyPaymentRequestParameters($ctx);
// parametreler serialize ediliyor.
$serializedParams = $this->serializeRequest($params);
// curl yapılıyor.
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $this->endPoint);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_POST, count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS, $serializedParams);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
$params['status'] = $response->response->state;
var_dump($response);exit;
}
public function getContextData(PaymentContext $ctx) {
return array(
'context' => array(
'uniqueTitle' => $ctx->getUniqueTitle(),
'cityId' => $ctx->getCity()->getId(),
'ip' => $ctx->getCustomerIP(),
'price' => $ctx->getPrice(),
'phone' => $ctx->getPhoneNumber(),
'email' => $ctx->getEmail(),
)
);
}
/**
* @param $data
*/
private function serializeRequest($data){
if($data == null || !isset($data)){
throw new \Exception("Parametreler boş olamaz!");
}
$result = '';
foreach($data as $key=>$value) {
$result .= $key.'='.$value.'&';
}
rtrim($result, '&');
return $result;
}
/**
* @param PaymentContext $ctx
* @return array
*/
public function getDailyPaymentRequestParameters(PaymentContext $ctx)
{
return array(
"api_id" => $this->secretKey,
"secret" => $this->apiId,
"response_mode" => "SYNC",
"mode" => $this->mode,
"type" => "DB",
"amount" => $ctx->getPrice(),
'card_holder_name' => '',
"currency" => "TRY",
"customer_first_name" => $ctx->getCustomerFirstName(),
"customer_last_name" => $ctx->getCustomerLastName(),
"customer_contact_ip" => $ctx->getCustomerIP(),
'customer_contact_email' => $ctx->getEmail(),
'customer_contact_mobile' => $ctx->getPhoneNumber(),
"connector_type" => "Garanti",
"card_token" => $ctx->getCardToken()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment