Skip to content

Commit

Permalink
Merge pull request #468 from dx/pp-edit-address-with-shipping
Browse files Browse the repository at this point in the history
Add shippingAddressEditable flag to BTPayPalRequest
  • Loading branch information
demerino authored and GitHub Enterprise committed Jun 14, 2018
2 parents c6ea454 + 1836c26 commit 846f066
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BraintreePayPal/BTPayPalDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ - (void)requestExpressCheckout:(BTPayPalRequest *)request
}

if (request.shippingAddressOverride != nil) {
experienceProfile[@"address_override"] = @YES;
experienceProfile[@"address_override"] = @(!request.isShippingAddressEditable);
BTPostalAddress *shippingAddress = request.shippingAddressOverride;
if (isBillingAgreement) {
NSMutableDictionary *shippingAddressParams = [NSMutableDictionary dictionary];
Expand Down
1 change: 1 addition & 0 deletions BraintreePayPal/BTPayPalRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ - (instancetype)init
if (self) {
_shippingAddressRequired = NO;
_offerCredit = NO;
_shippingAddressEditable = NO;
_intent = BTPayPalRequestIntentAuthorize;
_userAction = BTPayPalRequestUserActionDefault;
_landingPageType = BTPayPalRequestLandingPageTypeDefault;
Expand Down
7 changes: 7 additions & 0 deletions BraintreePayPal/Public/BTPayPalRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ typedef NS_ENUM(NSInteger, BTPayPalRequestUserAction) {
*/
@property (nonatomic, getter=isShippingAddressRequired) BOOL shippingAddressRequired;

/**
Defaults to false. Set to true to enable user editing of the shipping address.
@note Only applies when `shippingAddressOverride` is set.
*/
@property (nonatomic, getter=isShippingAddressEditable) BOOL shippingAddressEditable;

/**
Optional: A valid ISO currency code to use for the transaction. Defaults to merchant currency code if not set.
@note This is only used for one-time payments.
Expand Down
48 changes: 48 additions & 0 deletions UnitTests/BTPayPalDriver_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,30 @@ class BTPayPalDriver_Checkout_Tests: XCTestCase {
XCTAssertEqual(lastPostParameters["country_code"] as? String, "US")
}

func testCheckout_postsPaymentResourceWithShippingAddressEditable() {
let payPalDriver = BTPayPalDriver(apiClient: mockAPIClient)
mockAPIClient = payPalDriver.apiClient as! MockAPIClient
payPalDriver.returnURLScheme = "foo://"
let request = BTPayPalRequest(amount: "1")
request.currencyCode = "GBP"
let address : BTPostalAddress = BTPostalAddress()
request.shippingAddressOverride = address
request.isShippingAddressEditable = true
BTPayPalDriver.setPayPalClass(FakePayPalOneTouchCore.self)
payPalDriver.requestOneTimePayment(request) { _,_ -> Void in }

XCTAssertEqual("v1/paypal_hermes/create_payment_resource", mockAPIClient.lastPOSTPath)
guard let lastPostParameters = mockAPIClient.lastPOSTParameters else {
XCTFail()
return
}
guard let experienceProfile = lastPostParameters["experience_profile"] as? Dictionary<String, AnyObject> else {
XCTFail()
return
}
XCTAssertEqual(experienceProfile["address_override"] as? Bool, false)
}

func testCheckout_whenPayPalCreditOffered_performsSwitchCorrectly() {
let payPalDriver = BTPayPalDriver(apiClient: mockAPIClient)
mockAPIClient = payPalDriver.apiClient as! MockAPIClient
Expand Down Expand Up @@ -2374,6 +2398,30 @@ class BTPayPalDriver_BillingAgreements_Tests: XCTestCase {
XCTAssertEqual(shippingAddress["postal_code"] as? String, "12345")
XCTAssertEqual(shippingAddress["country_code"] as? String, "US")
}

func testBillingAgreement_postsPaymentResourceWithShippingAddressEditable() {
let payPalDriver = BTPayPalDriver(apiClient: mockAPIClient)
mockAPIClient = payPalDriver.apiClient as! MockAPIClient
payPalDriver.returnURLScheme = "foo://"
let request = BTPayPalRequest()
request.currencyCode = "GBP"
let address : BTPostalAddress = BTPostalAddress()
request.shippingAddressOverride = address
request.isShippingAddressEditable = true
BTPayPalDriver.setPayPalClass(FakePayPalOneTouchCore.self)
payPalDriver.requestBillingAgreement(request) { _,_ -> Void in }

XCTAssertEqual("v1/paypal_hermes/setup_billing_agreement", mockAPIClient.lastPOSTPath)
guard let lastPostParameters = mockAPIClient.lastPOSTParameters else {
XCTFail()
return
}
guard let experienceProfile = lastPostParameters["experience_profile"] as? Dictionary<String, AnyObject> else {
XCTFail()
return
}
XCTAssertEqual(experienceProfile["address_override"] as? Bool, false)
}
}

class BTPayPalDriver_DropIn_Tests: XCTestCase {
Expand Down

0 comments on commit 846f066

Please sign in to comment.