Hi Roku Community,
Please Anyone help me that How to integrate Roku Pay Push Notification with laravel PHP. I'm PHP laravel developer, I'm facing difficulties to integrate roku pay push notification web services.
In our database there is three table, first> subscription_plan (Column- id,plan_name, plan_days, plan_duration, plan-duration-type, plan_price, ProductID, platform, status) second> premium-purchase(column - platform, reciept, productId, amount). Third> Transaction(column- user_id, email, plan_id, gateway, payment-amount, payment-id) .
Can anyone provide me the correct code.
I've created an endpoint that is :
public function testRokuPush(Request $request)
{
// dd($request);
$pushNotificationData = $request->json()->all();
switch ($pushNotificationData['transactionType']) {
case 'Sale':
$customerId = $pushNotificationData['customerId'];
$transactionId = $pushNotificationData['transactionId'];
$productCode = $pushNotificationData['productCode'];
$price = $pushNotificationData['price'];
$subscriptionPlan = SubscriptionPlan::where('ProductID', $productCode)->first();
// Create a premium purchase record
if ($subscriptionPlan) {
$premiumPurchase = new PremiumPurchase();
$premiumPurchase->platform = 'Roku';
$premiumPurchase->reciept = $transactionId;
$premiumPurchase->productId = $productCode;
$premiumPurchase->amount = $price;
$premiumPurchase->save();
}
// Create a transaction record
$transaction = new Transactions();
$transaction->user_id = $customerId;
$transaction->plan_id = $subscriptionPlan->id;
$transaction->gateway = 'Roku Pay';
$transaction->payment_amount = $price;
$transaction->payment_id = $transactionId;
$transaction->save();
$user = User::find($customerId);
if ($user) {
// Check if the user already has an active subscription
if ($user->plan_id == $subscriptionPlan->id && $user->exp_date > time()) {
// User already has an active subscription, no need to activate again
} else {
$user->plan_id = $subscriptionPlan->id;
$user->start_date = time();
$expirationDate = strtotime("+" . $subscriptionPlan->plan_days . " days", $user->start_date);
$user->exp_date = $expirationDate;
$user->plan_amount = $price;
$user->roku_payment_id = $transactionId;
$user->save();
}
} else {
Log::error("Subscription plan not found for product code: $productCode");
}
break;
case 'cancellation':
$customerId = $pushNotificationData['customerId'];
$transactionId = $pushNotificationData['transactionId'];
$productCode = $pushNotificationData['productCode'];
$user = User::find($customerId);
break;
default:
break;
}
$responseKey = $pushNotificationData['responseKey'];
$apiKey = 'YOUR_ROKU_PAY_API_KEY';
return response($responseKey, 200)
->header('ApiKey', $apiKey)
->header('Content-Length', strlen($responseKey));
}