# Migration v9

Contains 1 breaking change of the SDK interface.

## Changes

- [createSubscription](#createSubscription)

### createSubscription

`paymentOptions` have changed to reduce the knowledge needed when creating a subscription.

- `billingCountry`, `billingState` and `billingPostcode` have been added to the `paymentOptions` rather than being set on the user to clarify their purpose.
- Complete `offer` model is being passed rather than offer ID so the payment term and trial structures can be created within the SDK rather than in the application.
- Missing `option` for fulfilment option has been added to the type.

```diff
- paymentType: string;
- currencyCode: string;
- paymentMethodId: string;
- paypalBAID: string;
- paypalEmail: string;
- offerId: string;
- segmentId: string;
- price: string;
- subscriptionTerm?: string;
- paymentGateway: string;
- trial: Trial,
- startDate?: string
+ paymentType: PaymentType - enum of value 'creditcard', 'directdebit', 'paypal' or 'applepay';
+ paymentMethodId: string;
+ paymentGateway: string;
+ paymentTerm: string;
+ billingCountry: string;
+ billingState?: string;
+ billingPostcode?: string;
+ offer: Offer;
+ segmentId?: string;
+ paypalBAID?: string;
+ paypalEmail?: string;
+ startDate?: string;
+ option?: string;
```

#### Before

```js
const selectedPaymentTerm = paymentTerms.find(term => term.value === req.body.paymentTerm);

const options = {
    paymentType: req.body.paymentType,
    paymentMethodId: req.body.paymentMethodId,
    paymentGateway: req.body.paymentGateway,
    price: selectedPaymentTerm.amount,
    currencyCode: selectedPaymentTerm.currency,
    subscriptionTerm: selectedPaymentTerm.value,
    offerId: offer.id,
    segmentId: segmentId,
};

if (offer.type === 'TRIAL') {
    Object.assign(options, {
        subscriptionTerm: 'P1M',
        term: 'trial',
        trial: {
            price: selectedPaymentTerm.trialAmount,
            term: selectedPaymentTerm.value
        }
    });
}

if (paymentType === PaymentType.PAYPAL) {
    options.paypalBAID = req.body.paypalBAID;
    options.paypalEmail = req.body.paypalEmail;
    options.paymentGateway = isTest(req) ? 'TEST - Paypal Gateway' : 'Paypal Gateway';
}

if (paymentType === PaymentType.APPLEPAY) {
    const paymentToken = JSON.parse(options.paymentMethodId);
    options.paymentToken = paymentToken.paymentData;
    options.transactionIdentifier = paymentToken.transactionIdentifier;
    options.paymentMethodId = 'apple-pay';
    options.paymentGateway = await membershipSdk.subscription.fetchGatewayName(PaymentType.APPLEPAY, billingCountry);
}

user.billingCountryCode = req.body.billingCountry;
user.billingState = req.body.billingState;
user.billingPostcode = req.body.billingPostcode;
```

#### After

```js
const options = {
    paymentType: req.body.paymentType,
    paymentMethodId: req.body.paymentMethodId,
    paymentGateway: req.body.paymentGateway,
    paymentTerm: req.body.paymentTerm,
    billingCountry: req.body.billingCountry,
    billingState: req.body.billingState,
    billingPostcode: req.body.billingPostcode,
    paypalBAID: req.body.paypalBAID,
    paypalEmail: req.body.paypalEmail,
    offer: view._offer,
    segmentId: view.segmentId
};
const subscriptionResponse = await membershipSdk.subscription.createSubscription(user, options);
```