Refresh the session
Read the session's amount and currency again after your server changes them, to show the new total before the customer pays.
checkout.refreshSession() reads the session's amount and currency from Pay.com again and updates checkout.session. Call it in your own UI after your server updates the session's amount, and show the new total before the customer pays. The drop-in and payWithApplePay() read the total again by themselves.
Paying without it is still safe. If the total changed, pay charges nothing and returns .failed(.amountChanged).
let session = try await checkout.refreshSession()Parameters
None.
Returns
The updated PaySession, which checkout.session has too. You can ignore it. Only amount and currency can change. A setup session has no total to read, so it comes back as it is, without a request.
Errors
refreshSession() throws a PayError when it can't read the total, and checkout.session keeps the one it had:
| Error | When |
|---|---|
sessionExpired | Pay.com returned HTTP 401. The session expired, or Pay.com rejected the client_secret. |
requestRejected | Pay.com refused the request with another status below 500. |
server | Pay.com failed with a 5xx or returned a 408. |
network | The request didn't reach Pay.com, or the response didn't arrive within 30 seconds. |
unexpectedResponse | Pay.com returned a response without the session's amount or currency, or one this SDK version can't read. |
Example
import PayCheckout
import PayCore
import UIKit
extension CartViewController {
func shippingChanged(to option: ShippingOption) async {
await shop.updateOrder(shipping: option) // Your server updates the session's amount
do throws(PayError) {
let session = try await checkout.refreshSession()
showTotal(session.amount, currency: session.currency)
} catch {
showMessage(error.localizedDescription) // Keep the pay button off until you can show the total
}
}
}Next steps
- Pay: What happens when the total changes as the customer pays.
- Present Apple Pay yourself: Refresh, then build the request.