<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sarthak kumar</title>
    <description>The latest articles on DEV Community by Sarthak kumar (@iamsarthakk).</description>
    <link>https://dev.to/iamsarthakk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F480236%2Faa4d5bda-f31e-4196-be9f-9ac24e886d92.jpeg</url>
      <title>DEV Community: Sarthak kumar</title>
      <link>https://dev.to/iamsarthakk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamsarthakk"/>
    <language>en</language>
    <item>
      <title>Stripe Connect Integration in Marketplace App</title>
      <dc:creator>Sarthak kumar</dc:creator>
      <pubDate>Sun, 05 Dec 2021 16:24:18 +0000</pubDate>
      <link>https://dev.to/iamsarthakk/marketplace-app-with-stripe-connect-2o6i</link>
      <guid>https://dev.to/iamsarthakk/marketplace-app-with-stripe-connect-2o6i</guid>
      <description>&lt;h2&gt;
  
  
  Set up stripe:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;npm install --save stripe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Put your stripe secrets in .env file&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create stripe object (backend - server.js)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY, {
  apiVersion: '2020-08-27',
  appInfo: {
    name: "stripe-samples/accept-a-payment/custom-payment-flow",
    version: "0.0.2",
    url: "https://github.com/stripe-samples"
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Seller Onboarding: Creating seller stripe account (backend - server.js)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/stripeConnectRegisterSeller', async (req, res) =&amp;gt; {
  try{
    //Create Express account for the seller
    const account = await stripe.accounts.create({type:'standard'});
    console.log(account);

    //Create account link
    const accountLink = await stripe.accountLinks.create({
      account: account.id,
      refresh_url: 'http://localhost:8080/failed',
      return_url: 'http://localhost:8080/success',
      type: 'account_onboarding',
    });

    console.log(accountLink);
    res.status(200).json({success: true, url: accountLink.url});
  }
  catch(err){
    console.log(err);
    res.send(err);
  }
});
app.get('/success', (req, res)=&amp;gt;{
  res.send("Success");
});
app.get('/failed', (req, res)=&amp;gt;{
  res.send("Failed");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Redirect the user to accountLink (frontend - account.js)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function addAccount(){
    document.getElementById("accountDetails").innerHTML = "Wait for request to process"
    await fetch(`${BACKEND_URL}/stripeConnectRegisterSeller`)
        .then(res=&amp;gt;res.json())
        .then(res =&amp;gt; {

            accountId = res.accountId;
            const currentUser = Moralis.User.current();
            currentUser.set("account_ID", accountId);
            currentUser.save();
            return res
        }) 
        .then(res =&amp;gt; {
            window.location = res.url;
        })
        .catch(err =&amp;gt; console.log(err))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Seller will fill their required details to create stripe account. User will be redirected to the &lt;strong&gt;return_url&lt;/strong&gt; after compeleting onboarding.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Payment by customer to the registered seller (backend - server.js)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create checkout session using stripe API and send this session object to the frontend
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/create-checkout-session', async (req, res) =&amp;gt; {
  const {currency, paymentMethodType, amount, userEthAddress, userStripeAccountId, tokenId, productType } = req.body;
  console.log({paymentMethodType, amount, currency, userEthAddress, userStripeAccountId, tokenId, productType})
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: [{
      name: "Connect",
      amount: amount,
      quantity: 1,
      currency: currency,
    }],
    mode: 'payment',
    success_url: 'https://example.com/success',
    cancel_url: 'https://example.com/failure',
    payment_intent_data: {
      application_fee_amount: 0.03*amount,
      transfer_data: {
        destination: userStripeAccountId,
      },
    },
  });

  res.send({session})
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Redirect to stripe payment page (frontend - payment.js)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const makePayment = async ()=&amp;gt;{
    const currentBid = document.querySelector('#payment-modal-token-price').value;
    const userEthAddress = localStorage.getItem('userEthAddress');
    const tokenId = parseInt(localStorage.getItem('tokenId'));
    let productType = getProductType();

    await fetch(
        `${BACKEND_URL}/create-checkout-session`,
        {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                currency: 'inr',
                amount: currentBid*100*80,
                paymentMethodType: 'card',
                userEthAddress: userEthAddress,
                userStripeAccountId: 'acct_1K3HMxQkqeDnOAwK',
                tokenId: tokenId,
                tokenNos: 1,
                productType: productType
            }),
        }
    )
    .then((r) =&amp;gt; r.json())
    .then((res)=&amp;gt;{
        const sessionId = res.session['id']; 
        var stripe = Stripe(STRIPE_PUBLISHABLE_KEY)
        stripe.redirectToCheckout({
            sessionId: sessionId
        }).then(function (result) {
            result.error.message = 'Error'
        });
        console.log(res);
    })
    .catch((err)=&amp;gt;console.log(err));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After completing payment process page will be redirected to success_url or cancel_url depending on the user response.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Creator Nation</title>
      <dc:creator>Sarthak kumar</dc:creator>
      <pubDate>Sun, 05 Dec 2021 15:56:57 +0000</pubDate>
      <link>https://dev.to/iamsarthakk/creator-nation-1k3p</link>
      <guid>https://dev.to/iamsarthakk/creator-nation-1k3p</guid>
      <description>&lt;h3&gt;
  
  
  My Workflow
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/actions/javascript-action"&gt;https://github.com/actions/javascript-action&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;DIY Deployments&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/kakarots-bro/CreatorNationOfficial.git"&gt;https://github.com/kakarots-bro/CreatorNationOfficial.git&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

&lt;p&gt;Website: &lt;a href="https://www.creatornation.net/"&gt;https://www.creatornation.net/&lt;/a&gt;&lt;br&gt;
App Link: &lt;a href="https://drive.google.com/file/d/1qZ9Ldwd2qMbD6nDm5z1C4jieaMZK08cV/view"&gt;https://drive.google.com/file/d/1qZ9Ldwd2qMbD6nDm5z1C4jieaMZK08cV/view&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
