Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Receiving an duplicate content error when displaying billing declined in an embedded app #94

Closed
ncpope opened this issue Sep 3, 2018 · 3 comments
Assignees
Labels
bug Bug with the code

Comments

@ncpope
Copy link
Contributor

ncpope commented Sep 3, 2018

When displaying within an embedded app it will redirect which will cause the billing controller to try and create the charge more than once in the db. This causes an error like SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1234567890' for key 'charges_charge_id_unique'

https://github.com/ohmybrew/laravel-shopify/blob/4258693b3eb7430d426530faf1932cf70d1aa6cd/src/ShopifyApp/Traits/BillingControllerTrait.php#L51-L55

These lines could be changed to:

$charge = Charge::firstOrCreate([
    "type" => $this->chargeType() === 'recurring' ? Charge::CHARGE_RECURRING : Charge::CHARGE_ONETIME,
    "charge_id" => $chargeId,
    "status" => $status,
    "shop_id" => $shop->id,
]);

This will prevent the error and will select the charge rather than creating a new one.

https://github.com/ohmybrew/laravel-shopify/blob/4258693b3eb7430d426530faf1932cf70d1aa6cd/src/ShopifyApp/Traits/BillingControllerTrait.php#L83-L84

This could then become:

// Save the charge
$charge->save();
@gnikyt gnikyt self-assigned this Sep 4, 2018
@gnikyt gnikyt added the bug Bug with the code label Sep 4, 2018
gnikyt added a commit that referenced this issue Sep 11, 2018
…for issue #96 to add a view for errors on billing, support for usage charges (untested) directly in billing controller for issue #76
@gnikyt gnikyt added this to the v4.0.0 milestone Sep 11, 2018
@gnikyt
Copy link
Owner

gnikyt commented Sep 11, 2018

Thank you for the note, I have adjusted this for next release.

@ncpope
Copy link
Contributor Author

ncpope commented Sep 13, 2018

Hi, I just left a comment on the commit but I'm not exactly sure whether or not it shows since I've never done one before, so I'll just post it here as well:

82b0778#r30494464

@gnikyt
Copy link
Owner

gnikyt commented Sep 14, 2018

Present in v4.0.0

@gnikyt gnikyt closed this as completed Sep 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug with the code
Projects
None yet
Development

No branches or pull requests

2 participants