stripe - how to request email info

Hi everyone,
Can you help.

I am using stripe currently and everything is fine, it all works. I have used the examples available widely on here and youtube to setup a basic payment system.
What I now want to do is request a payers email address, so I can send an invoice. But I am struggling to figure out how to do this. I think the issue is that the receipt email is part of an api that I am not using currently and I do not know how to add it in. I have tried to collect the info as metadata and as email_recipet but no luck.

I have copied my code below and you can see what I have tried, but no success - can anyone help?

Many thanks

payment request page code


import {createToken, encodeCard} from “public/stripeAPI.js”;
import {charge} from ‘backend/stripeProxy’;
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
setData();

});

export function payNow() {
createToken(encodeCard(createCard()))
.then((token) => {
charge(token,getCart())
.then((chargeResponse) => {
wixLocation.to(“/thankyoujob”);
});
});
console.log(“paynow func”);
}

function createCard() {
return {
“name”: $w(“#nameOnCard”).value,
“number”: $w(“#cardNumber”).value,
“cvc”: $w(“#cvc”).value,
“exp_year”: $w(“#expYear”).value,
“exp_month”: $w(“#expMonth”).value,
//“metadata”: {“email”: $w(“#receiptEmail”.value)},
//“amount”: $w(“#paymentAmount”).value
};
}

function getCart(){
return {
“amount”: $w(‘#paymentAmount’).value*100,
“currency”: “GBP”,
“description”: “OGDO Payment for Job Advert”,
//“metadata”: $w(“#receiptEmail”).value,
};
}

function setData() {
//$w(“#nameOnCard”).value = “Bob Smith”;
//$w(“#cardNumber”).value = 4242424242424242;
//$w(“#cvc”).value = 123;
//$w(“#expYear”).value = 18;
//$w(“#expMonth”).value = 12;
$w(“#paymentAmount”).value = 25.00;
}

export function payTest_click (event, $w) {
console.log(“clicked”);
payNow();

}


stripeAPI.js
const response = await fetch(“https://api.stripe.com/v1/tokens”, {
method: ‘post’,
headers: {
“Content-Type”: “application/x-www-form-urlencoded”,
“Authorization”: "Bearer " + apiKey
},
body: card
});

if (response.status >= 200 && response.status < 300) {
const json = await response.json();
return json.id;
}

const responseText = await response.text();
console.log(‘Response Status’, response.status);
return response.status;
}

export function encodeCard(card){
let encoded = “”;

for ( let [k, v] of Object.entries(card)) {
encoded = encoded.concat(“card[”, k, “]=”, encodeURI(v), “&”);
console.log(encoded);
}

return encoded.substr(0, encoded.length - 1);
}


stripeProxy.jsw

const response = await fetch(“https://api.stripe.com/v1/charges”, {
method: ‘post’,
headers: {
“Content-Type”: “application/x-www-form-urlencoded”,
“Authorization”: "Bearer " + apiKey
},
body: encodeBody(token, cart)

});

if (response.status >= 200 && response.status < 300) {
return await response.json();
}
return await response.text();
}

function encodeBody(token, cart){
let encoded = “”;

for ( let [k, v] of Object.entries(cart)) {
encoded = encoded.concat(k,“=”, encodeURI(v), “&”);
}
encoded = encoded.concat(“source=”, encodeURI(token));
return encoded;

}

This might not be helpful to you or you may have already seen and read it all…

Can you not add it somewhere in this example:
https://www.wix.com/corvid/forum/wix-tips-and-updates/example-stripe-payment-processing

Or try to add it as a Wix Invoice:
https://support.wix.com/en/article/about-wix-invoices

Or try to add it as a Wix Automation:
https://support.wix.com/en/article/setting-up-an-automation

If you are using Wix Stores, then you can setup email confirmations already:
https://support.wix.com/en/article/sending-confirmation-emails-to-your-customers-following-a-store-purchase

Hi,

You need to pass the receipt_email parameter with the order amount like this

function getCart(){
  return {
     "amount": $w('#paymentAmount').value*100,
     "currency": "GBP",
     "description": "OGDO Payment for Job Advert",
     "receipt_email": $w("#receiptEmail").value //this one here
  };
}

OMG the one combination that I didn’t try and it worked first time. This is very much appreciated! Thank you.

Thank you for your replies. Much appreciated.