使用Stripe with Meteor.js遇到的问题

时间:2016-03-29 07:02:40

标签: meteor stripe-payments

我最近在Meteor中使用条纹遇到了一些问题,这个社区对我来说一直都是一个很大的帮助,所以在这里!

我正在尝试创建一个简单的网站,允许用户创建支付预定费用的帖子。每月20美元,2个月30美元等。我有建立网站的整个骨架我现在只需要让用户付费。在搜索有关我的场景的任何信息时,我会浏览教程。

https://themeteorchef.com/recipes/payments-with-stripe-checkout/

这是一个非常有用且信息丰富的教程。但是我一路上遇到了一些问题。我的路径几乎完全相同,但在少数情况下我必须更改它们,因为我的预先存在的代码在哪里。我无法找出为什么这段代码不能正常工作,我希望第二组眼睛能抓住我错过的东西。

我的settings.json文件位于.meteor文件旁边的目录中:

{
"public": {
"stripe": "pk_test_jdsoajdanotrealhasodahsd"
},

"private": {
  "stripe": "sk_test_hfsd83totallyreal39u03fda",
  "CLOUDINARY_API_SECRET": "9847934f937ForSureReal49849f"
},

"CLOUDINARY_API_KEY": "fdnk84894wy7f7sdffake8494g",
"CLOUDINARY_CLOUD_NAME": "CompanyName"

}

My Meteor autofom HTML位于:/ CLIENT / PAGES / POSTS

  <template name="insertPostForm">
  {{#autoForm collection="Posts" id="insertPostForm" type="insert"}}
  <div class="form-group">
    <h4>Length of Post <small></small></h4>
     {{> afFormGroup name="expiryDate" options=expiryOptions}}
   <h3>Information <small></small></h3><hr>
    <div class="col-sm-12 col-md-6">
     {{> afQuickField name='address'}}
    </div>
    <div class="col-sm-12 col-md-6">
      {{> afQuickField name='status' options='allowed'}}
    </div>
    <h3>Details <small></small></h3><hr>
    <div class="col-sm-12 col-md-6">
      {{> afQuickField name='squareFoot'}}
    </div>
    <div class="col-sm-12 col-md-6">
     {{> afQuickField name='yearBought'}}
    </div>
    {{#unless processing}}
            <p class="alert alert-info">Please select your prefered months of posting time</p>

            <ul class="list-group price-list">
              <li class="list-group-item clearfix">
                <p class="pull-left"><strong>$32</strong> &mdash; 1 Month</p>
                <a href="#" data-service="1Month" type="submit" class="btn btn-primary">Buy Now</a>
              </li>
              <li class="list-group-item clearfix">
                <p class="pull-left"><strong>$50</strong> &mdash; 2 Months</p>
                <a href="#" data-service="2Months" type="submit" class="btn btn-primary">Buy Now</a>
              </li>
              <li class="list-group-item clearfix">
                <p class="pull-left"><strong>$75</strong> &mdash; 3 Months</p>
                <a href="#" data-service="3Months" type="submit" class="btn btn-primary">Buy Now</a>
              </li>
            </ul>

      {{else}}
        <p class="alert alert-warning"><i class="fa fa-refresh fa-spin"></i> Processing payment...</p>
      {{/unless}}
   <button type="submit" class="btn btn-primary">Add Listing</button>
 </div>
 {{/autoForm}}
</template>

我的service.js文件位于:CLIENT / PUBLIC / SERVICES.JS

Template.services.onCreated( () => {
  let template = Template.instance();

  template.selectedService  = new ReactiveVar( false );
  template.processing       = new ReactiveVar( false );

  template.checkout = StripeCheckout.configure({
    key: Meteor.settings.public.stripe,
    locale: 'auto',
    token( token ) {
      let service = template.selectedService.get(),
          charge  = {
            amount: token.amount || service.amount,
            currency: token.currency || 'usd',
            source: token.id,
            description: token.description || service.description,
            receipt_email: token.email
          };

      Meteor.call( 'processPayment', charge, ( error, response ) => {
        if ( error ) {
          template.processing.set( false );
          Bert.alert( error.reason, 'danger' );
        } else {
          Bert.alert( 'Success!' );
        }
      });
    },
    closed() {
      template.processing.set( false );
    }
  });
});

Template.services.helpers({
  processing() {
    return Template.instance().processing.get();
  },
  paymentSucceeded() {
    return Template.instance().paymentSucceeded.get();
  }
});

Template.services.events({
  'click [data-service]' ( event, template ) {
    const pricing = {
        '1Month': {
          amount: 3200,
          description: "1 Month"
        },
        '2Monthes': {
          amount: 5000,
          description: "2 Monthes"
        },
        '3Monthes': {
          amount: 7500,
          description: "3 Monthes"
        }
    };

    let service = pricing[ event.target.dataset.service ];

    template.selectedService.set( service );
    template.processing.set( true );

    template.checkout.open({
      name: 'Posting Service',
      description: service.description,
      amount: service.amount,
      bitcoin: true
    });
  }
});

我的Stripe.JS文件位于:/SERVER/STRIPE.JS

let Stripe = StripeAPI(Meteor.settings.private.stripe);

Meteor.methods({
  processPayment( charge ) {
    check( charge, {
      amount: Number,
      currency: String,
      source: String,
      description: String,
      receipt_email: String
    });

    let handleCharge = Meteor.wrapAsync( Stripe.charges.create, Stripe.charges ),
        payment      = handleCharge( charge );

    return payment;
  }

});
每当我进入命令行并输入“meteor --settings settings.json”

之后,将此代码从教程集成到我的项目中

我得到的第一行是

“ReferenceError:未定义StripeAPI” “at server / Stripe.js:1:14”

如果我将Stripe.js代码的第一行更改为(Meteor.private.Stripe)我的错误更改为

“TypeError:无法读取未定义的属性'stripe'”

“”

我刚刚在这里疯狂试图解决这个问题,并且我想如果你们中的一个好人能够在这件事上帮助我。如果您已经阅读了这篇文章,那么您已经为我做了一项服务,为此我感谢您!

1 个答案:

答案 0 :(得分:1)

首先要做的事情:你永远不应该!随时随地发布您的API密钥!阅读更多here

对于您的问题:看起来服务器上没有node-stripe。您是否meteor add mrgalaxy:stripe中指定了ReactDOM.render(Home, document.getElementById('app'))

相关问题