Stripe Dynamic Buy Now buttons without shopping cart

Hi Wappler,
Our use case is that we present each user with multiple services, which are entirely unique and dynamic. They are not Products in Stripe, and the name/price unique to that user. They are saved in a databsed, but are not products that we can sell multiple times. Ex:
user1 has been given offer1 at amount1 and offer2 at amount2
user2 has been given offer3 at amount3 and offer4 at amount4
None of these are available to any other user, it’s not a shopping cart situation. All quantities are always 1.
We’d like to have a button that goes to Stripe for each item. Click on “Buy offer1” and go pay amount1, click on “Buy offer2” and go pay amount2. No need to add offer1 to card and checkout as a second step, simply click and go pay on Stripe.

How should the Stripe component be set up, what should the line items be or come from?

How do I set a Buy button in the Repeater, as I need to have the cur, amount dynamic ?

Thank you much :slight_smile:

Sounds to me if I understand correctly is you need the invoice tools not the shopping cart.

Sorry @bradwe’re trying to make buttons to go to payments, not issue an invoice.
A receipt will surely be issued after payment, but we’re looking to have the buyer go to the Stripe checkout with dynamic parameters of amount, currency (and possibly the stripeID of who this will be paid to)

In an attempt to follow the Stripe Tutorials below, as a test we created a shopping cart, added to a Data Store, passed the product_ID (offerID in our case) to an API that queries the offer details (id, title, currency, amount)


The last steps are to create a checkoutSession with Custom Reference using the above query, set an id value with the createCheckoutSession.id in it, and get the Go To Payment button to use the stripe1.checking on Click.

All works well, the datastore is filled, passes the offerID to the API which queries/selects the right offer, but the stipe.php throws an error:

  1. {code: 0, file: “/home1/mdash/public_html/dmxConnectLib/modules/stripe.php”, line: 455,…}
  2. code: 0
  3. file: “/home1/mdash/public_html/dmxConnectLib/modules/stripe.php”
  4. line: 455
    4. message: "Undefined property: stdClass::$title"
  5. trace: “#0 /home1/mdash/public_html/dmxConnectLib/modules/stripe.php(455): exception_error_handler(8, ‘Undefined prope…’, ‘/home1/mdash/pu…’, 455, Array)↵#1 [internal function]: modules\stripe->modules{closure}(Object(stdClass))↵#2 /home1/mdash/public_html/dmxConnectLib/modules/stripe.php(459): array_map(Object(Closure), Array)↵#3 /home1/mdash/public_html/dmxConnectLib/lib/App.php(195): modules\stripe->createCheckoutSession(Object(stdClass), ‘createCheckoutS…’)↵#4 /home1/mdash/public_html/dmxConnectLib/lib/App.php(159): lib\App->execSteps(Object(stdClass))↵#5 /home1/mdash/public_html/dmxConnectLib/lib/App.php(127): lib\App->execSteps(Array)↵#6 /home1/mdash/public_html/dmxConnectLib/lib/App.php(116): lib\App->exec(Object(stdClass), false)↵#7 /home1/mdash/public_html/dmxConnectLib/lib/App.php(94): lib\App->exec(Object(stdClass))↵#8 /home1/mdash/public_html/dmxConnect/api/user/acceptOffer.php(8): lib\App->define(Object(stdClass))↵#9 {main}”

PS I have re-uploaded the /stripe/folder and the /dmxConnectLib/modules/stripe.php from version 3.9.2

Any idea what could cause this error?

This is a guess: I think that you do not have title in your query.

The following is my custom query, had to make it because ProductPrice is in dollars and Stripe requires cents. Also added currency to override the default usd

SELECT ProductID, ProductName AS title, ProductPrice * 100 AS amount,'aud' AS currency
FROM products
WHERE ProductID IN ({{$_POST.lineItems.flatten('product_id')}})

