private void onShippingMethodSave() { SelectShippingMethodWidget selectShippingMethodWidget = findViewById(R.id.select_shipping_method_widget); ShippingMethod shippingMethod = selectShippingMethodWidget.getSelectedShippingMethod(); mPaymentSessionData.setShippingMethod(shippingMethod); Intent intent = new Intent(); intent.putExtra(PAYMENT_SESSION_DATA_KEY, mPaymentSessionData); setResult(RESULT_OK, intent); finish(); }
private void onShippingInfoSubmitted() { ShippingInfoWidget shippingInfoWidget = findViewById(R.id.shipping_info_widget); ShippingInformation shippingInformation = shippingInfoWidget.getShippingInformation(); if (shippingInformation != null) { mShippingInformationSubmitted = shippingInformation; setCommunicatingProgress(true); broadcastShippingInfoSubmitted(shippingInformation); } }
@Test public void launchPaymentFlowActivity_withHideShippingInfoConfig_hidesShippingInfoView() { PaymentSessionConfig paymentSessionConfig = new PaymentSessionConfig.Builder() .setShippingInfoRequired(false) .build(); Intent intent = new Intent() .putExtra(PAYMENT_SESSION_DATA_KEY, new PaymentSessionData()) .putExtra(PAYMENT_SESSION_CONFIG, paymentSessionConfig); PaymentFlowActivity paymentFlowActivity = createActivity(intent); assertNull(paymentFlowActivity.findViewById(R.id.shipping_info_widget)); assertNotNull(paymentFlowActivity.findViewById(R.id.select_shipping_method_widget)); }
@Test public void onShippingInfoSave_whenShippingInfoNotPopulated_doesNotContinue() { Intent intent = new Intent(); PaymentSessionConfig paymentSessionConfig = new PaymentSessionConfig.Builder() .build(); intent.putExtra(PAYMENT_SESSION_CONFIG, paymentSessionConfig); PaymentSessionData paymentSessionData = new PaymentSessionData(); intent.putExtra(PAYMENT_SESSION_DATA_KEY, paymentSessionData); PaymentFlowActivity paymentFlowActivity = createActivity(intent); mShippingInfoWidget = paymentFlowActivity.findViewById(R.id.shipping_info_widget); assertNotNull(mShippingInfoWidget); paymentFlowActivity.onActionSave(); assertFalse(paymentFlowActivity.isFinishing()); assertNotNull(paymentFlowActivity.findViewById(R.id.shipping_info_widget)); }
@Test public void onShippingInfoSave_whenShippingNotPopulated_doesNotFinish() { PaymentSessionConfig paymentSessionConfig = new PaymentSessionConfig.Builder() .build(); Intent intent = new Intent() .putExtra(PAYMENT_SESSION_CONFIG, paymentSessionConfig) .putExtra(PAYMENT_SESSION_DATA_KEY, new PaymentSessionData()); PaymentFlowActivity paymentFlowActivity = createActivity(intent); mShippingInfoWidget = paymentFlowActivity.findViewById(R.id.shipping_info_widget); assertNotNull(mShippingInfoWidget); paymentFlowActivity.onActionSave(); assertFalse(paymentFlowActivity.isFinishing()); }
@Test public void onShippingInfoSave_whenShippingPopulated_sendsCorrectIntent() { Intent intent = new Intent(); PaymentSessionConfig paymentSessionConfig = new PaymentSessionConfig.Builder() .setPrepopulatedShippingInfo(getExampleShippingInfo()) .build(); intent.putExtra(PAYMENT_SESSION_CONFIG, paymentSessionConfig); PaymentSessionData paymentSessionData = new PaymentSessionData(); intent.putExtra(PAYMENT_SESSION_DATA_KEY, paymentSessionData); PaymentFlowActivity paymentFlowActivity = createActivity(intent); mShippingInfoWidget = paymentFlowActivity.findViewById(R.id.shipping_info_widget); assertNotNull(mShippingInfoWidget); paymentFlowActivity.onActionSave(); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mBroadcastReceiver).onReceive(any(Context.class), intentArgumentCaptor.capture()); Intent captured = intentArgumentCaptor.getValue(); assertNotNull(captured); assertEquals( captured.getParcelableExtra(EXTRA_SHIPPING_INFO_DATA), getExampleShippingInfo()); }
mViewStub.setLayoutResource(R.layout.activity_shipping_flow); mViewStub.inflate(); mViewPager = findViewById(R.id.shipping_flow_viewpager); final PaymentSessionConfig paymentSessionConfig = getIntent().getParcelableExtra(PAYMENT_SESSION_CONFIG);