FastSpring / fastspring-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add customer info to updateSubscription php wrapper

morrow95 opened this issue · comments

Using the php wrapper for updateSubscription. I noticed it does not include the ability to update firstname, lastName, company, email, phoneNumber. As this is the information used to contact your subscription users (email notifications) this should be added in.

I made some changes and it works as expected, but the documentation and example is lacking this information :

class FsprgSubscriptionUpdate {
    public $reference;
    public $productPath;
    public $quantity;
    public $tags;
    public $noEndDate;
    public $coupon;
    public $discountDuration;
    public $proration;
    public $firstName;
    public $lastName;
    public $company;
    public $email;
    public $phoneNumber;

    public function __construct($subscription_ref) {
        $this->reference = $subscription_ref;
    }

    public function toXML() {
        $xmlResult = new SimpleXMLElement("<subscription></subscription>");

        if ($this->firstName) {
            $xmlResult->firstName = $this->firstName;
        }
        if ($this->lastName) {
            $xmlResult->lastName = $this->lastName;
        }
        if ($this->company) {
            $xmlResult->company = $this->company;
        }
        if ($this->email) {
            $xmlResult->email = $this->email;
        }
        if ($this->phoneNumber) {
            $xmlResult->phoneNumber = $this->phoneNumber;
        }
        if ($this->productPath) {
            $xmlResult->productPath = $this->productPath;
        }
        if ($this->quantity) {
            $xmlResult->quantity = $this->quantity;
        }
        if ($this->tags) {
            $xmlResult->tags = $this->tags;
        }
        if (isset($this->noEndDate) && $this->noEndDate) {
            $xmlResult->addChild("no-end-date", null);
        }
        if ($this->coupon) {
            $xmlResult->coupon = $this->coupon;
        }
        if ($this->discountDuration) {
            $xmlResult->addChild("discount-duration", $this->discountDuration);
        }
        if (isset($this->proration)) {
            if ($this->proration) {
                $xmlResult->proration = "true";
            } else {
                $xmlResult->proration = "false";
            } 
        }

        return $xmlResult->asXML();
    }
}

If you are using the demo example files you can make the change above and then make the necessary changes in the example file as well.