#pulpremicks

1 messages ยท Page 1 of 1 (latest)

oak belfry
late moth
#

already checked that out mate, it seems to say that it should convert fine,

We have move from using a UI that has sources,

Now we have a new UI that uses payment methods,

#

so when we go to set a default method

#

it comes back with a source error

#

we run a micro service, so our core service could need a stripe update,

I dont wanna update it and have all our customer payments no longer work as it will only work for payment methods not sources

oak belfry
#

What is the source error that you are seeing?

late moth
#

2 secs ill get it

#

[2022-09-02 15:03:44] local.ERROR: No such source: 'pm_1LdEY2JhhmqoAYXaYcuxdUQG' {"userId":"7c25bf3e-286c-11ed-a5fd-01002da17977","exception":"[object] (Stripe\Exception\InvalidRequestException(code: 0): No such source: 'pm_1LdEY2JhhmqoAYXaYcuxdUQG' at /web/html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38)
[stacktrace]
#0 /web/html/vendor/stripe/stripe-php/lib/Exception/InvalidRequestException.php(35): Stripe\Exception\ApiErrorException::factory('No such source:...', 400, '{
"error": {
...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...')
#1 /web/html/vendor/stripe/stripe-php/lib/ApiRequestor.php(213): Stripe\Exception\InvalidRequestException::factory('No such source:...', 400, '{
"error": {
...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...', 'source')
#2 /web/html/vendor/stripe/stripe-php/lib/ApiRequestor.php(175): Stripe\ApiRequestor::_specificAPIError('{
"error": {
...', 400, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
#3 /web/html/vendor/stripe/stripe-php/lib/ApiRequestor.php(560): Stripe\ApiRequestor->handleErrorResponse('{
"error": {
...', 400, Object(Stripe\Util\CaseInsensitiveArray), Array)
#4 /web/html/vendor/stripe/stripe-php/lib/ApiRequestor.php(124): Stripe\ApiRequestor->_interpretResponse('{
"error": {
...', 400, Object(Stripe\Util\CaseInsensitiveArray))
#5 /web/html/vendor/stripe/stripe-php/lib/ApiOperations/Request.php(78): Stripe\ApiRequestor->request('post', '/v1/customers/c...', Array, Array)
#6 /web/html/vendor/stripe/stripe-php/lib/ApiOperations/Request.php(42): Stripe\ApiResource::_staticRequest('post', '/v1/customers/c...', Array, Object(Stripe\Util\RequestOptions))
#7 /web/html/vendor/stripe/stripe-php/lib/ApiOperations/Update.php(46): Stripe\ApiResource->_request('post', '/v1/customers/c...', Array, NULL)
#8 /web/html/app/Repositories/CustomerRepository.php(117): Stripe\Customer->save()

#

this is trying to set a default payment method

oak belfry
#

Can you show me the snippet of code that is making the call that gets that error?

#

You can't use payment methods in the same places as sources but there is likely another place that you can pass it in

late moth
#

illl get that now

#

/**
* Update a customers information on stripe.
*
* @param string $customer_id Customer uuid
* @param array $params Parameters
*
* @return mixed
* @throws \ReflectionException
*/
public static function update($customer_id, array $params)
{
$customer = Customer::where(function ($query) use ($customer_id) {
return $query->where('business_id', '=', $customer_id)
->orWhere('stripe_id', '=', $customer_id);
})->firstOrFail();

    static::authorizeUserAction('update', $customer);

    if (array_key_exists('id', $params)) {
        unset($params['id']);
    }


    if ($customer instanceof Collection) {
        $customer = $customer->first();
    }

    $stripe_customer = static::getStripeClass(StripeCustomer::class)::retrieve(
        $customer->stripe_id
    );

    $properties = static::getConstructorProperties(StripeCustomer::class);

    $params = Arr::only($params, $properties);

    foreach (Arr::dot($params) as $key => $value) {
        data_set(
            $stripe_customer,
            $key,
            $value
        );
    }

    $stripe_customer->save();

    Cache::forget('customers.all');
    Cache::forget('customers.' . $customer_id);

    return $stripe_customer;
}

We were setting params like
['default_source' => 'xxxxxxxx', 'id' => 'zzzzzzz']

we think we should be now trying to do something like
[
'invoice_settings' => ['default_payment_method' => $source_id],
'id' => $this->stripe_customer['id']
]

oak belfry
#

Yes, that is exactly it

#

invoice_settings.default_payment_method is the new equivalent of default_source

#

If you set that, Stripe will use that PM as the default for all subscriptions on that customer unless you specify a different payment method on the subscription itself

late moth
#

does it work with the older versions on the stripe API?

#

finding the version we are on now

oak belfry
#

default source and default payment method are only relevant for subscriptions. Can you tell me what other API methods you are looking to use here?

late moth
#

were on 7.125 , we only do subscriptions

oak belfry
late moth
#

Perfect thanks!

How do we remove a default sauce if we have already set one for the customer?

oak belfry
#

I think you either need to pass the empty string or null

#

Can you try with an empty string first and let me know if that works? My php project is broken at the moment

late moth
#

[2022-09-02 15:50:18] local.ERROR: You passed an empty string for 'default_source'. We assume empty values are an attempt to unset a parameter; however 'default_source' cannot be unset. You should remove 'default_source' from your request or supply a non-empty value. {"userId":"edbb26d4-2551-11ed-a80f-01002da17977","exception":"[object] (Stripe\Exception\InvalidRequestException(code: 0): You passed an empty string for 'default_source'. We assume empty values are an attempt to unset a parameter; however 'default_source' cannot be unset. You should remove 'default_source' from your request or supply a non-empty value. at /web/html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38)

#

Empty string error above

spring fossil
#

Hi ๐Ÿ‘‹ I

#

am stepping in for @oak belfry

#

There's a lot of context here. Could you summarize what is is you are trying to achieve?

late moth
#

Basically we are trying to update a default payment method but are running into problems because we used ti use sources

#

the above error comes from an attempt to go over the top of the default but using the payment method instead

spring fossil
#

an attempt to go over the top of the default but using the payment method instead
Can you explain what that is supposed to mean?

late moth
#

Because we have been using the older 'sources' version of the payment methods We are unable to set defaults from our newer system that uses payment methods

When we attempt to update the customer with the new default payment method we get this error

[2022-09-02 15:50:18] local.ERROR: You passed an empty string for 'default_source'. We assume empty values are an attempt to unset a parameter; however 'default_source' cannot be unset. You should remove 'default_source' from your request or supply a non-empty value. {"userId":"edbb26d4-2551-11ed-a80f-01002da17977","exception":"[object] (Stripe\Exception\InvalidRequestException(code: 0): You passed an empty string for 'default_source'. We assume empty values are an attempt to unset a parameter; however 'default_source' cannot be unset. You should remove 'default_source' from your request or supply a non-empty value. at /web/html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38)
Empty string error above

spring fossil
#

What API request are you making? Are you updating the Customer object?

late moth
#

yes like so...

/**
* Update a customers information on stripe.
*
* @param string $customer_id Customer uuid
* @param array $params Parameters
*
* @return mixed
* @throws \ReflectionException
*/
public static function update($customer_id, array $params)
{
$customer = Customer::where(function ($query) use ($customer_id) {
return $query->where('business_id', '=', $customer_id)
->orWhere('stripe_id', '=', $customer_id);
})->firstOrFail();

    static::authorizeUserAction('update', $customer);

    if (array_key_exists('id', $params)) {
        unset($params['id']);
    }


    if ($customer instanceof Collection) {
        $customer = $customer->first();
    }

    $stripe_customer = static::getStripeClass(StripeCustomer::class)::retrieve(
        $customer->stripe_id
    );

    $properties = static::getConstructorProperties(StripeCustomer::class);

    $params = Arr::only($params, $properties);

    foreach (Arr::dot($params) as $key => $value) {
        data_set(
            $stripe_customer,
            $key,
            $value
        );
    }

    $stripe_customer->save();

    Cache::forget('customers.all');
    Cache::forget('customers.' . $customer_id);

    return $stripe_customer;
}
spring fossil
late moth
#

It looks to be sorted. The problem seemed to be that the default source was taking precedence over the new payment method. So we needed to unset the default source before we sent it.

spring fossil
#

Okay good deal. I just wanted to call out that the invoice_settings one is taking precedence for newer Payment Method APIs

late moth
#

Thanks for your time ๐Ÿ™‚