-
|
Following up with the example provided to handle subscription purchase events. Code in my "AutoRenewSubscriptionPlayStore" Listener class AutoRenewSubscriptionPlayStore
{
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle(SubscriptionRenewed $event)
{
Log::info($event);
$notification = $event->getServerNotification();
$subscription = $notification->getSubscription();
$uniqueIdentifier = $subscription->getUniqueIdentifier();
$expirationTime = $subscription->getExpiryTime();
$userId = User::findUserBySubscriptionId($uniqueIdentifier,'PlayStore');
$user = User::find($userId);
$subscription = UserSubscription::where('subscription_id',$uniqueIdentifier)->where('user_id',$userId)->first();
$subscription->subscription_ends = $expirationTime;
$subscription->save();
$file = (isset($user->profile_picture)) ? $user->profile_picture : (($user->mediaImages->count() > 0) ? $user->profile_image : '');
$image = generateS3FilePath($file);
event(new SendPushNotification($user->id, trans('notification.subscription_updated'), array(trans('notification.subscription_updated'),'Subscription Updated',$image)));
}
}@imdhemy Help needed |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 22 replies
-
|
Did you make all the following steps? Google Play
App Store
SummaryThe config file |
Beta Was this translation helpful? Give feedback.
-
|
Don't know why but I can still see the similar error in logs due to which around 96% of the request to my server throws 500 error. ** ** It logs the same : |
Beta Was this translation helpful? Give feedback.
-
|
The problem with the weird Google Pay Payload is simply its pub-sub behavior which sends an empty payload when there are no valid subscriptions available to handle for a particular span of time. if (! $this->isParsable($data)) {
Log::info(sprintf("Google Play malformed RTDN: %s", json_encode($request->all())));
return;
} |
Beta Was this translation helpful? Give feedback.
-
|
Hi @imdhemy <?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
//use Imdhemy\Purchases\Events\GooglePlay\SubscriptionRenewed;
use Imdhemy\GooglePlay\Subscriptions\SubscriptionPurchase;
use Imdhemy\Purchases\Facades\Subscription;
use Illuminate\Support\Facades\Log;
use Imdhemy\Purchases\Events\PurchaseEvent;
use Imdhemy\Purchases\Contracts\ServerNotificationContract;
use Imdhemy\Purchases\ValueObjects\Time;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPurchased;
use App\Models\Table;
class SubscribeNotification
{
protected $event;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param Subscribe $event
* @return void
*/
public function handle(SubscriptionPurchased $event)
{
Log::info($event);
$notification = $event->getServerNotification();
$subscription = $notification->getSubscription();
$uniqueIdentifier = $subscription->getUniqueIdentifier();
$skuId = $subscription->getItemId();
$provider = $subscription->getProvider();
$subscriptionReceipt = Subscription::googlePlay()->id($skuId)->token($uniqueIdentifier)->get();
// Start Time
$StartTime = $subscriptionReceipt->getStartTime();
$data1= $StartTime->toDateTime();
$dateTime1 = json_encode($data1);
$Timedate1 = json_decode($dateTime1);
$str_time = $Timedate1->date;
//Expire Time
$ExpireTime = $subscriptionReceipt->getExpiryTime();
$data2= $ExpireTime->toDateTime();
$dateTime2 = json_encode($data2);
$Timedate2 = json_decode($dateTime2);
$exp_time = $Timedate2->date;
// save in sb
$data = new Table();
$data['purchase_token'] = $uniqueIdentifier;
$data['order_id'] = $subscriptionReceipt->getOrderId();
$data['start_time'] = $str_time;
$data['expire_time'] = $exp_time;
$data['sku_id'] = $skuId;
$data['price'] = '';
$data['provider'] = $provider;
$data['plan_status'] = 'Active';
$data['renew'] = 'No';
$data->save();
Log::info(sprintf("Google Play Purchases, version: %s", 1));
Log::info(sprintf("Google Play Test Notification, version: %s", $skuId));
Log::info(sprintf("Google Play Test Notification, version: %s", $uniqueIdentifier));
Log::info(sprintf("Google Play Test Notification, version: %s", $provider));
//Log::info(sprintf("Google Play Test Notification, version: %s", $expirationTime));
}
}Regards |
Beta Was this translation helpful? Give feedback.
-
|
Hi @imdhemy I am also using this package and followed all the installation steps mentioned in https://imdhemy.com/laravel-iap-docs/ My code is as follows:- [ 'signed' => false, ], 'google_play_package_name' => env('GOOGLE_PLAY_PACKAGE_NAME', 'com.some.thing'), 'appstore_password' => env('APPSTORE_PASSWORD', 'XXXXXXX'), 'appstore_sandbox' => env('APPSTORE_SANDBOX', true), 'eventListeners' => [ /** * -------------------------------------------------------- * Google Play Events * -------------------------------------------------------- */ SubscriptionPurchased::class => [], SubscriptionRenewed::class => [], SubscriptionInGracePeriod::class => [], SubscriptionExpired::class => [], SubscriptionCanceled::class => [], SubscriptionPaused::class => [], SubscriptionRestarted::class => [], SubscriptionDeferred::class => [], SubscriptionRevoked::class => [], SubscriptionOnHold::class => [], SubscriptionRecovered::class => [], SubscriptionPauseScheduleChanged::class => [], SubscriptionPriceChangeConfirmed::class => [], /** * -------------------------------------------------------- * App Store Events * -------------------------------------------------------- */ Cancel::class => [\App\Listeners\Subscription\Apple\SubscriptionCanceledListener::class], DidChangeRenewalPref::class => [], DidChangeRenewalStatus::class => [], DidFailToRenew::class => [], DidRecover::class => [\App\Listeners\Subscription\Apple\SubscriptionDidRecoverListener::class], DidRenew::class => [\App\Listeners\Subscription\Apple\SubscriptionDidRenewListener::class], InitialBuy::class => [\App\Listeners\Subscription\Apple\SubscriptionPurchasedListener::class], InteractiveRenewal::class => [], PriceIncreaseConsent::class => [], Refund::class => [], Revoke::class => [], ], ]; Code of one of my listener is as follows:- getServerNotification()->getSubscription(); $uniqueIdentifier = $subscription->getUniqueIdentifier(); $expirationTime = $subscription->getExpiryTime(); $item_id = $subscription->getItemId(); Log::info(array("data"=> $notification,"uniqueIdentifier"=> $uniqueIdentifier,"expirationTime"=> $expirationTime,"item_id"=> $item_id)); $subscription = $notification->getSubscription(); Log::info(array("subscription"=> $subscription,'name'=>"didrenew")); // $data = UserSubscriptionHistory::googleHisUpdateOrCreate($subscription, $item_id, 'canceled'); // if ($data) { // UserSubscriptionHistory::SubscriptionFirebaseNotification($data, 'canceled'); // } } catch(\Exception $e){ Log::info($e->getMessage()); } } } But no notification is received. Can you please help me to debug the issue. Thanks |
Beta Was this translation helpful? Give feedback.
-
|
Make sure you did the following:
Side Notes:
|
Beta Was this translation helpful? Give feedback.
Did you make all the following steps?
Google Play
purchase.php, attach the created listener to the proper event.App Store
purchase.php, attach the created listener to the proper event.Summary
The config file
purchase.php, contains two separate groups for different purchase events, be sure to attach the listener to the proper event for google or apple after settin…