<commit_before># Spree-ember-paypal-express
[![Build Status](https://travis-ci.org/givanse/spree-ember-paypal-express.svg?branch=master)](https://travis-ci.org/givanse/spree-ember-paypal-express)
[![Code Climate](https://codeclimate.com/github/givanse/spree-ember-paypal-express/badges/gpa.svg)](https://codeclimate.com/github/givanse/spree-ember-paypal-express)

[spree-ember](https://github.com/hhff/spree-ember)
addon for the gem
[better_spree_paypal_express](https://github.com/spree-contrib/better_spree_paypal_express)

Currently this addon is meant to be used with Spree `2-4-stable`.

## Install

    # not available yet, coming soon
    ember install spree-ember-paypal-express

## Dependencies

### Backend

The following fork of `better_spree_paypal_express` is needed because it has two things:

 * The changes of [PR #168](https://github.com/spree-contrib/better_spree_paypal_express/pull/168)
 * `active_model_serializers` version `0.8.2`

Gemfile

    gem 'spree_paypal_express', github: 'givanse/better_spree_paypal_express', branch: 'ams_0.8.2'

### Frontend

package.js

    "spree-ember-storefront": "0.0.1-beta.1"

## Usage

This addon adds an ember service, `paypal-express`, and it is injected into
the `spree` service so you can access it from anywhere in your code. Ex:

```bash
  actions: {
    initPaypalExpress: function() {
      this.spree.paypalExpress.getRedirectURL().then(response => {
        // redirect to PayPal express
        window.open(response.redirect_url, '_self');
      });
    }
  }
```

When a payment is completed through PayPal, the page will redirect to
the route `confirmUrl`.

```bash
// ENV['paypal-express'].confirmUrl
// defaults to spree.checkout

  beforeModel: function(transition) {                                            
    let qp = transition.queryParams;                                             
                                                                                 
    if (qp.token  && qp.PayerID) {                                               
      this.spree.paypalExpress.confirm(qp.token, qp.PayerID)                     
      .then(currentOrder => {                                                    
        /* (?)
        this.spree.get('checkouts').transition('complete').finally(() => {          
          this.redirect();                                                       
        });                                                                      
        */
      });                                                                        
    }                                                                            
  } 
```

## Configuration

In `config/environment.js` you can override the following default values:

```<commit_msg>use js highlight<commit_after># Spree-ember-paypal-express
[![Build Status](https://travis-ci.org/givanse/spree-ember-paypal-express.svg?branch=master)](https://travis-ci.org/givanse/spree-ember-paypal-express)
[![Code Climate](https://codeclimate.com/github/givanse/spree-ember-paypal-express/badges/gpa.svg)](https://codeclimate.com/github/givanse/spree-ember-paypal-express)

[spree-ember](https://github.com/hhff/spree-ember)
addon for the gem
[better_spree_paypal_express](https://github.com/spree-contrib/better_spree_paypal_express)

Currently this addon is meant to be used with Spree `2-4-stable`.

## Install

    # not available yet, coming soon
    ember install spree-ember-paypal-express

## Dependencies

### Backend

The following fork of `better_spree_paypal_express` is needed because it has two things:

 * The changes of [PR #168](https://github.com/spree-contrib/better_spree_paypal_express/pull/168)
 * `active_model_serializers` version `0.8.2`

Gemfile

    gem 'spree_paypal_express', github: 'givanse/better_spree_paypal_express', branch: 'ams_0.8.2'

### Frontend

package.js

    "spree-ember-storefront": "0.0.1-beta.1"

## Usage

This addon adds an ember service, `paypal-express`, and it is injected into
the `spree` service so you can access it from anywhere in your code. Ex:

```bash
  actions: {
    initPaypalExpress: function() {
      this.spree.paypalExpress.getRedirectURL().then(response => {
        // redirect to PayPal express
        window.open(response.redirect_url, '_self');
      });
    }
  }
```

When a payment is completed through PayPal, the page will redirect to
the route `confirmUrl`.

```js
// ENV['paypal-express'].confirmUrl
// defaults to spree.checkout

  beforeModel: function(transition) {                                            
    let qp = transition.queryParams;                                             
                                                                                 
    if (qp.token  && qp.PayerID) {                                               
      this.spree.paypalExpress.confirm(qp.token, qp.PayerID)                     
      .then(currentOrder => {                                                    
        /* (?)
        this.spree.get('checkouts').transition('complete').finally(() => {          
          this.redirect();                                                       
        });                                                                      
        */
      });                                                                        
    }                                                                            
  } 
```

## Configuration

In `config/environment.js` you can override the following default values:

```js
{'fraction_non_alphanumeric': 0.11141353656323716, 'fraction_numerical': 0.0065323897659227, 'mean_word_length': 1.6666666666666667, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1934048', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1457, 'n_words': 295}