Hi @ben that was my first thought too, but the query contains title. the columns are called title, and I even added an alias as title, same issue
image
(I’m testing with id = 1 who I know exists and this query does return 1 record in mySQL.

file: “/home1/mdash/public_html/dmxConnectLib/modules/stripe.php” Line 455
message: “Undefined property: stdClass::$title”

Is it likely that the /dmxConnectLib/modules/Stripe.php file is not the latest one? See the code below. I have version 3.9.2

Our qryOffer query returns one line of data as expected.
{“userid”:null,“qryOffer”:{“id”:1,“title”:“Offer C4 to U3”,“amount”:“99.00”,“currency”:“EUR”}}

qryOffer is then fed to the Checkout Session:


The trouble begins when the title isn’t found in the data what is passed (Line 455 of /dmxConnectLib/modules/Stripe.php)

// /v1/checkout/sessions - post
  public function createCheckoutSession($options) {
    $options = $this->app->parseObject($options, NULL, TRUE);
    if ($options && isset($options->lineItemsType)) {
      if ($options->lineItemsType == 'custom' || $options->lineItemsType == 'customRef') {
        $options->line_items = array_map(function($item) {
          $item = (object)$item;
          $output = (object)array();
          $output->price_data = (object)array();
          $output->price_data->currency = isset($item->currency) ? $item->currency : 'USD';
          $output->price_data->product_data = (object)array();

455 $output->price_data->product_data->name = $item->title;
$output->price_data->unit_amount_decimal = $item->amount;
$output->quantity = isset($item->quantity) ? $item->quantity : 1;
return $output;
}, $options->line_items);
}

Could I please get some expert help, so we could unlock this phase? :slight_smile:
Thank you very much Wappler community! @Teodor what do you think (bug or wrong version)?

Try this one:

Thank you @George
I replaced the stripe.php the same error is now on line 506 :laughing:

You can try to enable the output of you query to see the real data it has. As it seems title is really missing

Hi George, the title is present in the query.

It looks like you are using a single query, rather than multiple.

If so, I believe that might be the issue…line items is expecting an array (even if that array only has a single object within.)

1 Like

@Fred_K I don’t know if this is useful feedback or not, as I have not used the new Wappler stripe features… so I’m not following the detail of your previous posts.

I wrote my stripe interface a year ago, and all I do is:

  1. Create a Payment Intent
  2. Update the Payment Intent amount as the user chooses different things.
  3. Do a Stripe Checkout (I think it’s called that… am not at my computer at the moment).

So I would be looking to replicate those Stripe calls using the Wappler tools.

Do a search for “Stripe SCA” to find the article I wrote about it. I can’t seem to paste the link to it from my phone!

That is a different workflow @Antony, not really replayed to the discussion here.

Also a lot has changed with Stripe since an year ago.

Hi @mebeingken, I didn’t realise that single and multiple records were handled differently in Wappler.
You’re correct, the single doesn’t produce an Array and that was causing the error in the Stripe.php handling of the result returned.
It now works when using the multiple record query type.
Thank you much!

1 Like

Now we finally arrived on the Stripe Payment page but something funny happens, the amount gets to be in Cents not full Euros :slight_smile:

qryOffer: [{id: 3, title: “My offer”, amount: “150.00”, currency: “EUR”}]
{id: 3, title: “My offer”, amount: “150.00”, currency: “EUR”}
1. amount: “150.00”
2. currency: “EUR”
3. id: 3
4. title: “My offer”

Did anyone see something similar before?

Could it be a number formatting setting somewhere along the line? In the database it is set as Decimal (11,2) to allow for 2 digits numbers.
image

image

There was indeed a problem with Single Query and PHP

Here is an improved version:

stripe.zip (6.8 KB)

1 Like

I created custom query to handle the conversion to cents

SELECT ProductID, ProductName AS title, ProductPrice * 100 AS amount,'aud' AS currency
FROM products
WHERE ProductID IN ({{$_POST.lineItems.flatten('product_id')}})

Very easy, just multiply by 100.

1 Like

Thanks @ben, definitely this could be a fix on our end.
Wappler though should look at this to see if this is a bug, or if doing x100 fix on queried amounts is the only thing to do :slight_smile:

That is not a bug. That’s how Stripe expects your prices

https://stripe.com/docs/currencies#zero-decimal

All API requests expect amounts to be provided in a currency’s smallest unit. For example, to charge 10 USD, provide an amount value of 1000 (i.e., 1000 cents).

1 Like