<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "ApplePayontheWeb",
  "identifier" : "/documentation/ApplePayontheWeb/ApplePaySession/oncouponcodechanged",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Apple Pay on the Web"
    ],
    "preciseIdentifier" : "instp/ApplePaySession/oncouponcodechanged"
  },
  "title" : "oncouponcodechanged"
}
-->

# oncouponcodechanged

An event handler called by the system when the user enters or updates a coupon code.

```
attribute EventHandler oncouponcodechanged;
```

## Discussion

Set this attribute to a function with one parameter that contains an [`ApplePayCouponCodeChangedEvent`](/documentation/ApplePayontheWeb/ApplePayCouponCodeChangedEvent). This function processes the coupon code update, and then calls [`completeCouponCodeChange`](/documentation/ApplePayontheWeb/ApplePaySession/completeCouponCodeChange) with the results.

The code below shows adding a listener for the coupon code changed event to the Apple Pay session:

```javascript
// Add a listener for the couponcodechanged event to the Apple Pay session.
session.addEventListener("couponcodechanged", function(event) {
    var newCode = event.couponCode;

    // Process the coupon code.
    ...

    // Call the Apple Pay session completion method for this event.
    session.completeCouponCodeChange({
        // Update the payment request with any changed information.
        newTotal: ...
    });
});
```

> Note:
> Call `completeCouponCodeChange` within `30` seconds to prevent the system ending the payment request.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)