2016-08-13 15 views
1

私は現在、それが文書に示されますように、テストウェブフック通知を作成しようとしています:テスト環境でウェブフック、通知を作成

HashMap<String, String> sampleNotification = gateway.webhookTesting().sampleNotification(
    WebhookNotification.Kind.SUBSCRIPTION_WENT_PAST_DUE, "my_id" 
); 

WebhookNotification webhookNotification = gateway.webhookNotification().parse(
    sampleNotification.get("bt_signature"), 
    sampleNotification.get("bt_payload") 
); 

webhookNotification.getSubscription().getId(); 
// "my_id" 

まずオフ、私が実際にどうあるべきかmy_id分かりません。それは計画のIDであるはずですか?または、Subscription IDである必要がありますか?

私はそれをすべてテストしました。私は私のボールト内の既存の料金プランに設定していると私はまた、このような実際のSubscriptionまでCustomerを作成しようとしました:

public class WebhookChargedSuccessfullyLocal { 

    private final static BraintreeGateway BT; 

    static { 
     String btConfig = "C:\\workspaces\\mz\\mz-server\\mz-web-server\\src\\main\\assembly\\dev\\braintree.properties"; 
     Braintree.initialize(btConfig); 
     BT = Braintree.instance(); 
    } 

    public static void main(String[] args) { 

     WebhookChargedSuccessfullyLocal webhookChargedSuccessfullyLocal = new WebhookChargedSuccessfullyLocal(); 
     webhookChargedSuccessfullyLocal.post(); 
    } 

    /** 
    * 
    */ 
    public void post() { 

     CustomerRequest customerRequest = new CustomerRequest() 
       .firstName("Testuser") 
       .lastName("Tester"); 

     Result<Customer> createUserResult = BT.customer().create(customerRequest); 

     if(createUserResult.isSuccess() == false) { 
      System.err.println("Could not create customer"); 
      System.exit(1); 
     } 

     Customer customer = createUserResult.getTarget(); 

     PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest() 
       .customerId(customer.getId()) 
       .paymentMethodNonce("fake-valid-visa-nonce"); 

     Result<? extends PaymentMethod> createPaymentMethodResult = BT.paymentMethod().create(paymentMethodRequest); 

     if(createPaymentMethodResult.isSuccess() == false) { 
      System.err.println("Could not create payment method"); 
      System.exit(1); 
     } 

     if(!(createPaymentMethodResult.getTarget() instanceof CreditCard)) { 
      System.err.println("Unexpected error. Result is not a credit card."); 
      System.exit(1); 
     } 

     CreditCard creditCard = (CreditCard) createPaymentMethodResult.getTarget(); 

     SubscriptionRequest subscriptionRequest = new SubscriptionRequest() 
       .paymentMethodToken(creditCard.getToken()) 
       .planId("mmb2"); 

     Result<Subscription> createSubscriptionResult = BT.subscription().create(subscriptionRequest); 

     if(createSubscriptionResult.isSuccess() == false) { 
      System.err.println("Could not create subscription"); 
      System.exit(1); 
     } 

     Subscription subscription = createSubscriptionResult.getTarget(); 

     HashMap<String, String> sampleNotification = BT.webhookTesting() 
       .sampleNotification(WebhookNotification.Kind.SUBSCRIPTION_CHARGED_SUCCESSFULLY, subscription.getId()); 

     WebhookNotification webhookNotification = BT.webhookNotification() 
       .parse(
         sampleNotification.get("bt_signature"), 
         sampleNotification.get("bt_payload") 
         ); 

     System.out.println(webhookNotification.getSubscription().getId()); 

    } 

} 

を私は取得しています、すべては何も設定されていないWebhookNotificationインスタンスであります。そのIDとタイムスタンプだけが設定されているように見えますが、それだけです。

は私が期待したもの:

私は、顧客が、例えばだけでなく、それに加入している私に語っSubscriptionオブジェクトを受け取ることが期待しました請求計画に含まれるすべてのアドオン。

サンドボックスモードでこのようなテスト通知を受け取る方法はありますか?

答えて

0

全開示:私はブレーンツリーで働いています。ご不明な点がございましたら、supportまでお気軽にお問い合わせください。

webhookNotification.getSubscription().getId();は、sampleNotificationに関連付けられているサブスクリプションのIDを返します。これは、テスト目的では何でも可能ですが、プロダクション環境ではSubscriptionIDになります。

webhookTesting().sampleNotification()からダミーオブジェクトを受信すると、expected behaviorとなり、あらゆる種類のウェブフックを正しく捕捉できるようになります。そのロジックが設定されたら、サンドボックスゲートウェイの[設定]> [Webhooks]の下で、実際のWebhook通知を受け取るようにエンドポイントを指定できます。

SUBSCRIPTION_CHARGED_SUCCESSFULLYの場合、実際にはアドオン情報を含むSubscription objectと、顧客情報を含むTransaction objectsの配列が表示されます。

関連する問題