<?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 Thisun Bandara on Medium]]></title>
        <description><![CDATA[Stories by Thisun Bandara on Medium]]></description>
        <link>https://medium.com/@thisunwork?source=rss-423e2504554f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*doyS7C1KYdyxBoXWJ4RxSA.jpeg</url>
            <title>Stories by Thisun Bandara on Medium</title>
            <link>https://medium.com/@thisunwork?source=rss-423e2504554f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:19:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thisunwork/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[Bridging React Native with Native iOS For Azure Communication Calling]]></title>
            <link>https://medium.com/@thisunwork/bridging-react-native-with-native-ios-for-azure-communication-calling-cda86168f172?source=rss-423e2504554f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cda86168f172</guid>
            <dc:creator><![CDATA[Thisun Bandara]]></dc:creator>
            <pubDate>Thu, 27 Feb 2025 17:07:47 GMT</pubDate>
            <atom:updated>2025-02-27T17:13:51.394Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*TvYMfCvNLW9dc1fY4qh11Q.png" /></figure><p>The Azure Communication Calling library for React Native is not functioning properly due to an issue with the Crypto library. As a result, one possible solution is to implement the calling features directly in the Native iOS codebase.</p><p>This involves developing the necessary functionality using the native SDKs provided by Azure Communication Services for iOS. Once the calling features are implemented natively, they can be exposed to the React Native application using bridging headers.</p><p>This approach allows seamless communication between the native modules and the JavaScript side of the React Native app, ensuring that video and voice calling features work as expected without dependency issues.</p><h3>Bridging:</h3><p>In your React Native project, open the <strong>iOS project</strong> (workspace) using <strong>Xcode</strong> and create the following files to set up the bridging.</p><h3><strong>1.1 Bridging Header (</strong><strong>Bridging-header.h)</strong></h3><ul><li>The <strong>Bridging Header</strong> allows Swift files to communicate with React Native.</li><li>RCTViewManager is imported to register native UI components in React Native.</li></ul><pre>#import &quot;React/RCTViewManager.h&quot;</pre><h3><strong>1.2 Swift Native Module (</strong><strong>NativeViewManager.swift)</strong></h3><ul><li><strong>NativeViewManager</strong> is a React Native module that exposes a native view to JavaScript.</li><li>The @objc(NativeViewManager) annotation ensures React Native can recognize this module.</li><li>The view() function returns a <strong>SwiftUI-based UIView</strong> (NativeHostingView), which will render NativeContentView.</li><li>requiresMainQueueSetup() ensures that the module is initialized on the main thread.</li></ul><pre>import SwiftUI<br>import UIKit<br><br>@objc(NativeViewManager)<br>class NativeViewManager: RCTViewManager {<br>  <br>  override func view() -&gt; UIView! {<br>    if #available(iOS 14.0, *) {<br>      return NativeHostingView()<br>    } else {<br>      return nil<br>    }<br>  }<br>  <br>  override static func requiresMainQueueSetup() -&gt; Bool {<br>    return true<br>  }<br>}</pre><h3><strong>1.3 Objective-C Bridge (</strong><strong>NativeViewManager.m)</strong></h3><ul><li>This file acts as a bridge between <strong>Swift and React Native</strong>.</li><li>RCT_EXTERN_MODULE(NativeViewManager, RCTViewManager) makes NativeViewManager accessible from React Native.</li></ul><pre>#import &quot;React/RCTViewManager.h&quot;<br><br>@interface RCT_EXTERN_MODULE(NativeViewManager, RCTViewManager)<br>@end</pre><h3><strong>1.4 Hosting View (</strong><strong>NativeHostingView.swift)</strong></h3><ul><li><strong>NativeHostingView</strong> is a UIView that embeds a <strong>SwiftUI view</strong> (NativeContentView) into UIKit.</li><li>UIHostingController is used to integrate SwiftUI (NativeContentView) into a UIKit-based app.</li><li>setupUI() initializes and <strong>adds SwiftUI (</strong><strong>NativeContentView) to the view</strong>.</li><li>NSLayoutConstraint.activate([...]) ensures that the SwiftUI view takes up the full space of the UIView.</li></ul><h3><strong>1.5 SwiftUI View (</strong><strong>NativeContentView.swift)</strong></h3><p>After setting up all the necessary components, you can create the NativeContentView.swift file to integrate the native iOS calling implementation for Azure Communication Calling. This Swift file will serve as the calling window.</p><h3><strong>1.6 Call the Native Module from React Native Using (IOSCallView.js)</strong></h3><p><strong>1.6.1 </strong><strong>requireNativeComponent(&quot;NativeViewManager&quot;)</strong>:</p><ul><li>This tells React Native to render a native iOS UI component called &quot;NativeViewManager”, which is registered on the iOS side (typically in Swift/Objective-C).</li><li>The NativeViewManager component in iOS could be a UIView that manages the video call UI.</li></ul><p><strong>1.6.2 </strong><strong>RNCallView (Native UI Component) is returned in JSX</strong>:</p><ul><li>This acts like a <strong>React Native View</strong> but is actually a native iOS element.</li></ul><p><strong>1.6.3 Passing </strong><strong>props (if needed)</strong>:</p><ul><li>If the native component needs data (e.g., call tokens, user details), we can pass props from React Native to iOS.</li></ul><pre>import React from &quot;react&quot;;<br>import { requireNativeComponent } from &quot;react-native&quot;;<br><br>const RNCallView = requireNativeComponent(&quot;NativeViewManager&quot;);<br><br>const IOSCallView = () =&gt; {<br>   return &lt;RNCallView style={{ height: &#39;100%&#39;, width: &#39;100%&#39; }} /&gt;<br>};<br><br>export default IOSCallView;</pre><h3><strong>1.7 Render the IOSCallView In App.Js</strong></h3><p>Since we have created IOSCallView to render the native iOS view, it can now be used anywhere in the React Native code. In this case, we are using it in App.js.</p><pre>import React, { useEffect, useState } from &quot;react&quot;;<br>import { Modal, Platform } from &quot;react-native&quot;;<br>import IOSCallView from &quot;../../../IOSCallView&quot;;<br><br>const App = () =&gt; {<br>  const [displayIOSCallView, setDisplayIOSCallView] = useState(false);<br><br>  useEffect(() =&gt; {<br>    if (Platform.OS === &quot;ios&quot;) {<br>      setDisplayIOSCallView(true);<br>    }<br>  }, []);<br><br>  return (<br>    &lt;&gt;<br>      {displayIOSCallView &amp;&amp; (<br>        &lt;Modal&gt;<br>          &lt;IOSCallView /&gt;<br>        &lt;/Modal&gt;<br>      )}<br>    &lt;/&gt;<br>  );<br>};<br><br>export default App;</pre><p>This guide explains how to bridge video calling features implemented in Native iOS with React Native. To integrate Azure Video Calling into your app, follow the provided <a href="https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/voice-video-calling/get-started-with-video-calling?pivots=platform-ios">link</a>. You can then use the technique described above to seamlessly render the Native iOS calling window (NativeContentView.swift) within your React Native application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cda86168f172" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bridging React Native with Native Android For Azure Communication Calling]]></title>
            <link>https://medium.com/@thisunwork/bridging-react-native-with-native-android-for-azure-communication-calling-03203eef5278?source=rss-423e2504554f------2</link>
            <guid isPermaLink="false">https://medium.com/p/03203eef5278</guid>
            <dc:creator><![CDATA[Thisun Bandara]]></dc:creator>
            <pubDate>Thu, 27 Feb 2025 09:27:03 GMT</pubDate>
            <atom:updated>2025-02-27T17:13:12.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOivGe5JBcKrhOe3B-_7rA.png" /></figure><p>The Azure Communication Calling library for React Native is not functioning properly due to an issue with the Crypto library. As a result, one possible solution is to implement the calling features directly in the Native Android codebase.</p><p>This involves developing the necessary functionality using the native SDKs provided by Azure Communication Services for Android. Once the calling features are implemented natively, they can be exposed to the React Native application using bridging headers.</p><p>This approach allows seamless communication between the native modules and the JavaScript side of the React Native app, ensuring that video and voice calling features work as expected without dependency issues.</p><h3><strong>Bridging:</strong></h3><p>In your React Native project, open the <strong>Android</strong> <strong>project</strong> using <strong>Android Studio</strong> and create a <strong>Native Module</strong> that will allow communication between the React Native and Native Android sides.</p><h4>1.1 Create a Native Module (OpenNativeActivityModule.java)</h4><p>This module acts as a bridge between React Native and the native Android activity.</p><h4>Steps to Implement:</h4><ul><li>Inside the android/app/src/main/java/com/yourpackage/ directory, create a new Java file: <strong>OpenNativeActivityModule.java</strong></li><li>Add the following code:</li></ul><pre>package com.example;<br><br>import com.facebook.react.bridge.ReactApplicationContext;<br>import com.facebook.react.bridge.ReactContextBaseJavaModule;<br>import com.facebook.react.bridge.ReactMethod;<br><br>import android.content.Intent;<br><br>public class OpenNativeActivityModule extends ReactContextBaseJavaModule {<br>    private static ReactApplicationContext reactContext;<br>    private Intent intent;<br><br>    public OpenNativeActivityModule(ReactApplicationContext context) {<br>        super(context);<br>        reactContext = context;<br>        intent = new Intent(reactContext, NativeActivity.class);<br>    }<br><br>    @Override<br>    public String getName() {<br>        return &quot;OpenNativeActivityModule&quot;;<br>    }<br><br>    @ReactMethod<br>    public void openNativeActivity() {<br>        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);<br>        reactContext.startActivity(intent);<br>    }  <br>}</pre><h4>1.2 Register the Module (RNAzureCommunicationUICallingPackage.java)</h4><p>This class will register the module that we created earlier.</p><h4>Steps to Implement:</h4><ul><li>Create another Java file <strong>RNAzureCommunicationUICallingPackage.java</strong> inside android/app/src/main/java/com/yourpackage/.</li></ul><pre>package com.example; // Update with your package name<br><br>import com.facebook.react.ReactPackage;<br>import com.facebook.react.bridge.NativeModule;<br>import com.facebook.react.bridge.ReactApplicationContext;<br>import com.facebook.react.uimanager.ViewManager;<br>import java.util.ArrayList;<br>import java.util.Collections;<br>import java.util.List;<br><br>public class RNAzureCommunicationUICallingPackage implements ReactPackage {<br>    @Override<br>    public List&lt;NativeModule&gt; createNativeModules(ReactApplicationContext reactContext) {<br>        List&lt;NativeModule&gt; modules = new ArrayList&lt;&gt;();<br>        modules.add(new OpenNativeActivityModule(reactContext)); // Register the module<br>        return modules;<br>    }<br><br>    @Override<br>    public List&lt;ViewManager&lt;?, ?&gt;&gt; createViewManagers(ReactApplicationContext reactContext) {<br>        return Collections.emptyList();<br>    }<br>}</pre><h4>1.3 Register the Package in MainApplication.java</h4><p>Modify android/app/src/main/java/com/yourpackage/MainApplication.java and add your package inside getPackages():</p><pre>@Override<br>protected List&lt;ReactPackage&gt; getPackages() {<br>    return Arrays.&lt;ReactPackage&gt;asList(<br>        new MainReactPackage(),<br>        new RNAzureCommunicationUICallingPackage() // Add this line<br>    );<br>}</pre><h4>1.4 Call the Native Module from React Native</h4><p>Inside your JavaScript/TypeScript file (e.g., App.js or a specific screen):</p><pre>import { NativeModules, Button } from &#39;react-native&#39;;<br>import React from &#39;react&#39;;<br><br>const { OpenNativeActivityModule } = NativeModules;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Button title=&quot;Start Video Call&quot; onPress={() =&gt; OpenNativeActivityModule.openNativeActivity()} /&gt;<br>  );<br>};<br><br>export default App;</pre><p>This guide explains how to bridge video calling features implemented in Native Android with React Native. To integrate Azure Video Calling into your app, follow the provided <a href="https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/voice-video-calling/get-started-with-video-calling?pivots=platform-android">link</a>. You can then use the technique described above to seamlessly render the Native Android calling activity within your React Native application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03203eef5278" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing the PayPal Payment Service in NodeJS/Express JS to Manage Subscriptions]]></title>
            <link>https://medium.com/@thisunwork/implementing-the-paypal-payment-service-in-nodejs-express-js-to-manage-subscriptions-517074024ef?source=rss-423e2504554f------2</link>
            <guid isPermaLink="false">https://medium.com/p/517074024ef</guid>
            <dc:creator><![CDATA[Thisun Bandara]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 07:32:08 GMT</pubDate>
            <atom:updated>2023-06-19T07:32:08.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*voOV439fwiUwurxngwvPfw.jpeg" /></figure><p>This blog post will walk you through the process of creating an entry-level PayPal payment service to manage subscriptions in a NodeJS / Express backend development environment.</p><p><strong>Initial Setup:</strong></p><p>First and foremost, we need to be aware that we need to open a developer account and a test merchant account in PayPal for this.</p><p>Click Log in to dashboard at <a href="https://developer.paypal.com/home">https://developer.paypal.com/home</a>. You will first need to create a developer account, and then you will need to login into your brand-new PayPal developer account.</p><p>You will get on the next page after logging into your PayPal developer account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*YU1KtYBUUBhfXwOCDjY5sQ.png" /><figcaption>PayPal Developer Account Home Page</figcaption></figure><p>Click Sandbox accounts under Testing Tools. To simulate a PayPal payment, you must set up a test sandbox account, often known as a merchant account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*L7x04O3McLRDeihIepLRfg.png" /><figcaption>PayPal Sandbox Test Accounts</figcaption></figure><p>Click on “create account” as seen in the screenshot above, then fill out the necessary details. Make sure you choose “business account” for the account type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KT--e9yrx7VkpNhi2EZK7Q.png" /><figcaption>Create Sandbox Account</figcaption></figure><p>Once an account has been created, you can view it like in the screenshot up above. When you pick View/Edit account by clicking the three dots, you can input your desired email address. Here, we’ll use a fictitious email address for the test merchant account, testmerchant@business.example.com.</p><p>This email address will be used in the following steps to access the test merchant account. Additionally, you can set up a unique password for the account. You can save the modifications after completion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*AL3T9uzojWJAvazViiOknA.png" /><figcaption>Created Sandbox Account Details</figcaption></figure><p>Go to apps and credentials and select create app from there. Enter the necessary details and choose merchant as the type. Click on create app, then select the just created test merchant account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*aG0sDbaIfkQdiMqYcD6v0w.png" /><figcaption>Create App</figcaption></figure><p>You can view the app once it has been created as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*Oh-xToghzGi4B9Kb8Rj32Q.png" /><figcaption>App Credentials for Created App</figcaption></figure><p>Take note of the Client ID and Secret key that will be given to you because we will need them in the next steps when we use the PayPal API.</p><p><strong>Implementation:</strong></p><p>Log into the test merchant account that was recently created at <a href="https://www.sandbox.paypal.com/lk/home">https://www.sandbox.paypal.com/lk/home</a> After logging in, you will be taken to the merchant dashboard page. Click on subscriptions under the sales tab.</p><p>The subscription plans are displayed here as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CNGL_eUOMCmSYPFJCp_jA.png" /><figcaption>Manage Subscriptions Page in Merchant (Sandbox) Account</figcaption></figure><p>To manage subscriptions, you must first create a subscription plan for a product or service. As a result, we will develop a subscription plan. Click on Create Plan, then enter necessary product details before clicking Next.</p><p>Select the product that should be available with a subscription and then click next. You’ll be asked to choose a subscription type, and in this case, I’ll go with fixed pricing. You must enter a plan name and description on the following page. The following screen will ask you to define pricing for the subscription plan, which will be filled up as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*NMrbgJ_pUqbg__8BaytttQ.png" /><figcaption>Product Subscription Configuration</figcaption></figure><p>After that, turn the plan on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*BfmfsB0RH93IoUu5apIIZg.png" /><figcaption>Create Subscription Plan for Product</figcaption></figure><p>Following the successful creation of the plan, the plan information will be displayed as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*e7EylSenweaM0tLhhJEAfw.png" /><figcaption>Manage Subscriptions Page</figcaption></figure><p>When you click on the newly formed subscription plan, you will see the subscription details and, most importantly, the subscription plan id. Make a note of it because we’ll need it in the next steps.</p><p>Now, we’ll attempt to subscribe to a service, cancel a transaction, obtain subscription data, and unsubscribe from the service.</p><p>I have created a simple NodeJS/ Express JS project to showcase the usage of PayPal Subscription APIs.</p><p><strong>Subscribe:</strong></p><p>I created a simple API endpoint for the project for handling the subscription service. The first line of the screenshot below shows that I assigned the previously obtained PayPal client id and secret key to variables and assigned both to a variable called “auth” concatenating in the displayed format where we must use it for the authorization header when calling PayPal APIs.</p><p>The subscription payload object, which we must use to access the PayPal Subscribe API, is found in the following line. You can enter the subscription plan id that we acquired from the site as the plan Id. Add a brand name to the application context and leave the remaining property values as they are, as shown in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*TrsaTiTVhKzCCxqVkFNJsg.png" /><figcaption>PayPal Subscription Payload Object [Code Snippet]</figcaption></figure><p>When payment is successful, the user (payer) will be sent to the return address. When a payment is cancelled, the cancel URL is the URL to which the user (payer) is redirected. Depending on your preferences, you can add different URLs. In this case, the success URL has been added as a project-created API endpoint.</p><p>The PayPal subscribe API endpoint is built, as seen in the screenshot below, and the subscription plan id is assigned to a variable in the first line. Second, we made a POST request to the PayPal subscription API, passing the PayPal Subscription Object that we constructed earlier in the body.</p><p>In addition, we must include the authorization header, which is a basic authorization and will use the “auth” string that we previously produced using the obtained PayPal client id and secret key. Finally, we can obtain the PayPal subscription API response, convert it to JSON objects, and send it as the Project API endpoint response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*y6jab84Viei6MF9rMddThg.png" /><figcaption>PayPal Subscribe API Endpoint [Code Snippet]</figcaption></figure><p>When you call the “subscribe” API, you will get the following response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*c6zrIXVOjlrJaJYeZ5n7-A.png" /><figcaption>Subscribe API Endpoint Response</figcaption></figure><p>The PayPal Web URL for the payment gateway is contained as the first (At Index 0) object in a collection of URLs referred to as links. When you click the link, you will be redirected to the PayPal payment gateway as shown in the following screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ENYdojrbQxy2ZAvOhqxsEw.png" /><figcaption>Loading Screen of PayPal Payment Gateway</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*YX_FsQJQSigI9xcRbDCz8g.png" /><figcaption>Login Page for PayPal Payment Gateway</figcaption></figure><p>This is the initial window that appears in the payment gateway. You must login into your PayPal account, and in this case, we will use the PayPal developer account credentials to sign in and simulate the payer’s transaction through the PayPal gateway.</p><p>Otherwise, if you use another PayPal account that is an active public customer account, it will not work because we are testing on the PayPal test website, also known as the sandbox website. After logging in, the user will be taken to the screen shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hc_UM7dSQFeptk_cpxQ2DQ.png" /><figcaption>PayPal Payment Gateway Page Section 01</figcaption></figure><p>When you click on 0.00 USD, a little dropdown, it displays information about the free trial as well as the subscription amount that will be collected from your payment account once the free trial expires.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RxDUz69R5Khu4E65AFXziw.png" /><figcaption>PayPal Payment Gateway Page Section 02 with Subscription Details</figcaption></figure><p>Also, at the bottom of the page, there is a link that says “Cancel and return to Test Brand” where you can cancel the transaction, which is explained and depicted in the Cancel transaction section.</p><p>You can choose a payment method and it will display that a Visa card is already linked to your PayPal account; you can also simulate the payment by selecting that option. Following that, you will be taken to another page to confirm your payment, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*plczdRCEClqZeStLb-crTA.png" /><figcaption>Confirm Payment Page</figcaption></figure><p>When you click “Agree &amp; Subscribe,” the payment is processed, and the subscription procedure is completed.</p><p><strong>On Success Payment:</strong></p><p>If the subscription is successful, you should be sent to the success page; in this case, we’ve configured the success URL as our project endpoint and printed the subscription id to the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*CrdRrwF811pRgKlnz0_rTw.png" /><figcaption>Success Payment API Endpoint [Code Snippet]</figcaption></figure><p>When you access the console, you will notice that the subscription ID, which begins with “I,” is printed as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*pshD0PnoSB9sisoD5EmsPA.png" /><figcaption>Subscription ID Print in Server Console</figcaption></figure><p>That means the subscription was successful, and you can check it by returning to the PayPal test merchant account, heading to the Sales Tab, and selecting the subscriptions category under subscriptions. You will be able to see the active subscription with the same Subscription ID that we printed to the console in there. This is shown in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*FHbueNTOHONogebMkPo7-w.png" /><figcaption>Recently Subscribed Plan Listed in Subscriptions Page in Merchant (Sandbox) Account</figcaption></figure><p><strong>Get subscription details:</strong></p><p>Now that we’ve managed to subscribe to the product/service via PayPal subscription, you can utilize the subscription Id obtained from the success payment endpoint that we constructed to obtain the subscription data. The screenshot below shows how you can use the PayPal API to access the information of your subscription by passing the subscription ID to the PayPal subscriptions URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*LiKfDuqvqBi_7VQL9tNMHg.png" /><figcaption>Get Subscription Details API Endpoint [Code Snippet]</figcaption></figure><p>You will be able to obtain the JSON response after retrieving the GET request.</p><p>When you call the above-mentioned API, you will receive the response shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*yD8EddSkB0KNP10ialpUsQ.png" /><figcaption>Get Subscription Details API Endpoint Response</figcaption></figure><p>You can notice a property called status that states “ACTIVE” in the details, and along with it, you can view plenty of information about your subscription.</p><p><strong>Unsubscribe:</strong></p><p>To unsubscribe from the service/product, we must utilize the subscription ID once more, and with the help of the PayPal API for unsubscribing the service, as shown in the screenshot below, we can construct the function to handle the cancellation (unsubscribe) of the subscription.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*BX0t24OpAuwPriwQO07hnQ.png" /><figcaption>Unsubscribe API Endpoint [Code Snippet]</figcaption></figure><p>To unsubscribe, as seen in the preceding screenshot, you must submit an object with the reason as the payload for the PayPal API request, and in this example, we will provide an empty string for demonstration purposes.</p><p>The request headers are similar to prior requests, and once the fetch is complete, we can obtain the response status. According to PayPal’s API documentation, if the status is 204, the subscription cancellation is considered successful.</p><p>After executing the aforementioned unsubscribe API, we can confirm that the process was successful by returning to the PayPal test merchant account and viewing the subscriptions and cancelled sections, which display the Subscription ID, while the subscription ID is no longer available in the active section, as shown in the screenshots below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*3G1HJA8a7lXahPku6KU9fg.png" /><figcaption>Unsubscribed Subscription is Listed Under Cancelled Tab in Manage Subscriptions Page in Merchant (Sandbox) Account</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfFM8vM6ubGjG87rz3gMuQ.png" /><figcaption>Active Subscription Tab is Empty Now</figcaption></figure><p><strong>Cancel Transaction:</strong></p><p>As seen in the example below, if the user cancels payment by selecting the cancel link named “Cancel and return to Test Brand”, the payment gateway is replaced with the cancel URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RxDUz69R5Khu4E65AFXziw.png" /><figcaption>PayPal Payment Gateway</figcaption></figure><p>The user will be directed to the cancel payment URL, which in our instance is a separate endpoint, and the message “Payment cancelled” will be printed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*QStIqGu7Egb2bhTVYDQ1SA.png" /><figcaption>Cancel Payment API Endpoint [Code Snippet]</figcaption></figure><p>When the cancel link is clicked, the following will be printed on the console, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*Pqe1VPxR81bwOVKXgJIdGw.png" /><figcaption>Payment Cancelled Print in Server Console</figcaption></figure><p>We have now performed the basic PayPal subscription operations in a Node JS/Express backend development environment, which include subscribing to a service, collecting subscription details, canceling transactions, and unsubscribing from the service. We hope this has given you some insight.</p><p>Thank you.</p><p>Reference:</p><p><a href="https://developer.paypal.com/docs/subscriptions/integrate">https://developer.paypal.com/docs/subscriptions/integrate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=517074024ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing the Stripe Payment Service in NodeJS/Express JS to Manage Subscriptions]]></title>
            <link>https://medium.com/@thisunwork/implementing-the-stripe-payment-service-in-nodejs-express-js-to-manage-subscriptions-cdff7a4fef33?source=rss-423e2504554f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdff7a4fef33</guid>
            <dc:creator><![CDATA[Thisun Bandara]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 07:32:07 GMT</pubDate>
            <atom:updated>2023-06-19T07:32:07.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LgbZYCGaWywbN8cQgM4RAg.png" /></figure><p>This blog post will walk you through the process of creating an entry-level Stripe payment service to manage subscriptions in a NodeJS / Express backend development environment.</p><p>The primary component of a subscription should be a product / service. so that we may first create a product.</p><p><strong>Create Product:</strong></p><p>Go to the dashboard page after logging into your Stripe developer account at <a href="https://stripe.com/docs/development">https://stripe.com/docs/development</a> and choose products.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2k90fx3ZI4WI3AkmIBwkXQ.png" /><figcaption>Stripe Products Page</figcaption></figure><p>To establish a simple subscription plan, choose add product and enter the information as it appears in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uiDGeNRTuXvXu9Sl6KvruA.png" /><figcaption>Add Product Page</figcaption></figure><p>Since this is a subscription plan, it is possible to add a trial period; as can be seen in the screenshot up top, the trial term for the subscription is now set at 7 days.</p><p>The product will be saved after you click “Save Product.”</p><p>You will be taken to the page for the newly generated product after the product has been saved, and it will display all the information related to the new product as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aEAoslvcEa5_lh4Z1MzCAA.png" /><figcaption>Product Details Page</figcaption></figure><p>The most crucial component that we must use in Stripe API calls to distinguish our product from the subscription is an ID called API ID that can be found in the pricing section. Keep a note of that ID.</p><p>Another crucial piece of information can be found on the home page, and that is the Secret Key that we will need to make Stripe API calls. Likewise, make a note of that key.</p><p>Now, we’ll attempt to subscribe to a service, cancel a transaction, obtain subscription data, and unsubscribe from the service.</p><p>I have created a simple NodeJS/ Express JS project to showcase the usage of Stripe Subscription APIs.</p><p>First and foremost, you need to install stripe library to your Node JS project by entering <strong>“npm install stripe”</strong> and the latest version will be installed to your project.</p><p><strong>Subscribe:</strong></p><p>To manage the subscription service, I made a straightforward API endpoint for the project.</p><p>The first line of the screenshot below shows the Stripe Secret Key that I have already acquired, as previously explained. As indicated in line 2, we will initialize the Stripe service to our project using the Stripe secret key.</p><p>Thirdly, we have developed the session object, which launches the subscription process using the Stripe checkout session. We have declared the mode as subscription in this code part, and in the line items, we will be supplying the API ID that we previously acquired from the newly formed products page.</p><p>This is also known as “<strong>Price ID</strong>”. We will subscribe to the service one at a time, therefore the quantity will be set to 1, and the price ID will be assigned to the price property. Finally, there will be a success URL and a cancel URL. The success URL redirects the user to a page when the payment is successfully completed, while the cancel URL simply cancels the payment.</p><p>In this instance, we have added the success URL as a project-created API endpoint. We will also be extracting the <strong>Stripe Session ID</strong> from the transaction process, which will play a vital role in the next section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeTHSrfksLwWZFgqi5UEEw.png" /><figcaption>Stripe Subscribe API Endpoint [Code Snippet]</figcaption></figure><p>You will get the following response when you call the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJWKKynf4PntOarcAMEXTQ.png" /><figcaption>Stripe Subscribe API Endpoint Response</figcaption></figure><p>The Stripe Web URL for the payment gateway is contained in an attribute referred to as URL. You will be taken to the Stripe payment gateway when you click the link as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*YZziBiHyF5rv0ZoqMTk9Hg.png" /><figcaption>Stripe Payment Gateway Page 01</figcaption></figure><p>In addition, there is a back button icon at the top left of the page where you can cancel the transaction, which is discussed and displayed in the Cancel transaction section.</p><p>You can enter data for direct card payment as seen in the following snapshot: in this instance, we’ll make use of a test card that Stripe offers. Click subscribe to finish the subscription transaction procedure after adding the relevant data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*QX-l_Qy6G8XeZJ2hJEP61g.png" /><figcaption>Stripe Payment Gateway Page 02</figcaption></figure><p><strong>On Success Payment:</strong></p><p>Then, as seen below, you will be redirected to the success URL that you previously established in the Stripe Payment Object. In this case, I have only written the session ID that is derived from the Stripe transaction process. If you want to know more about the subscription transaction and how it was performed, you may use this session ID to get details about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*thJlmCPlgFkyyd5VU1L89Q.png" /><figcaption>Stripe Success Payment API Endpoint [Code Snippet]</figcaption></figure><p>The session id which starts with “cs_test” is displayed on the server console, as shown in the screenshot below. Also make a note of that session ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*h9BBVwZsasNBNj2QCLm8BQ.png" /><figcaption>Session ID Print in Server Console</figcaption></figure><p>Additionally, you can alter the aforementioned API endpoint to output an html file that shows a success message to the user while persisting the pertinent data on the subscription transaction process.</p><p><strong>Get the subscription details:</strong></p><p>Following the initialization of the Stripe service using the Stripe secret key, as demonstrated below, we use the checkout session once more to retrieve the data associated with the subscription process.</p><p>To receive the subscription information for the chosen session id, we must first supply the session id that we obtained from the prior transaction. Then, using the session details, we use “<strong>session.subscription</strong>” to retrieve the subscription details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3E9Q2bUy3Uu6O5Yc0VdFOA.png" /><figcaption>Stripe Get Subscription Details API Endpoint [Code Snippet]</figcaption></figure><p>The following response will be sent once you call the aforementioned API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*rFshfUIvzl3la_RWM95Jfg.png" /><figcaption>Stripe Get Subscription Details API Endpoint Response Part 01</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*SOjkYnWO-5wvwgan50wolw.png" /><figcaption>Stripe Get Subscription Details API Endpoint Response Part 02</figcaption></figure><p>There are several data about the subscription that you can view, but the most essential one is the subscription ID at the top of the response. Finally, it has a parameter that indicates the status, which in this case is active. The subscription ID may be retrieved by utilizing the Id attribute, which is located at the top of the API response. Make a note of it.</p><p>Returning to the Stripe developer account as displayed below, go to the Billing section where you can see the subscription listed under “Subscriptions,” “Current Subscriptions.” This will enable us to confirm that the subscription was received and is still active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*OGdkrpFNf9PIdYh7667Bfg.png" /><figcaption>Stripe Current Subscriptions Page</figcaption></figure><p>The subscription details and the user will be visible once you click on the subscription item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*sWV9mT47V4MCSQsNRZHTrQ.png" /><figcaption>Stripe Subscription Details Page</figcaption></figure><p><strong>Unsubscribe:</strong></p><p>The API endpoint that was developed to test the unsubscribe feature is shown in the screenshot below.</p><p>The same as before, after setting up the Stripe service for the project using the Stripe secret key, we cancel the subscription using the subscription ID we just got from the previous response. Cancellation will be executed by “<strong>stripe.subscriptions.del(SUBSCRIPTION ID)” </strong>code line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*hpNY2oskF0ngKumNTBrS5g.png" /><figcaption>Stripe Unsubscribe API Endpoint [Code Snippet]</figcaption></figure><p>Following a successful cancellation of the service, you will see “Cancelled” in the status field of the response you receive after calling the aforementioned API, which looks similar to the response with subscription details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*8xX19O2YaU3pxU_RvdD57Q.png" /><figcaption>Stripe Unsubscribe API Endpoint Response</figcaption></figure><p>You may confirm that you have successfully unsubscribed from the service by logging back into your Stripe developer account as displayed below, where the subscription is no longer displayed under Current in the Billing tab but is instead visible under Canceled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*efkVBi4kigjAc2x85HN76Q.png" /><figcaption>Stripe Subscriptions Page</figcaption></figure><p><strong>Cancel Transaction:</strong></p><p>As seen in the example below, if the user cancels payment by clicking the back button at the top left of the page, the payment gateway is replaced with the cancel URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kUA1H2DVgLWaqctEJv3hZw.png" /><figcaption>Stripe Payment Gateway</figcaption></figure><p>The user will be directed to the cancel payment URL, which in our instance is a separate endpoint, and the message “Payment cancelled” will be printed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*jLYR6J8cjX0D7Ts-E6yxsw.png" /><figcaption>Stripe Cancel Payment API Endpoint [Code Snippet]</figcaption></figure><p>When the cancel link is clicked, the following will be printed on the console, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*oyMsSUwQRt8GsObNgZb9hg.png" /><figcaption>Payment Cancelled Message Print in Server Console</figcaption></figure><p>We have now performed the basic Stripe subscription operations in a Node JS/Express backend development environment, which include subscribing to a service, collecting subscription details, canceling transactions, and unsubscribing from the service. We hope this has given you some insight.</p><p>Thank you.</p><p>Reference:</p><p><a href="https://stripe.com/docs/api">https://stripe.com/docs/api</a></p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdff7a4fef33" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>