Skip to content

Purchase (Satın Al)

Tolga Can Günel edited this page Sep 11, 2021 · 4 revisions

Create Paytr Gateway, set your merchant id, key and salt. You can get them from your Paytr panel.

Build your options, send with the method. getData method will return an object with all possible values.

$gateway = \Omnipay\Omnipay::create("Paytr");

$gateway->setMerchantId("000000");

$gateway->setMerchantKey("--------------");

$gateway->setMerchantSalt("---------------");

$gateway->setTestMode(true);

3D Secure Payment (3D Secure ile Ödeme)

$options = [
  "transactionId" => "6123ad8ba9cb76123ad8ba9cb9",
  "amount" => 12.34,
  "card" => {
    "firstName" => "Example",
    "lastName" => "User",
    "number" => "9792030394440796",
    "expiryMonth" => "12",
    "expiryYear" => "2099",
    "cvv" => "000",
    "billingAddress1" => "123 Billing St",
    "billingAddress2" => "Billsville",
    "billingCity" => "Billstown",
    "billingPostcode" => "12345",
    "billingState" => "CA",
    "billingCountry" => "TR",
    "billingPhone" => "5554443322",
    "shippingAddress1" => "123 Shipping St",
    "shippingAddress2" => "Shipsville",
    "shippingCity" => "Shipstown",
    "shippingPostcode" => "54321",
    "shippingState" => "NY",
    "shippingCountry" => "TR",
    "shippingPhone" => "5554443322"
  },
  "clientIp" => "127.0.0.1",
  "items" => [
    {
      "name" => "Perspiciatis et facilis tempore facilis.",
      "description" => "My notion was that she was talking. 'How CAN I have done that?' she thought. 'I must be a LITTLE larger, sir, if you like,' said the King and Queen of Hearts, carrying the King's crown on a.",
      "quantity" => 1,
      "price" => 12.34
    }
  ],
  "secure" => true,
  "returnUrl" => "https://paytrtest.com/omnipay/paytr/usage/payment-success.php",
  "cancelUrl" => "https://paytrtest.com/omnipay/paytr/usage/payment-failure.php"
];

Without 3D Secure Payment (3D Secure Olmadan Ödeme)

$options = [
  "transactionId" => "6123ad8ba9cb76123ad8ba9cb9",
  "amount" => 12.34,
  "card" => {
    "firstName" => "Example",
    "lastName" => "User",
    "number" => "9792030394440796",
    "expiryMonth" => "12",
    "expiryYear" => "2099",
    "cvv" => "000",
    "billingAddress1" => "123 Billing St",
    "billingAddress2" => "Billsville",
    "billingCity" => "Billstown",
    "billingPostcode" => "12345",
    "billingState" => "CA",
    "billingCountry" => "TR",
    "billingPhone" => "5554443322",
    "shippingAddress1" => "123 Shipping St",
    "shippingAddress2" => "Shipsville",
    "shippingCity" => "Shipstown",
    "shippingPostcode" => "54321",
    "shippingState" => "NY",
    "shippingCountry" => "TR",
    "shippingPhone" => "5554443322"
  },
  "clientIp" => "127.0.0.1",
  "items" => [
    {
      "name" => "Perspiciatis et facilis tempore facilis.",
      "description" => "My notion was that she was talking. 'How CAN I have done that?' she thought. 'I must be a LITTLE larger, sir, if you like,' said the King and Queen of Hearts, carrying the King's crown on a.",
      "quantity" => 1,
      "price" => 12.34
    }
  ],
  "secure" => false,
  "returnUrl" => "https://paytrtest.com/omnipay/paytr/usage/payment-success.php",
  "cancelUrl" => "https://paytrtest.com/omnipay/paytr/usage/payment-failure.php"
];

Purchase with Stored Card (Kayıt Kart ile Ödeme Yap)

$options = [
  "cardReference" => "9f0fcc05d021744e3d9df5ad1dccbba0111c2030244439ec58eac8c841d1bfcb",
  "userReference" => "f2cc71216eb234f0e27450ed6cf3d5e4f9478d3d55b015488fae40187456dea1",
  "transactionId" => "6123ad8ba9cb76123ad8ba9cb9",
  "amount" => 45.67,
  "clientIp" => "127.0.0.1",
  "items" => [
    {
      "name" => "Perspiciatis et facilis tempore facilis.",
      "description" => "My notion was that she was talking. 'How CAN I have done that?' she thought. 'I must be a LITTLE larger, sir, if you like,' said the King and Queen of Hearts, carrying the King's crown on a.",
      "quantity" => 1,
      "price" => 45.67
    }
  ],
  "secure" => true,
  "returnUrl" => "https://iparatest.com/omnipay/paytr/usage/payment-success.php",
  "cancelUrl" => "https://iparatest.com/omnipay/paytr/usage/payment-failure.php",
];

Store Card with Payment (Ödeme Yaparken Kart Kaydet)

$options = [
  "storeCard" => "1", // Save card command.
  // Optional value. 
  // If this value is not set, a new userReference will be created by Paytr and sent back.
  "userReference" => "f2cc71216eb234f0e27450ed6cf3d5e4f9478d3d55b015488fae40187456dea1",

  "transactionId" => "6123ad8ba9cb76123ad8ba9cb9",
  "amount" => 12.34,
  "card" => {
    "firstName" => "Example",
    "lastName" => "User",
    "number" => "4355084355084358",
    "expiryMonth" => "12",
    "expiryYear" => "2024",
    "cvv" => "000",
    "billingAddress1" => "123 Billing St",
    "billingAddress2" => "Billsville",
    "billingCity" => "Billstown",
    "billingPostcode" => "12345",
    "billingState" => "CA",
    "billingCountry" => "TR",
    "billingPhone" => "5554443322",
    "shippingAddress1" => "123 Shipping St",
    "shippingAddress2" => "Shipsville",
    "shippingCity" => "Shipstown",
    "shippingPostcode" => "54321",
    "shippingState" => "NY",
    "shippingCountry" => "TR",
    "shippingPhone" => "5554443322"
  },
  "clientIp" => "127.0.0.1",
  "items" => [
    {
      "name" => "Perspiciatis et facilis tempore facilis.",
      "description" => "My notion was that she was talking. 'How CAN I have done that?' she thought. 'I must be a LITTLE larger, sir, if you like,' said the King and Queen of Hearts, carrying the King's crown on a.",
      "quantity" => 1,
      "price" => 12.34
    }
  ],
  "secure" => true,
  "returnUrl" => "https://iparatest.com/omnipay/paytr/usage/payment-success.php",
  "cancelUrl" => "https://iparatest.com/omnipay/paytr/usage/payment-failure.php",
];

/** @var \Omnipay\Paytr\Message\RefundResponse $response */
$response = $gateway->purchase($options)->send();

// Whether with 3d or not, successful requests will always make a form post request.
if ($response->isRedirect()) {

    // Make a form post request to Paytr endpoint. 
    // When it is complete Paytr will redirect back to return url or cancel url.
    $response->redirect();

}else {

    // işlem gerçekleşmedi
    echo $response->getMessage();

}