#irfanz4951

1 messages · Page 1 of 1 (latest)

fluid scaffoldBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

stuck shadow
#

Hello! Can you summarize your question/issue here for me?

#

I tried to use retrofit to link my application to the stripe api using Kotlin, can I use it?

#

Let's talk here. 🙂

#

I'm not familiar with retrofit, can you tell me more about what that is?

unborn lake
#

Retrofit is a library that Android developers can use in Android Studio to link a JSON file on the server with your application.

stuck shadow
#

This isn't something we officially support. If you can get it working that's great, but I can't tell you if it will work or help you with the retrofit side of things. I can only assist with the Stripe side.

unborn lake
#

No that's fine because the retofit part works fine. I'm needing assistance with why I'm not able to update the pay button amount from the payment sheet

stuck shadow
#

So you're using our Android SDK?

unborn lake
#

On the payment sheet that pops up, there is a button with text that says "Pay $19.99". I want to get into the Stripe Api to change that amount on the button. This is where I'm having problems. Yes I'm using Android SDK

#

The language that I'm using is Kotlin

stuck shadow
#

Are you creating a Payment Intent first and then using the client secret to initialize the PaymentSheet?

unborn lake
#

let me check one second

#

This is the code that I'm using to update the amount

#

fun updatePaymentAmount(id: String, updatedSubTotal: Double) {
dispatchers?.let {
viewModelScope.launch(it.io) {
_checkoutLoad.value = CheckoutLoadingEvent.Loading
when (val checkoutResponse = checkoutRepo.updatePaymentIntent(id)) {
is Resource.Error -> checkoutResponse.errorMsg?.let {
CheckoutLoadingEvent.Failure(
it
)
}

                is Resource.Success -> {
                    checkoutResponse.data?.amount = (updatedSubTotal * 100).toInt()
                   _checkoutLoad.value = CheckoutLoadingEvent.Success("${ checkoutResponse.data?.amount}")

                    Log.d("CheckOutViewModel", checkoutResponse.data?.amount.toString())
                }
            }

        }
    }

}
#

So at the point where is says "checkoutResponse.data?.amount = (updatedSubTotal * 100).toInt, I'm assiging the updated value to the amount key in the the data class.

#

That data class is as following:

#

package com.tritongames.shoppingwishlist.data.models.checkout

data class StripePaymentIntent(
var amount: Int,
val amount_capturable: Int,
val amount_details: AmountDetails,
val amount_received: Int,
val application: Any,
val application_fee_amount: Any,
val automatic_payment_methods: Any,
val canceled_at: Any,
val cancellation_reason: Any,
val capture_method: String,
val client_secret: String,
val confirmation_method: String,
val created: Int,
val currency: String,
val customer: Any,
val description: String,
val id: String,
val invoice: Any,
val last_payment_error: Any,
val latest_charge: Any,
val livemode: Boolean,
val metadata: Metadata,
val next_action: Any,
val object: String,
val on_behalf_of: Any,
val payment_method: Any,
val payment_method_configuration_details: Any,
val payment_method_options: PaymentMethodOptions,
val payment_method_types: List<String>,
val processing: Any,
val receipt_email: Any,
val redaction: Any,
val review: Any,
val setup_future_usage: Any,
val shipping: Any,
val statement_descriptor: Any,
val statement_descriptor_suffix: Any,
val status: String,
val transfer_data: Any,
val transfer_group: Any
)

#

So I think what you're trying to tell me is that it won't update on the server until I've created the PaymentIntent?

stuck shadow
#

No, I'm trying to ask you what kind of flow you have, because the way you update the amount depends on the flow you're using.

#

I need to know if you're creating the Payment Intent first and initializing the PaymentSheet with the Intent's client secret, or if you're not creating the Payment Intent until later?

unborn lake
#

Oh I'm creating the payment intent first and then initializing the payment sheet. I believe also if I do it that way it also has to be confirmed as well, right?

stuck shadow
#

If you're doing that you would need to update the Payment Intent amount on your server, then update the PaymentSheet. Let me find out the specific steps...

#

While I'm looking, I want to confirm I understand correctly that you want to update the amount while the PaymentSheet is being displayed, correct?

unborn lake
#

yeah because I want to make sure when I put this live, they correct amount should be displayed. Right now its in test mode

stuck shadow
#

That's farily unusual. Why would the amount change while the PaymentSheet is being displayed?

unborn lake
#

no before the payment sheet shows up I wanted the 'amount' to change

stuck shadow
#

