Initialization
Merchant will initialize the mandatory parameters i.e. environment, mid, key, and website, after which merchant can directly call SDK methods to call APIs of payment gateway.
// For Staging
$environment = LibraryConstants::STAGING_ENVIRONMENT;
// For Production
// $environment = LibraryConstants::PRODUCTION_ENVIRONMENT;
// Find your mid, key, website in your Paytm Dashboard at https://dashboard.paytmpayments.com/next/apikeys
$mid = "YOUR_MID_HERE";
$key = "YOUR_KEY_HERE";
$website = "YOUR_WEBSITE_NAME";
$client_id = "YOUR_CLIENT_ID_HERE";
$callbackUrl = "MERCHANT_CALLBACK_URL";
MerchantProperties::setCallbackUrl($callbackUrl);
MerchantProperties::initialize($environment, $mid, $key, $client_id, $website);
// If you want to add log file to your project, use below code
Config::$monologName = '[PAYTM]';
Config::$monologLevel = MonologLogger::INFO;
Config::$monologLogfile = '/path/log/file.log';
Note: Make sure the log file (/path/log/file.log) has write permission.
Payments
Create Transaction Token
$channelId = EChannelId::WEB;
$orderId = "UNIQUE_ORDER_ID";
$txnAmount = Money::constructWithCurrencyAndValue(EnumCurrency::INR, "1.00");
$userInfo = new UserInfo("CUSTOMER_ID");
$userInfo->setAddress("CUSTOMER_ADDRESS");
$userInfo->setEmail("CUSTOMER_EMAIL_ID");
$userInfo->setFirstName("CUSTOMER_FIRST_NAME");
$userInfo->setLastName("CUSTOMER_LAST_NAME");
$userInfo->setMobile("CUSTOMER_MOBILE_NO");
$userInfo->setPincode("CUSTOMER_PINCODE");
$paymentDetailBuilder = new PaymentDetailBuilder($channelId, $orderId, $txnAmount, $userInfo);
$paymentDetail = $paymentDetailBuilder->build();
$response = Payment::createTxnToken($paymentDetail);
GetPaymentStatus
$orderId = "YOUR_ORDER_ID";
$readTimeout = 80000;
$paymentStatusDetailBuilder = new PaymentStatusDetailBuilder($orderId);
$paymentStatusDetail = $paymentStatusDetailBuilder->setReadTimeout($readTimeout)->build();
$response = Payment::getPaymentStatus($paymentStatusDetail);
Refunds
InitiateRefund
$orderId = "YOUR_ORDER_ID";
$refId = "REFERENCE_ID";
$txnId = "TRANSACTION_ID";
$txnType = "REFUND";
$refundAmount = "1";
$readTimeout = 80000;
$subWalletAmount = array();
$subWalletAmount[UserSubWalletType::FOOD] = 1.00;
$subWalletAmount[UserSubWalletType::GIFT] = 1.00;
$refund = new RefundDetailBuilder($orderId,
$refId, $txnId, $txnType, $refundAmount);
$refundDetail = $refund->setReadTimeout($readTimeout)
->setSubwalletAmount($subWalletAmount)
->build();
$response = Refund::initiateRefund($refundDetail);
GetRefundStatus
$orderId = "YOUR_ORDER_ID";
$refId = "REFERENCE_ID";
$readTimeout = 8000;
$refundStatusDetailBuilder = new RefundStatusDetailBuilder($orderId, $refId);
$refundStatusDetail = $refundStatusDetailBuilder->setReadTimeout($readTimeout)->build();
$response = Refund::getRefundStatus($refundStatusDetail);
SDK Method References
Class |
Methods |
HTTP request |
Description |
Payments
|
createTxnToken |
POST/theia/api/v1/initiateTransaction |
Returns a token which will be used further in frontend payment calls |
getPaymentStatus |
POST/merchant-status/api/v1/getPaymentStatus |
Returns the payment status |
Refunds
|
initiateRefund |
POST/refund/api/v1/async/refund |
Initiates the refund |
getRefundStatus |
POST/refund/api/v1/refundStatus |
Returns the refund status |