<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohsin Ali Soomro on Medium]]></title>
        <description><![CDATA[Stories by Mohsin Ali Soomro on Medium]]></description>
        <link>https://medium.com/@mohsinalisoomro23?source=rss-12987dda425------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rwEaU1ZzkemyTTjbFTmMWA.jpeg</url>
            <title>Stories by Mohsin Ali Soomro on Medium</title>
            <link>https://medium.com/@mohsinalisoomro23?source=rss-12987dda425------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:23:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohsinalisoomro23/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create stripe webhook in nextjs 13.4.4.]]></title>
            <link>https://medium.com/@mohsinalisoomro23/how-to-create-stripe-webhook-in-nextjs-13-4-4-17d2c193ec0c?source=rss-12987dda425------2</link>
            <guid isPermaLink="false">https://medium.com/p/17d2c193ec0c</guid>
            <category><![CDATA[drizzle]]></category>
            <category><![CDATA[stripe]]></category>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[checkout]]></category>
            <category><![CDATA[next]]></category>
            <dc:creator><![CDATA[Mohsin Ali Soomro]]></dc:creator>
            <pubDate>Mon, 04 Sep 2023 10:40:11 GMT</pubDate>
            <atom:updated>2023-09-04T10:40:11.147Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCPATNOQoHpx9hcHG1Xl8w.png" /></figure><p>As you follow this article, you better know about nextjs.</p><p>Let’s know what a webhook is.</p><p>A webhook is a method of automating and integrating data or events between different applications or systems over the internet. It allows one application to send real-time information to another application or service when a specific event or trigger occurs.</p><p>Remember points when you work with stripe webhook<br>Webhook accepts raw body<br>It must be post-request<br>Event you should handle.</p><p>Let’s code.</p><p>Create a file route.ts inside an API folder,<br>api/stripe/webhook/route.t</p><pre>import Stripe from &quot;stripe&quot;;<br>import { NextRequest } from &quot;next/server&quot;;<br>import { OrderTable, db } from &quot;@/lib/drizzleOrm&quot;;<br>import { headers } from &quot;next/headers&quot;;<br>const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {<br>  apiVersion: &quot;2022-11-15&quot;,<br>  typescript: true,<br>});<br><br>export async function POST(request: NextRequest) {<br>  const body = await request.text();<br>  const endpointSecret = process.env.STRIPE_SECRET_WEBHOOK_KEY!;<br>  const sig = headers().get(&quot;stripe-signature&quot;) as string;<br>  let event: Stripe.Event;<br>  try {<br>    event = stripe.webhooks.constructEvent(body, sig, endpointSecret);<br>  } catch (err) {<br>    return new Response(`Webhook Error: ${err}`, {<br>      status: 400,<br>    });<br>  }<br><br>  switch (event.type) {<br>    case &quot;checkout.session.async_payment_failed&quot;:<br>      const checkoutSessionAsyncPaymentFailed = event.data.object;<br>      break;<br>    case &quot;checkout.session.async_payment_succeeded&quot;:<br>      const checkoutSessionAsyncPaymentSucceeded = event.data.object;<br><br>      break;<br>    case &quot;checkout.session.completed&quot;:<br>      const checkoutSessionCompleted: any = event.data.object;<br>      const response1 = await db<br>        .insert(OrderTable)<br>        .values({<br>          userId: checkoutSessionCompleted?.metadata.userId,<br>          itemCount: 1,<br>          total: checkoutSessionCompleted?.amount_total as any,<br>          isComplete: true,<br>        })<br>        .returning();<br>      break;<br>    default:<br>      console.log(`Unhandled event type ${event.type}`);<br>  }<br>  return new Response(&quot;RESPONSE EXECUTE&quot;, {<br>    status: 200,<br>  });<br>}</pre><p>Let’s break the code,</p><p>await request.text() =&gt; This will convert your rawbody to a string</p><ol><li>It imports necessary modules and initializes the Stripe API with the provided secret key.</li><li>It defines an asynchronous function POST(request: NextRequest) that will handle incoming HTTP POST requests.</li><li>Inside the function:</li></ol><ul><li>It extracts the request body and the Stripe webhook signature.</li><li>It attempts to construct a Stripe event from the request data using the Stripe library.</li><li>If there’s an error during event construction, it returns a 400 Bad Request response with an error message.</li></ul><ol><li>It then checks the type of the Stripe event and performs different actions based on the event type:</li></ol><ul><li>For “checkout.session.async_payment_failed,” it does nothing specific.</li><li>For “checkout.session.async_payment_succeeded,” it does nothing specific.</li><li>For “checkout.session.completed,” it inserts an order record into a database table using the Drizzle ORM library.</li></ul><ol><li>It logs an error message for any unhandled event types.</li><li>Finally, it returns a 200 OK response with the message “RESPONSE EXECUTE” to acknowledge the webhook execution.</li></ol><p>When a webhook calls it saves the record in the database if the checkout session is complete. For other events, you should follow according</p><p>Now how to test webhook,<br>You can test webhook on localhost<br><a href="https://stripe.com/docs/webhooks">https://stripe.com/docs/webhooks</a><br>Go to stripe =&gt; developer =&gt; webhook<br><a href="https://dashboard.stripe.com/test/webhooks/create">https://dashboard.stripe.com/test/webhooks/create</a><br>Here you will get a test key for localhost</p><p>Note: The webhook localhost key and production key are different, The localhost key you will get on the webhook page, for production you have to register the key webhook and click on reveal You will get a webhook production key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5APDalH1SoAgDnI8BO2ew.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17d2c193ec0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Splitting a PDF file into multiple files using AWS Lambda and Node.js]]></title>
            <link>https://medium.com/@mohsinalisoomro23/splitting-a-pdf-file-into-multiple-files-using-aws-lambda-and-node-js-a3d795e8db06?source=rss-12987dda425------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3d795e8db06</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[pdf]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Mohsin Ali Soomro]]></dc:creator>
            <pubDate>Sat, 11 Feb 2023 13:20:30 GMT</pubDate>
            <atom:updated>2023-02-11T13:20:30.228Z</atom:updated>
            <content:encoded><![CDATA[<pre>import fs from &#39;fs&#39;<br>import AWS from &#39;aws-sdk&#39;;<br>import { PDFDocument } from &#39;pdf-lib&#39;<br>const s3 = new AWS.S3();<br><br>export const handler = async (event) =&gt; {<br>    console.log({ PDFDocument, event })<br>    const bucket = event.Records[0].s3.bucket.name;<br>    const key = event.Records[0].s3.object.key;<br><br>    console.log(&quot;KEy&quot;, { bucket, key, record: JSON.stringify(event) })<br><br>    const params = {<br>        Bucket: bucket,<br>        Key: key<br>    }<br>    const pdf = await s3.getObject(params).promise();<br><br>    console.log(&quot;PDF BODY&quot;, { pdf })<br><br>    const pdfDoc = await PDFDocument.load(pdf.Body);<br>    console.log(&quot;event&quot;, { bucket, key, pdf })<br>    const promises = [];<br>    for (let i = 0; i &lt; pdfDoc.getPages().length; i++) {<br>        // Create a new &quot;sub&quot; document<br>        const subDocument = await PDFDocument.create();<br><br>        // copy the page at current index<br>        const [copiedPage] = await subDocument.copyPages(pdfDoc, [i])<br>        subDocument.addPage(copiedPage);<br>        const pdfBytes = await subDocument.save()<br><br><br>        const splitFile = key.split(&#39;.pdf&#39;)[0] + &#39;_&#39; + i + &#39;.pdf&#39;;<br>        console.log(&quot;SPLIT NAME&quot;,{key:key.split(&#39;.pdf&#39;)[0] + &#39;_&#39; + i + &#39;.pdf&#39;,splitFile})<br>        promises.push(s3.putObject({<br>            Bucket:&quot;splitedfile&quot;,<br>            Key: splitFile,<br>            Body: pdfBytes<br>        }).promise());<br>    }<br><br>  const response =  await Promise.all(promises);<br>        console.log(&quot;response&quot;,{response})<br>    return {<br>        message: &#39;PDF file split and saved to S3 successfully.&#39;<br>    };<br>};`</pre><p>This is an AWS Lambda function written in Node.js which is used to split a PDF file into multiple PDF files, one for each page of the original file.</p><h3>The code first imports three libraries:</h3><ul><li>fs (File System): A built-in library in Node.js used to work with the file system of the system on which the code is running. In this code, it is not being used.</li><li>AWS (Amazon Web Services) from ‘aws-sdk’: A library for working with Amazon Web Services. In this code, it is used to interact with Amazon S3 (Simple Storage Service), a cloud-based object storage service.</li><li>PDFDocument from ‘pdf-lib’: A library for working with PDF (Portable Document Format) files. In this code, it is used to load and manipulate PDF files. Then, an instance of the S3 client is created using new AWS.S3(). This instance will be used to interact with the S3 service.</li></ul><p>The main logic of the function is inside the handler function. This function will be called when the AWS Lambda is triggered.</p><p>The function starts by logging the event object, which is passed as an argument. This event object contains information about the event that triggered the function. In this case, it should contain information about the S3 object that was just created or updated.</p><p>Then, the name of the S3 bucket and the key of the object is extracted from the event object. The key represents the path of the object in the S3 bucket.</p><p>The function then uses the s3.getObject method to get the contents of the PDF file from the S3 bucket. The method is passed an object with two properties, Bucket and Key, which represent the name of the S3 bucket and the key of the object, respectively.</p><p>Once the contents of the PDF file are retrieved, the function uses the PDFDocument.load method to load the PDF document.</p><p>The function then creates an array of promises, where each promise represents a task to split one page of the PDF document into a separate file and save it to S3.</p><p>For each page in the PDF document, the function creates a new PDF document using the PDFDocument.create method. Then, it uses the copyPages method to copy the page from the original document to the new document. Finally, it uses the save method to save the new document as a new PDF file. The contents of the new file are then uploaded to S3 using the s3.putObject method.</p><p>Once all the promises are fulfilled, the function returns a message indicating that the PDF file has been split and saved to S3 successfully.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3d795e8db06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to invoke a function in javascript]]></title>
            <link>https://medium.com/@mohsinalisoomro23/how-to-invoke-a-function-in-javascript-e58b854a8b88?source=rss-12987dda425------2</link>
            <guid isPermaLink="false">https://medium.com/p/e58b854a8b88</guid>
            <category><![CDATA[function]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mohsin Ali Soomro]]></dc:creator>
            <pubDate>Wed, 05 Aug 2020 08:23:05 GMT</pubDate>
            <atom:updated>2020-08-05T08:23:05.897Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey! Friends</p><p>Today we are going to learn how to invoke a function in javascript</p><p>let start, invoke function are invoked in four ways</p><p>1 As a function — stalk();</p><p>2 As a method — func.stalk()</p><p>3 As a constructor — new stalk();</p><p>4 Via a function’s apply or call method — stalk.call(func) or stalk.applu(func)</p><p>let’s explore one by one</p><p>1 <strong>Invoke as a function</strong>? well of course function are invoked as a function. how to silly think otherwise. But in reality, we say that a function is invoked as a function to distinguish it from the other invocation mechanisms: methods, constructor, apply/call</p><pre>function(){return this;}</pre><p>2 <strong>Invoke as a method</strong>? when a function is assigned to a property of an object and the invocation occurs by referencing the function using that property, then the function is invoked as a method of that object. Here&#39;s an example:</p><pre>var func={}<br>func.stulk=function(){};<br>func.stulk();</pre><p>3 <strong>Invoke as a constructor</strong>? There is nothing special about a function that going to be used, constructor. The constructor function declared just like any other function expect there is the use of a “new” keyword. Here’s an example:</p><pre>function func(){return this}</pre><pre>var func1=new func();<br>func1()</pre><p>4 <strong>Invoke as an apply of call method</strong>? so far you have seen that one of the major differences among the types of function invocation.</p><p>let’s see an example of the call and apply methods:</p><pre>function print(){<br>console.log(&quot;Hello world&quot;)<br>}<br>print()//Hello world<br>print.call()//Hello world<br>print.apply()//Hello world</pre><h3><strong>Conclusion :</strong></h3><p>You see the differences among the function invocation to how to invoke functions in different scenarios. It is up to you to how to use them</p><p>Thanks for reading</p><p>What you think in comments</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e58b854a8b88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Copy WhataApp Status Without Third Party Software]]></title>
            <link>https://medium.com/@mohsinalisoomro23/copy-whataapp-status-without-third-party-software-ac135e29f35b?source=rss-12987dda425------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac135e29f35b</guid>
            <category><![CDATA[whatsapp]]></category>
            <dc:creator><![CDATA[Mohsin Ali Soomro]]></dc:creator>
            <pubDate>Thu, 12 Dec 2019 09:22:08 GMT</pubDate>
            <atom:updated>2019-12-12T09:22:08.791Z</atom:updated>
            <content:encoded><![CDATA[<p>Are You Bored With The Third Party Application for Copying WhatsApp Statuses</p><p>Or Has Security Issue or memory issue?</p><p>Then You Are a Right Place</p><p>Copying The WhatsApp Status Without Any Third Party Application</p><p>I Am Gonna Tell You To How To Copy WhatsApp Status Without Any Third Party Application</p><p>Step 1</p><p>Go To File Explorer&gt;Internal Storage And Find WhatsApp Folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*MVUBLj9K1_B4EvWxRiErwQ.jpeg" /><figcaption>File Explorar</figcaption></figure><p>Step 2</p><p>WhatsApp Folder&gt;media&gt; Click Three Tick and Go To Settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*LdrOHOvhsqM8wPQF5z8mvA.jpeg" /></figure><p>Step 3</p><p>Enable The Hidden File Then Back</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*gQzX1_K-CaaQhEhT7fuBnw.jpeg" /></figure><p>Step 4</p><p>Here Show The File (.Statuses) Open Then You Find All Statuses</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*zwY8ZgCIhJ96IzSQrrKjSQ.jpeg" /></figure><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac135e29f35b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>