The amount shown in the PaymentSheet is based on the amount on the Payment Intent you're using.

#

It's not something you set in your Android code, it's something you set on your server.

unborn lake
#

You see before the payment sheet happens I have a grid of items to be purchased along with a subtotal. That subtotal will be added to taxes, etc. Then that final value will be sent to update the amount on the server. Then I want to pull that amount in to reflect on the payment sheet

stuck shadow
#

That should already be happening. When you create the Payment Intent it should have the total amount you want to charge (everything selected plus tax and whatnot), then you pass the Payment Intent's client secret to your app and initialize the PaymentSheet with it. At that point the amount displayed in the PaymentSheet should be the amount set on the Payment Intent.

#

Does that describe what you're doing?

unborn lake
#

yeah so like I said, it won't update on the server until I do the payment intent?

#

So can I pass in the data class that I've posted earlier?

stuck shadow
#

Pass it in where?

unborn lake
#

pass it into the payment intent.

#

The parameters that are included with the update method matches of that in the data class

stuck shadow
#

Not directly. Typically what happens is your app sends a message to your server containing info about what was selected for the purchase, then your server creates a Payment Intent for it using the Stripe API.

#

The part where your app communicates with your server can happen however you want.

unborn lake
#

So what is the typical form of the payment intent? Is it like a function with the parameters?

stuck shadow
unborn lake
#

So how does it return values, as a JSON

stuck shadow
#

The Stripe API returns JSON, yes.

unborn lake
#

Can I initiate the create (or update) methods within my code

stuck shadow
#

For the Payment Intent? Yeah, in your server code.

#

Don't try to integrate it into your current project, do this as a separate side project just to learn how all the pieces fit together.

unborn lake
#

This is what I have for server code that is currently on Dreamhost.com

#

<?php
require 'vendor/autoload.php';

$stripe = new \Stripe\StripeClient('sk_test_
// Use an existing Customer ID if this is a returning customer.
$customer = $stripe->customers->create(
[
    'name' => 'Irfan Ziaulla',
    'address' => [
    'line1' => '456 Example Street',
    'postal_code' => '45871',
    'city' => 'Anywhere',
    'state' => 'CA',
    'country' => 'US'
]
]

);
$ephemeralKey = $stripe->ephemeralKeys->create([
  'customer' => $customer->id,
], [
  'stripe_version' => '2022-08-01',
]);
$paymentIntent = $stripe->paymentIntents->create([
  'amount' => 1099,
  'currency' => 'usd',
  'customer' => $customer->id,
  // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
  'automatic_payment_methods' => [
    'enabled' => 'true',
  ],
]);

echo json_encode(
  [
    'paymentIntent' => $paymentIntent->client_secret,
    'ephemeralKey' => $ephemeralKey->secret,
    'customer' => $customer->id,
    'publishableKey' => 'pk_test_~~
  ]
);
http_response_code(200);

?>

stuck shadow
#

You should probably edit that message to not include your secret test key.

#

This is a public server.

#

But yeah, see how you're setting amount to 1099 there? That's where the amount you're seeing in the PaymentSheet is coming from.

#

Instead of hard-coding that you would set that to the total you calculate based on your customer's selections.

unborn lake
#

yeah, so I've put this code on my dreamhost account server, is that alright? That's the value that I know I have to change, so do I have to change the URLs for the GET, POST methods to where this code exist?

stuck shadow
#

Yeah, putting this on your DreamHost server is fine. You need to make significant modifications to the code to make it work with your app, yeah.

unborn lake
#

The document was showing that the GET mehod for " GET
/v1/payment_intents/:id" for retrieve payment Intent, I was kind of confused about that

stuck shadow
#

That's the API endpoint you would use to retreive a Payment Intent. Typically, for the flow you're trying to build, you wouldn't need to do that unless you had a specific reason to.

unborn lake
#

oh so in my case, I have to point my urls to the dreamhost one

stuck shadow
#

Yeah, your app talks to your server, your server talks to Stripe.

unborn lake
#

In my server code, it currently has a create method, do I need a similar ones for the other methlds as well like update?

stuck shadow
#

That's up to you and what you need to make your app/integration work.

#

Some people need them, some people don't, it depends on what you're building.

unborn lake
#

Oh okay now it's starting to make some sense, thank you

#

now all I have to do is access this server code on dreamhost to create the payment intent.

#

okay let me play with it some more. Is there anyway that I can see this chat again for reference of what we've discussed?

stuck shadow
unborn lake
#

Cool thanks a lot for your help